@@ -162,73 +162,103 @@ export async function hashFile(file) {
162162 return hash . digest ( 'hex' )
163163}
164164
165+ // macos is not listed explicitly, see below
165166const GitHubHostedPlatforms = [
166167 'ubuntu-20.04-x64' ,
167168 'ubuntu-22.04-x64' ,
168169 'ubuntu-24.04-x64' ,
169- 'macos-12-x64' ,
170- 'macos-13-x64' ,
171- 'macos-13-arm64' ,
172- 'macos-14-x64' ,
173- 'macos-14-arm64' ,
174170 'windows-2019-x64' ,
175171 'windows-2022-x64' ,
176172]
177173
174+ // Precisely: whether we have builds for that platform and there are GitHub-hosted runners to test it
175+ function isSupportedPlatform ( ) {
176+ const platform = getOSName ( )
177+ switch ( platform ) {
178+ case 'ubuntu' :
179+ return GitHubHostedPlatforms . includes ( getOSNameVersionArch ( ) )
180+ case 'macos' :
181+ // See https://github.com/ruby/ruby-builder/blob/master/README.md#naming
182+ // 13 on arm64 because of old macos-arm-oss runners
183+ return ( os . arch ( ) === 'x64' && parseInt ( getOSVersion ( ) ) >= 12 ) ||
184+ ( os . arch ( ) === 'arm64' && parseInt ( getOSVersion ( ) ) >= 13 )
185+ case 'windows' :
186+ return GitHubHostedPlatforms . includes ( getOSNameVersionArch ( ) )
187+ }
188+ }
189+
178190// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
179191export function isSelfHostedRunner ( ) {
180192 if ( inputs . selfHosted === undefined ) {
181193 throw new Error ( 'inputs.selfHosted should have been already set' )
182194 }
183195
184- return inputs . selfHosted === 'true' ||
185- ! GitHubHostedPlatforms . includes ( getOSNameVersionArch ( ) )
196+ return inputs . selfHosted === 'true' || ! isSupportedPlatform ( )
186197}
187198
188199export function selfHostedRunnerReason ( ) {
189200 if ( inputs . selfHosted === 'true' ) {
190201 return 'the self-hosted input was set'
191- } else if ( ! GitHubHostedPlatforms . includes ( getOSNameVersionArch ( ) ) ) {
202+ } else if ( ! isSupportedPlatform ( ) ) {
192203 return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
193204 } else {
194205 return 'unknown reason'
195206 }
196207}
197208
198- let osNameVersion = undefined
209+ let osName = undefined
210+ let osVersion = undefined
199211
200- export function getOSNameVersion ( ) {
201- if ( osNameVersion !== undefined ) {
202- return osNameVersion
212+ export function getOSName ( ) {
213+ if ( osName !== undefined ) {
214+ return osName
203215 }
204216
205217 const platform = os . platform ( )
206- let osName
207- let osVersion
208218 if ( platform === 'linux' ) {
209219 const info = linuxOSInfo ( { mode : 'sync' } )
210220 osName = info . id
211- osVersion = info . version_id
212221 } else if ( platform === 'darwin' ) {
213222 osName = 'macos'
214- osVersion = macosRelease ( ) . version
215223 } else if ( platform === 'win32' ) {
216224 osName = 'windows'
225+ } else {
226+ throw new Error ( `Unknown platform ${ platform } ` )
227+ }
228+
229+ return osName
230+ }
231+
232+ export function getOSVersion ( ) {
233+ if ( osVersion !== undefined ) {
234+ return osVersion
235+ }
236+
237+ const platform = os . platform ( )
238+ if ( platform === 'linux' ) {
239+ const info = linuxOSInfo ( { mode : 'sync' } )
240+ osVersion = info . version_id
241+ } else if ( platform === 'darwin' ) {
242+ osVersion = macosRelease ( ) . version
243+ } else if ( platform === 'win32' ) {
217244 osVersion = findWindowsVersion ( )
218245 } else {
219246 throw new Error ( `Unknown platform ${ platform } ` )
220247 }
221248
222- osNameVersion = `${ osName } -${ osVersion } `
223- return osNameVersion
249+ return osVersion
250+ }
251+
252+ export function getOSNameVersion ( ) {
253+ return `${ getOSName ( ) } -${ getOSVersion ( ) } `
224254}
225255
226256export function getOSNameVersionArch ( ) {
227- return `${ getOSNameVersion ( ) } -${ os . arch ( ) } `
257+ return `${ getOSName ( ) } - ${ getOSVersion ( ) } -${ os . arch ( ) } `
228258}
229259
230260function findWindowsVersion ( ) {
231- const version = os . version ( ) ;
261+ const version = os . version ( )
232262 const match = version . match ( / ^ W i n d o w s S e r v e r ( \d + ) D a t a c e n t e r / )
233263 if ( match ) {
234264 return match [ 1 ]
@@ -261,15 +291,14 @@ export function getRunnerToolCache() {
261291
262292// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
263293function getDefaultToolCachePath ( ) {
264- const platform = getOSNameVersion ( )
265- if ( platform . startsWith ( 'ubuntu-' ) ) {
266- return '/opt/hostedtoolcache'
267- } else if ( platform . startsWith ( 'macos-' ) ) {
268- return '/Users/runner/hostedtoolcache'
269- } else if ( platform . startsWith ( 'windows-' ) ) {
270- return 'C:\\hostedtoolcache\\windows'
271- } else {
272- throw new Error ( 'Unknown platform' )
294+ const platform = getOSName ( )
295+ switch ( platform ) {
296+ case 'ubuntu' :
297+ return '/opt/hostedtoolcache'
298+ case 'macos' :
299+ return '/Users/runner/hostedtoolcache'
300+ case 'windows' :
301+ return 'C:\\hostedtoolcache\\windows'
273302 }
274303}
275304
0 commit comments