Compare commits

...
11 Commits
Author SHA1 Message Date
Benoit Daloze a699edbce6 Add test for ruby-3.0.0-preview1 2020-11-19 00:33:41 +01:00
Benoit Daloze e38f9abc9e Fix usages of string.split(sep, limit)
* Since the limit just removes further matches in JavaScript.
2020-11-19 00:33:40 +01:00
Benoit Daloze 7c2bf7263d Ensure an engine-only ruby-version picks the latest stable version and not a preview or RC 2020-11-18 21:52:51 +01:00
Benoit Daloze 34fbbc1d36 Update README.md 2020-11-16 12:13:08 +01:00
Benoit Daloze 9bc07a3af0 No builds of truffleruby{,-head} on macos-11.0 yet 2020-11-13 10:48:04 +01:00
Benoit Daloze 63dde36864 Remove the Caching bundle install manually section
* It is too error prone and the automatic approach is a lot safer and easier.
2020-11-13 10:38:56 +01:00
Benoit Daloze fde3324171 Remove redundant bundle install in the usage examples 2020-11-13 10:38:56 +01:00
Benoit Daloze 59aafb8612 Add support for macos-11.0 2020-11-13 10:33:21 +01:00
Benoit Daloze ad1ebae995 Also include the version in the platform for macos and windows
* Guess the platform based on $ImageOS.
2020-11-12 20:23:53 +01:00
Benoit Daloze f4a8aa6c33 Use ImageOS for the cache key, so it also includes the OS version 2020-11-12 19:59:05 +01:00
Benoit Daloze bc0f274d1c Fix Bundler cache when there is no Gemfile.lock
* Always show the list of installed gems in the log.
2020-11-12 19:34:43 +01:00
7 changed files with 162 additions and 162 deletions
+6 -2
View File
@@ -15,20 +15,24 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15, windows-2016, windows-2019 ]
os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0, windows-2016, windows-2019 ]
# Use various version syntax here for testing
ruby: [ 2.1, 2.2, 2.3, 2.4, 2.5, 2.6.6, 2.7, ruby-head, debug, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ]
ruby: [ 2.1, 2.2, 2.3, 2.4, 2.5, 2.6.6, 2.7, ruby-3.0.0-preview1, ruby-head, debug, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ]
include:
- { os: windows-2016, ruby: mingw }
- { os: windows-2019, ruby: mingw }
- { os: windows-2019, ruby: mswin }
exclude:
- { os: windows-2016, ruby: ruby-3.0.0-preview1 }
- { os: windows-2016, ruby: debug }
- { os: windows-2016, ruby: truffleruby }
- { os: windows-2016, ruby: truffleruby-head }
- { os: windows-2019, ruby: ruby-3.0.0-preview1 }
- { os: windows-2019, ruby: debug }
- { os: windows-2019, ruby: truffleruby }
- { os: windows-2019, ruby: truffleruby-head }
- { os: macos-11.0, ruby: truffleruby }
- { os: macos-11.0, ruby: truffleruby-head }
name: ${{ matrix.os }} ${{ matrix.ruby }}
runs-on: ${{ matrix.os }}
+2 -32
View File
@@ -39,7 +39,7 @@ The action works for all [GitHub-hosted runners](https://help.github.com/en/acti
| Operating System | Recommended | Other Supported Versions |
| ----------- | -------- | -------- |
| Ubuntu | `ubuntu-latest` (= `ubuntu-18.04`) | `ubuntu-20.04`, `ubuntu-16.04` |
| macOS | `macos-latest` (= `macos-10.15`) | |
| macOS | `macos-latest` (= `macos-10.15`) | `macos-11.0` |
| Windows | `windows-latest` (= `windows-2019`) | `windows-2016` |
The prebuilt releases are generated by [ruby-builder](https://github.com/ruby/ruby-builder)
@@ -67,7 +67,6 @@ jobs:
with:
ruby-version: 2.6 # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- run: bundle install
- run: bundle exec rake
```
@@ -93,7 +92,6 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- run: bundle install
- run: bundle exec rake
```
@@ -142,35 +140,6 @@ If there is a `Gemfile.lock` (or `$BUNDLE_GEMFILE.lock` or `gems.locked`), `bund
To perform caching, this action will use `bundle config --local path vendor/bundle`.
Therefore, the Bundler `path` should not be changed in your workflow for the cache to work (no `bundle config path`).
### Caching `bundle install` manually
You can also cache gems manually,
but this is not recommended because it is verbose and very difficult to use a correct cache key.
You can cache the installed gems with these two steps:
```yaml
- uses: actions/cache@v2
with:
path: vendor/bundle
key: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-
- name: bundle install
run: |
bundle config deployment true
bundle config path vendor/bundle
bundle install --jobs 4
```
When using a single OS, replace `${{ matrix.os }}` with the OS.
When using a single job with a Ruby version, replace `${{ matrix.ruby }}` with the Ruby version.
When using `.ruby-version`, replace `${{ matrix.ruby }}` with `${{ hashFiles('.ruby-version') }}`.
When using `.tool-versions`, replace `${{ matrix.ruby }}` with `${{ hashFiles('.tool-versions') }}`.
This uses the [cache action](https://github.com/actions/cache).
The code above is a more complete version of the [Ruby - Bundler example](https://github.com/actions/cache/blob/master/examples.md#ruby---bundler).
Make sure to include `use-ruby` in the `key` to avoid conflicting with previous caches.
## Windows
Note that running CI on Windows can be quite challenging if you are not very familiar with Windows.
@@ -201,6 +170,7 @@ This action might work with [self-hosted runners](https://docs.github.com/en/act
if the [virtual environment](https://github.com/actions/virtual-environments) is very similar to the ones used by GitHub runners. Notably:
* Make sure to use the same operating system and version.
* Set the environment variable `ImageOS` to the corresponding value on GitHub-hosted runners (e.g. `ubuntu18`/`macos1015`/`win19`). This is necessary to detect the operating system and version.
* Make sure to use the same version of libssl.
* Make sure that the operating system has `libyaml-0` installed
* The default tool cache directory (`/opt/hostedtoolcache` on Linux, `/Users/runner/hostedtoolcache` on macOS,
+35 -17
View File
@@ -11,6 +11,14 @@ export const windows = (os.platform() === 'win32')
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
export const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined)
export function partition(string, separator) {
const i = string.indexOf(separator)
if (i === -1) {
throw new Error(`No separator ${separator} in string ${string}`)
}
return [string.slice(0, i), string.slice(i + separator.length, string.length)]
}
export async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
@@ -28,6 +36,10 @@ export function isHeadVersion(rubyVersion) {
return rubyVersion === 'head' || rubyVersion === 'debug' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
}
export function isStableVersion(rubyVersion) {
return /^\d+(\.\d+)*$/.test(rubyVersion)
}
export async function hashFile(file) {
// See https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts
const hash = crypto.createHash('sha256')
@@ -36,27 +48,33 @@ export async function hashFile(file) {
return hash.digest('hex')
}
export function getVirtualEnvironmentName() {
const platform = os.platform()
if (platform === 'linux') {
return `ubuntu-${findUbuntuVersion()}`
} else if (platform === 'darwin') {
return 'macos-latest'
} else if (platform === 'win32') {
return 'windows-latest'
} else {
throw new Error(`Unknown platform ${platform}`)
function getImageOS() {
const imageOS = process.env['ImageOS']
if (!imageOS) {
throw new Error('The environment variable ImageOS must be set')
}
return imageOS
}
function findUbuntuVersion() {
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
export function getVirtualEnvironmentName() {
const imageOS = getImageOS()
let match = imageOS.match(/^ubuntu(\d+)/) // e.g. ubuntu18
if (match) {
return match[1]
} else {
throw new Error('Could not find Ubuntu version')
return `ubuntu-${match[1]}.04`
}
match = imageOS.match(/^macos(\d{2})(\d+)?/) // e.g. macos1015, macos11
if (match) {
return `macos-${match[1]}.${match[2] || '0'}`
}
match = imageOS.match(/^win(\d+)/) // e.g. win19
if (match) {
return `windows-20${match[1]}`
}
throw new Error(`Unknown ImageOS ${imageOS}`)
}
export function shouldExtractInToolCache(engine, version) {
@@ -85,7 +103,7 @@ export function getToolCacheRubyPrefix(platform, version) {
export function win2nix(path) {
if (/^[A-Z]:/i.test(path)) {
// path starts with drive
path = `/${path[0].toLowerCase()}${path.split(':', 2)[1]}`
path = `/${path[0].toLowerCase()}${partition(path, ':')[1]}`
}
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
}
Generated Vendored
+78 -64
View File
@@ -27796,7 +27796,7 @@ function addVCVARSEnv() {
let newSet = cp.execSync(cmd).toString().trim().split(/\r?\n/)
newSet = newSet.filter(line => line.match(/\S=\S/))
newSet.forEach(s => {
let [k,v] = s.split('=', 2)
let [k,v] = common.partition(s, '=')
newEnv.set(k,v)
})
@@ -32094,8 +32094,10 @@ exports.default = _default;
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "windows", function() { return windows; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "drive", function() { return drive; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "partition", function() { return partition; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "measure", function() { return measure; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isHeadVersion", function() { return isHeadVersion; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isStableVersion", function() { return isStableVersion; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hashFile", function() { return hashFile; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVirtualEnvironmentName", function() { return getVirtualEnvironmentName; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shouldExtractInToolCache", function() { return shouldExtractInToolCache; });
@@ -32115,6 +32117,14 @@ const windows = (os.platform() === 'win32')
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined)
function partition(string, separator) {
const i = string.indexOf(separator)
if (i === -1) {
throw new Error(`No separator ${separator} in string ${string}`)
}
return [string.slice(0, i), string.slice(i + separator.length, string.length)]
}
async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
@@ -32132,6 +32142,10 @@ function isHeadVersion(rubyVersion) {
return rubyVersion === 'head' || rubyVersion === 'debug' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
}
function isStableVersion(rubyVersion) {
return /^\d+(\.\d+)*$/.test(rubyVersion)
}
async function hashFile(file) {
// See https://github.com/actions/runner/blob/master/src/Misc/expressionFunc/hashFiles/src/hashFiles.ts
const hash = crypto.createHash('sha256')
@@ -32140,27 +32154,33 @@ async function hashFile(file) {
return hash.digest('hex')
}
function getVirtualEnvironmentName() {
const platform = os.platform()
if (platform === 'linux') {
return `ubuntu-${findUbuntuVersion()}`
} else if (platform === 'darwin') {
return 'macos-latest'
} else if (platform === 'win32') {
return 'windows-latest'
} else {
throw new Error(`Unknown platform ${platform}`)
function getImageOS() {
const imageOS = process.env['ImageOS']
if (!imageOS) {
throw new Error('The environment variable ImageOS must be set')
}
return imageOS
}
function findUbuntuVersion() {
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
function getVirtualEnvironmentName() {
const imageOS = getImageOS()
let match = imageOS.match(/^ubuntu(\d+)/) // e.g. ubuntu18
if (match) {
return match[1]
} else {
throw new Error('Could not find Ubuntu version')
return `ubuntu-${match[1]}.04`
}
match = imageOS.match(/^macos(\d{2})(\d+)?/) // e.g. macos1015, macos11
if (match) {
return `macos-${match[1]}.${match[2] || '0'}`
}
match = imageOS.match(/^win(\d+)/) // e.g. win19
if (match) {
return `windows-20${match[1]}`
}
throw new Error(`Unknown ImageOS ${imageOS}`)
}
function shouldExtractInToolCache(engine, version) {
@@ -32189,7 +32209,7 @@ function getToolCacheRubyPrefix(platform, version) {
function win2nix(path) {
if (/^[A-Z]:/i.test(path)) {
// path starts with drive
path = `/${path[0].toLowerCase()}${path.split(':', 2)[1]}`
path = `/${path[0].toLowerCase()}${partition(path, ':')[1]}`
}
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
}
@@ -51227,25 +51247,15 @@ async function setupRuby(options = {}) {
core.setOutput('ruby-prefix', rubyPrefix)
}
// The returned gemfile is guaranteed to exist, the lockfile might not exist
function detectGemfiles() {
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
if (fs.existsSync(gemfilePath)) {
const lockPath = `${gemfilePath}.lock`
if (fs.existsSync(lockPath)) {
return [gemfilePath, lockPath]
} else {
return [gemfilePath, null]
}
return [gemfilePath, `${gemfilePath}.lock`]
}
const gemsRbPath = "gems.rb"
if (fs.existsSync(gemsRbPath)) {
const lockPath = "gems.locked"
if (fs.existsSync(lockPath)) {
return [gemsRbPath, lockPath]
} else {
return [gemsRbPath, null]
}
if (fs.existsSync("gems.rb")) {
return ["gems.rb", "gems.locked"]
}
return [null, null]
@@ -51268,7 +51278,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
} else if (rubyVersion === '.tool-versions') { // Read from .tool-versions
const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim()
const rubyLine = toolVersions.split(/\r?\n/).filter(e => e.match(/^ruby\s/))[0]
rubyVersion = rubyLine.split(/\s+/, 2)[1]
rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1]
console.log(`Using ${rubyVersion} as input from file .tool-versions`)
}
@@ -51280,7 +51290,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
engine = rubyVersion
version = '' // Let the logic in validateRubyEngineAndVersion() find the version
} else { // engine-X.Y.Z
[engine, version] = rubyVersion.split('-', 2)
[engine, version] = common.partition(rubyVersion, '-')
}
return [engine, version]
@@ -51294,7 +51304,7 @@ function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVe
let version = parsedVersion
if (!engineVersions.includes(parsedVersion)) {
const latestToFirstVersion = engineVersions.slice().reverse()
const found = latestToFirstVersion.find(v => !common.isHeadVersion(v) && v.startsWith(parsedVersion))
const found = latestToFirstVersion.find(v => common.isStableVersion(v) && v.startsWith(parsedVersion))
if (found) {
version = found
} else {
@@ -51329,7 +51339,7 @@ function envPreInstall() {
}
function readBundledWithFromGemfileLock(lockFile) {
if (lockFile !== null) {
if (lockFile !== null && fs.existsSync(lockFile)) {
const contents = fs.readFileSync(lockFile, 'utf8')
const lines = contents.split(/\r?\n/)
const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
@@ -51397,24 +51407,22 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
// config
const path = 'vendor/bundle'
if (lockFile !== null) {
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
}
await exec.exec('bundle', ['config', '--local', 'path', path])
if (fs.existsSync(lockFile)) {
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
} else {
// Generate the lockfile so we can use it to compute the cache key.
// This will also automatically pick up the latest gem versions compatible with the Gemfile.
await exec.exec('bundle', ['lock'])
}
// cache key
const paths = [path]
const baseKey = await computeBaseKey(platform, engine, version, gemfile)
let key = baseKey
let restoreKeys
if (lockFile !== null) {
key += `-${lockFile}-${await common.hashFile(lockFile)}`
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
restoreKeys = [`${baseKey}-${lockFile}-`]
} else {
// Only exact key, to never mix native gems of different platforms or Ruby versions
restoreKeys = []
}
const baseKey = await computeBaseKey(platform, engine, version, lockFile)
const key = `${baseKey}-${await common.hashFile(lockFile)}`
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
const restoreKeys = [`${baseKey}-`]
console.log(`Cache key: ${key}`)
// restore cache & install
@@ -51433,15 +51441,11 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
console.log(`Found cache for key: ${cachedKey}`)
}
let alreadyInstalled = false
if (cachedKey === key) {
const exitCode = await exec.exec('bundle', ['check'], { ignoreReturnCode: true })
alreadyInstalled = (exitCode === 0)
}
if (!alreadyInstalled) {
await exec.exec('bundle', ['install', '--jobs', '4'])
// Always run 'bundle install' to list the gems
await exec.exec('bundle', ['install', '--jobs', '4'])
// @actions/cache only allows to save for non-existing keys
if (cachedKey !== key) {
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
console.log('Saving cache')
try {
@@ -51460,8 +51464,9 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
return true
}
async function computeBaseKey(platform, engine, version, gemfile) {
let baseKey = `setup-ruby-toolcache-bundle-install-${platform}-${engine}-${version}-${gemfile}`
async function computeBaseKey(platform, engine, version, lockFile) {
let key = `setup-ruby-bundler-cache-v2-${platform}-${engine}-${version}`
if (engine !== 'jruby' && common.isHeadVersion(version)) {
let revision = '';
await exec.exec('ruby', ['-e', 'print RUBY_REVISION'], {
@@ -51472,9 +51477,11 @@ async function computeBaseKey(platform, engine, version, gemfile) {
}
}
});
baseKey += `-revision-${revision}`
key += `-revision-${revision}`
}
return baseKey
key += `-${lockFile}`
return key
}
if (__filename.endsWith('index.js')) { run() }
@@ -52948,10 +52955,17 @@ async function downloadAndExtract(platform, engine, version) {
}
function getDownloadURL(platform, engine, version) {
let builderPlatform = platform
if (platform.startsWith('windows-')) {
builderPlatform = 'windows-latest'
} else if (platform.startsWith('macos-')) {
builderPlatform = 'macos-latest'
}
if (common.isHeadVersion(version)) {
return getLatestHeadBuildURL(platform, engine, version)
return getLatestHeadBuildURL(builderPlatform, engine, version)
} else {
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${platform}.tar.gz`
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${builderPlatform}.tar.gz`
}
}
+31 -44
View File
@@ -75,25 +75,15 @@ export async function setupRuby(options = {}) {
core.setOutput('ruby-prefix', rubyPrefix)
}
// The returned gemfile is guaranteed to exist, the lockfile might not exist
function detectGemfiles() {
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
if (fs.existsSync(gemfilePath)) {
const lockPath = `${gemfilePath}.lock`
if (fs.existsSync(lockPath)) {
return [gemfilePath, lockPath]
} else {
return [gemfilePath, null]
}
return [gemfilePath, `${gemfilePath}.lock`]
}
const gemsRbPath = "gems.rb"
if (fs.existsSync(gemsRbPath)) {
const lockPath = "gems.locked"
if (fs.existsSync(lockPath)) {
return [gemsRbPath, lockPath]
} else {
return [gemsRbPath, null]
}
if (fs.existsSync("gems.rb")) {
return ["gems.rb", "gems.locked"]
}
return [null, null]
@@ -116,7 +106,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
} else if (rubyVersion === '.tool-versions') { // Read from .tool-versions
const toolVersions = fs.readFileSync('.tool-versions', 'utf8').trim()
const rubyLine = toolVersions.split(/\r?\n/).filter(e => e.match(/^ruby\s/))[0]
rubyVersion = rubyLine.split(/\s+/, 2)[1]
rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1]
console.log(`Using ${rubyVersion} as input from file .tool-versions`)
}
@@ -128,7 +118,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
engine = rubyVersion
version = '' // Let the logic in validateRubyEngineAndVersion() find the version
} else { // engine-X.Y.Z
[engine, version] = rubyVersion.split('-', 2)
[engine, version] = common.partition(rubyVersion, '-')
}
return [engine, version]
@@ -142,7 +132,7 @@ function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVe
let version = parsedVersion
if (!engineVersions.includes(parsedVersion)) {
const latestToFirstVersion = engineVersions.slice().reverse()
const found = latestToFirstVersion.find(v => !common.isHeadVersion(v) && v.startsWith(parsedVersion))
const found = latestToFirstVersion.find(v => common.isStableVersion(v) && v.startsWith(parsedVersion))
if (found) {
version = found
} else {
@@ -177,7 +167,7 @@ function envPreInstall() {
}
function readBundledWithFromGemfileLock(lockFile) {
if (lockFile !== null) {
if (lockFile !== null && fs.existsSync(lockFile)) {
const contents = fs.readFileSync(lockFile, 'utf8')
const lines = contents.split(/\r?\n/)
const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
@@ -245,24 +235,22 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
// config
const path = 'vendor/bundle'
if (lockFile !== null) {
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
}
await exec.exec('bundle', ['config', '--local', 'path', path])
if (fs.existsSync(lockFile)) {
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
} else {
// Generate the lockfile so we can use it to compute the cache key.
// This will also automatically pick up the latest gem versions compatible with the Gemfile.
await exec.exec('bundle', ['lock'])
}
// cache key
const paths = [path]
const baseKey = await computeBaseKey(platform, engine, version, gemfile)
let key = baseKey
let restoreKeys
if (lockFile !== null) {
key += `-${lockFile}-${await common.hashFile(lockFile)}`
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
restoreKeys = [`${baseKey}-${lockFile}-`]
} else {
// Only exact key, to never mix native gems of different platforms or Ruby versions
restoreKeys = []
}
const baseKey = await computeBaseKey(platform, engine, version, lockFile)
const key = `${baseKey}-${await common.hashFile(lockFile)}`
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
const restoreKeys = [`${baseKey}-`]
console.log(`Cache key: ${key}`)
// restore cache & install
@@ -281,15 +269,11 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
console.log(`Found cache for key: ${cachedKey}`)
}
let alreadyInstalled = false
if (cachedKey === key) {
const exitCode = await exec.exec('bundle', ['check'], { ignoreReturnCode: true })
alreadyInstalled = (exitCode === 0)
}
if (!alreadyInstalled) {
await exec.exec('bundle', ['install', '--jobs', '4'])
// Always run 'bundle install' to list the gems
await exec.exec('bundle', ['install', '--jobs', '4'])
// @actions/cache only allows to save for non-existing keys
if (cachedKey !== key) {
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
console.log('Saving cache')
try {
@@ -308,8 +292,9 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
return true
}
async function computeBaseKey(platform, engine, version, gemfile) {
let baseKey = `setup-ruby-toolcache-bundle-install-${platform}-${engine}-${version}-${gemfile}`
async function computeBaseKey(platform, engine, version, lockFile) {
let key = `setup-ruby-bundler-cache-v2-${platform}-${engine}-${version}`
if (engine !== 'jruby' && common.isHeadVersion(version)) {
let revision = '';
await exec.exec('ruby', ['-e', 'print RUBY_REVISION'], {
@@ -320,9 +305,11 @@ async function computeBaseKey(platform, engine, version, gemfile) {
}
}
});
baseKey += `-revision-${revision}`
key += `-revision-${revision}`
}
return baseKey
key += `-${lockFile}`
return key
}
if (__filename.endsWith('index.js')) { run() }
+9 -2
View File
@@ -57,10 +57,17 @@ async function downloadAndExtract(platform, engine, version) {
}
function getDownloadURL(platform, engine, version) {
let builderPlatform = platform
if (platform.startsWith('windows-')) {
builderPlatform = 'windows-latest'
} else if (platform.startsWith('macos-')) {
builderPlatform = 'macos-latest'
}
if (common.isHeadVersion(version)) {
return getLatestHeadBuildURL(platform, engine, version)
return getLatestHeadBuildURL(builderPlatform, engine, version)
} else {
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${platform}.tar.gz`
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${builderPlatform}.tar.gz`
}
}
+1 -1
View File
@@ -120,7 +120,7 @@ export function addVCVARSEnv() {
let newSet = cp.execSync(cmd).toString().trim().split(/\r?\n/)
newSet = newSet.filter(line => line.match(/\S=\S/))
newSet.forEach(s => {
let [k,v] = s.split('=', 2)
let [k,v] = common.partition(s, '=')
newEnv.set(k,v)
})