Skip to content

Commit 72189aa

Browse files
authored
Try to infer runner is on hosted/ghes when githuburl is empty. (#4254)
1 parent e012ab6 commit 72189aa

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/Runner.Common/ConfigurationStore.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,41 @@ public bool IsHostedServer
7575
{
7676
return UrlUtil.IsHostedServer(new UriBuilder(GitHubUrl));
7777
}
78+
else
79+
{
80+
// feature flag env in case the new logic is wrong.
81+
if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_FORCE_EMPTY_GITHUB_URL_IS_HOSTED")))
82+
{
83+
return true;
84+
}
85+
86+
// GitHubUrl will be empty for jit configured runner
87+
// We will try to infer it from the ServerUrl/ServerUrlV2
88+
if (StringUtil.ConvertToBoolean(Environment.GetEnvironmentVariable("GITHUB_ACTIONS_RUNNER_FORCE_GHES")))
89+
{
90+
// Allow env to override and force GHES in case the inference logic is wrong.
91+
return false;
92+
}
93+
94+
if (!string.IsNullOrEmpty(ServerUrl))
95+
{
96+
// pipelines services
97+
var serverUrl = new UriBuilder(ServerUrl);
98+
return serverUrl.Host.EndsWith(".actions.githubusercontent.com", StringComparison.OrdinalIgnoreCase)
99+
|| serverUrl.Host.EndsWith(".codedev.ms", StringComparison.OrdinalIgnoreCase);
100+
}
101+
102+
if (!string.IsNullOrEmpty(ServerUrlV2))
103+
{
104+
// broker-listener
105+
var serverUrlV2 = new UriBuilder(ServerUrlV2);
106+
return serverUrlV2.Host.EndsWith(".actions.githubusercontent.com", StringComparison.OrdinalIgnoreCase)
107+
|| serverUrlV2.Host.EndsWith(".githubapp.com", StringComparison.OrdinalIgnoreCase)
108+
|| serverUrlV2.Host.EndsWith(".ghe.com", StringComparison.OrdinalIgnoreCase)
109+
|| serverUrlV2.Host.EndsWith(".actions.localhost", StringComparison.OrdinalIgnoreCase)
110+
|| serverUrlV2.Host.EndsWith(".ghe.localhost", StringComparison.OrdinalIgnoreCase);
111+
}
112+
}
78113

79114
// Default to true since Hosted runners likely don't have this property set.
80115
return true;

0 commit comments

Comments
 (0)