@@ -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