Skip to content

Commit ad1ebae

Browse files
committed
Also include the version in the platform for macos and windows
* Guess the platform based on $ImageOS.
1 parent f4a8aa6 commit ad1ebae

File tree

4 files changed

+60
-51
lines changed

4 files changed

+60
-51
lines changed

common.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,33 @@ export async function hashFile(file) {
3636
return hash.digest('hex')
3737
}
3838

39-
export function getVirtualEnvironmentName() {
40-
const platform = os.platform()
41-
if (platform === 'linux') {
42-
return `ubuntu-${findUbuntuVersion()}`
43-
} else if (platform === 'darwin') {
44-
return 'macos-latest'
45-
} else if (platform === 'win32') {
46-
return 'windows-latest'
47-
} else {
48-
throw new Error(`Unknown platform ${platform}`)
39+
function getImageOS() {
40+
const imageOS = process.env['ImageOS']
41+
if (!imageOS) {
42+
throw new Error('The environment variable ImageOS must be set')
4943
}
44+
return imageOS
5045
}
5146

52-
function findUbuntuVersion() {
53-
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
54-
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
47+
export function getVirtualEnvironmentName() {
48+
const imageOS = getImageOS()
49+
50+
let match = imageOS.match(/^ubuntu(\d+)/) // e.g. ubuntu18
5551
if (match) {
56-
return match[1]
57-
} else {
58-
throw new Error('Could not find Ubuntu version')
52+
return `ubuntu-${match[1]}.04`
5953
}
60-
}
6154

62-
export function getImageOS() {
63-
const imageOS = process.env['ImageOS']
64-
if (!imageOS) {
65-
throw new Error('The environment variable ImageOS must be set')
55+
match = imageOS.match(/^macos(\d{2})(\d+)/) // e.g. macos1015
56+
if (match) {
57+
return `macos-${match[1]}.${match[2]}`
6658
}
67-
return imageOS
59+
60+
match = imageOS.match(/^win(\d+)/) // e.g. win19
61+
if (match) {
62+
return `windows-20${match[1]}`
63+
}
64+
65+
throw new Error(`Unknown ImageOS ${imageOS}`)
6866
}
6967

7068
export function shouldExtractInToolCache(engine, version) {

dist/index.js

Lines changed: 30 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
293293
}
294294

295295
async function computeBaseKey(platform, engine, version, lockFile) {
296-
let key = `setup-ruby-bundler-cache-v2-${common.getImageOS()}-${engine}-${version}`
296+
let key = `setup-ruby-bundler-cache-v2-${platform}-${engine}-${version}`
297297

298298
if (engine !== 'jruby' && common.isHeadVersion(version)) {
299299
let revision = '';

ruby-builder.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ async function downloadAndExtract(platform, engine, version) {
5757
}
5858

5959
function getDownloadURL(platform, engine, version) {
60+
let builderPlatform = platform
61+
if (platform.startsWith('windows-')) {
62+
builderPlatform = 'windows-latest'
63+
} else if (platform.startsWith('macos-')) {
64+
builderPlatform = 'macos-latest'
65+
}
66+
6067
if (common.isHeadVersion(version)) {
61-
return getLatestHeadBuildURL(platform, engine, version)
68+
return getLatestHeadBuildURL(builderPlatform, engine, version)
6269
} else {
63-
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${platform}.tar.gz`
70+
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${builderPlatform}.tar.gz`
6471
}
6572
}
6673

0 commit comments

Comments
 (0)