Skip to content

Commit

Permalink
Add support for macos-15 and all future macos runners
Browse files Browse the repository at this point in the history
* Fixes #647
  • Loading branch information
eregon committed Sep 25, 2024
1 parent 5496baa commit 17f5c91
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 60 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14, windows-2019, windows-2022 ]
os: [ ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14, macos-15, windows-2019, windows-2022 ]
ruby: [
'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,
jruby, jruby-head,
Expand All @@ -35,14 +35,21 @@ jobs:
- { os: ubuntu-22.04, ruby: '2.2' }
- { os: ubuntu-24.04, ruby: '1.9' }
- { os: ubuntu-24.04, ruby: '2.2' }
# These old Rubies fail to compile on macos-14 (macOS 14, arm64), which is used for ruby/ruby-builder
# These old Rubies fail to compile on macOS arm64
- { os: macos-14, ruby: '1.9' }
- { os: macos-14, ruby: '2.0' }
- { os: macos-14, ruby: '2.1' }
- { os: macos-14, ruby: '2.2' }
- { os: macos-14, ruby: '2.3' }
- { os: macos-14, ruby: '2.4' }
- { os: macos-14, ruby: '2.5' }
- { os: macos-15, ruby: '1.9' }
- { os: macos-15, ruby: '2.0' }
- { os: macos-15, ruby: '2.1' }
- { os: macos-15, ruby: '2.2' }
- { os: macos-15, ruby: '2.3' }
- { os: macos-15, ruby: '2.4' }
- { os: macos-15, ruby: '2.5' }
# Windows
- { os: windows-2019, ruby: '1.9' }
- { os: windows-2019, ruby: debug }
Expand Down
87 changes: 58 additions & 29 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,73 +162,103 @@ export async function hashFile(file) {
return hash.digest('hex')
}

// macos is not listed explicitly, see below
const GitHubHostedPlatforms = [
'ubuntu-20.04-x64',
'ubuntu-22.04-x64',
'ubuntu-24.04-x64',
'macos-12-x64',
'macos-13-x64',
'macos-13-arm64',
'macos-14-x64',
'macos-14-arm64',
'windows-2019-x64',
'windows-2022-x64',
]

// Precisely: whether we have builds for that platform and there are GitHub-hosted runners to test it
function isSupportedPlatform() {
const platform = getOSName()
switch (platform) {
case 'ubuntu':
return GitHubHostedPlatforms.includes(getOSNameVersionArch())
case 'macos':
// See https://github.com/ruby/ruby-builder/blob/master/README.md#naming
// 13 on arm64 because of old macos-arm-oss runners
return (os.arch() === 'x64' && parseInt(getOSVersion()) >= 12) ||
(os.arch() === 'arm64' && parseInt(getOSVersion()) >= 13)
case 'windows':
return GitHubHostedPlatforms.includes(getOSNameVersionArch())
}
}

// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
export function isSelfHostedRunner() {
if (inputs.selfHosted === undefined) {
throw new Error('inputs.selfHosted should have been already set')
}

return inputs.selfHosted === 'true' ||
!GitHubHostedPlatforms.includes(getOSNameVersionArch())
return inputs.selfHosted === 'true' || !isSupportedPlatform()
}

export function selfHostedRunnerReason() {
if (inputs.selfHosted === 'true') {
return 'the self-hosted input was set'
} else if (!GitHubHostedPlatforms.includes(getOSNameVersionArch())) {
} else if (!isSupportedPlatform()) {
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
} else {
return 'unknown reason'
}
}

let osNameVersion = undefined
let osName = undefined
let osVersion = undefined

export function getOSNameVersion() {
if (osNameVersion !== undefined) {
return osNameVersion
export function getOSName() {
if (osName !== undefined) {
return osName
}

const platform = os.platform()
let osName
let osVersion
if (platform === 'linux') {
const info = linuxOSInfo({mode: 'sync'})
osName = info.id
osVersion = info.version_id
} else if (platform === 'darwin') {
osName = 'macos'
osVersion = macosRelease().version
} else if (platform === 'win32') {
osName = 'windows'
} else {
throw new Error(`Unknown platform ${platform}`)
}

return osName
}

export function getOSVersion() {
if (osVersion !== undefined) {
return osVersion
}

const platform = os.platform()
if (platform === 'linux') {
const info = linuxOSInfo({mode: 'sync'})
osVersion = info.version_id
} else if (platform === 'darwin') {
osVersion = macosRelease().version
} else if (platform === 'win32') {
osVersion = findWindowsVersion()
} else {
throw new Error(`Unknown platform ${platform}`)
}

osNameVersion = `${osName}-${osVersion}`
return osNameVersion
return osVersion
}

export function getOSNameVersion() {
return `${getOSName()}-${getOSVersion()}`
}

export function getOSNameVersionArch() {
return `${getOSNameVersion()}-${os.arch()}`
return `${getOSName()}-${getOSVersion()}-${os.arch()}`
}

function findWindowsVersion() {
const version = os.version();
const version = os.version()
const match = version.match(/^Windows Server (\d+) Datacenter/)
if (match) {
return match[1]
Expand Down Expand Up @@ -261,15 +291,14 @@ export function getRunnerToolCache() {

// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
function getDefaultToolCachePath() {
const platform = getOSNameVersion()
if (platform.startsWith('ubuntu-')) {
return '/opt/hostedtoolcache'
} else if (platform.startsWith('macos-')) {
return '/Users/runner/hostedtoolcache'
} else if (platform.startsWith('windows-')) {
return 'C:\\hostedtoolcache\\windows'
} else {
throw new Error('Unknown platform')
const platform = getOSName()
switch (platform) {
case 'ubuntu':
return '/opt/hostedtoolcache'
case 'macos':
return '/Users/runner/hostedtoolcache'
case 'windows':
return 'C:\\hostedtoolcache\\windows'
}
}

Expand Down
89 changes: 60 additions & 29 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 17f5c91

Please sign in to comment.