@@ -162,73 +162,103 @@ export async function hashFile(file) {
162
162
return hash . digest ( 'hex' )
163
163
}
164
164
165
+ // macos is not listed explicitly, see below
165
166
const GitHubHostedPlatforms = [
166
167
'ubuntu-20.04-x64' ,
167
168
'ubuntu-22.04-x64' ,
168
169
'ubuntu-24.04-x64' ,
169
- 'macos-12-x64' ,
170
- 'macos-13-x64' ,
171
- 'macos-13-arm64' ,
172
- 'macos-14-x64' ,
173
- 'macos-14-arm64' ,
174
170
'windows-2019-x64' ,
175
171
'windows-2022-x64' ,
176
172
]
177
173
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
+
178
190
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
179
191
export function isSelfHostedRunner ( ) {
180
192
if ( inputs . selfHosted === undefined ) {
181
193
throw new Error ( 'inputs.selfHosted should have been already set' )
182
194
}
183
195
184
- return inputs . selfHosted === 'true' ||
185
- ! GitHubHostedPlatforms . includes ( getOSNameVersionArch ( ) )
196
+ return inputs . selfHosted === 'true' || ! isSupportedPlatform ( )
186
197
}
187
198
188
199
export function selfHostedRunnerReason ( ) {
189
200
if ( inputs . selfHosted === 'true' ) {
190
201
return 'the self-hosted input was set'
191
- } else if ( ! GitHubHostedPlatforms . includes ( getOSNameVersionArch ( ) ) ) {
202
+ } else if ( ! isSupportedPlatform ( ) ) {
192
203
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
193
204
} else {
194
205
return 'unknown reason'
195
206
}
196
207
}
197
208
198
- let osNameVersion = undefined
209
+ let osName = undefined
210
+ let osVersion = undefined
199
211
200
- export function getOSNameVersion ( ) {
201
- if ( osNameVersion !== undefined ) {
202
- return osNameVersion
212
+ export function getOSName ( ) {
213
+ if ( osName !== undefined ) {
214
+ return osName
203
215
}
204
216
205
217
const platform = os . platform ( )
206
- let osName
207
- let osVersion
208
218
if ( platform === 'linux' ) {
209
219
const info = linuxOSInfo ( { mode : 'sync' } )
210
220
osName = info . id
211
- osVersion = info . version_id
212
221
} else if ( platform === 'darwin' ) {
213
222
osName = 'macos'
214
- osVersion = macosRelease ( ) . version
215
223
} else if ( platform === 'win32' ) {
216
224
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' ) {
217
244
osVersion = findWindowsVersion ( )
218
245
} else {
219
246
throw new Error ( `Unknown platform ${ platform } ` )
220
247
}
221
248
222
- osNameVersion = `${ osName } -${ osVersion } `
223
- return osNameVersion
249
+ return osVersion
250
+ }
251
+
252
+ export function getOSNameVersion ( ) {
253
+ return `${ getOSName ( ) } -${ getOSVersion ( ) } `
224
254
}
225
255
226
256
export function getOSNameVersionArch ( ) {
227
- return `${ getOSNameVersion ( ) } -${ os . arch ( ) } `
257
+ return `${ getOSName ( ) } - ${ getOSVersion ( ) } -${ os . arch ( ) } `
228
258
}
229
259
230
260
function findWindowsVersion ( ) {
231
- const version = os . version ( ) ;
261
+ const version = os . version ( )
232
262
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 / )
233
263
if ( match ) {
234
264
return match [ 1 ]
@@ -261,15 +291,14 @@ export function getRunnerToolCache() {
261
291
262
292
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
263
293
function 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'
273
302
}
274
303
}
275
304
0 commit comments