Skip to content

Commit 17f5c91

Browse files
committed
Add support for macos-15 and all future macos runners
* Fixes #647
1 parent 5496baa commit 17f5c91

File tree

3 files changed

+127
-60
lines changed

3 files changed

+127
-60
lines changed

.github/workflows/test.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14, windows-2019, windows-2022 ]
20+
os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14, macos-15, windows-2019, windows-2022 ]
2121
ruby: [
2222
'1.9', '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', ruby-head,
2323
jruby, jruby-head,
@@ -35,14 +35,21 @@ jobs:
3535
- { os: ubuntu-22.04, ruby: '2.2' }
3636
- { os: ubuntu-24.04, ruby: '1.9' }
3737
- { os: ubuntu-24.04, ruby: '2.2' }
38-
# These old Rubies fail to compile on macos-14 (macOS 14, arm64), which is used for ruby/ruby-builder
38+
# These old Rubies fail to compile on macOS arm64
3939
- { os: macos-14, ruby: '1.9' }
4040
- { os: macos-14, ruby: '2.0' }
4141
- { os: macos-14, ruby: '2.1' }
4242
- { os: macos-14, ruby: '2.2' }
4343
- { os: macos-14, ruby: '2.3' }
4444
- { os: macos-14, ruby: '2.4' }
4545
- { os: macos-14, ruby: '2.5' }
46+
- { os: macos-15, ruby: '1.9' }
47+
- { os: macos-15, ruby: '2.0' }
48+
- { os: macos-15, ruby: '2.1' }
49+
- { os: macos-15, ruby: '2.2' }
50+
- { os: macos-15, ruby: '2.3' }
51+
- { os: macos-15, ruby: '2.4' }
52+
- { os: macos-15, ruby: '2.5' }
4653
# Windows
4754
- { os: windows-2019, ruby: '1.9' }
4855
- { os: windows-2019, ruby: debug }

common.js

+58-29
Original file line numberDiff line numberDiff line change
@@ -162,73 +162,103 @@ export async function hashFile(file) {
162162
return hash.digest('hex')
163163
}
164164

165+
// macos is not listed explicitly, see below
165166
const 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,
179191
export 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

188199
export 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

226256
export function getOSNameVersionArch() {
227-
return `${getOSNameVersion()}-${os.arch()}`
257+
return `${getOSName()}-${getOSVersion()}-${os.arch()}`
228258
}
229259

230260
function findWindowsVersion() {
231-
const version = os.version();
261+
const version = os.version()
232262
const match = version.match(/^Windows Server (\d+) Datacenter/)
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
263293
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'
273302
}
274303
}
275304

dist/index.js

+60-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)