mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 14:34:21 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fdcfbcf14e | ||
|
|
a358e49b56 | ||
|
|
6e288cd651 | ||
|
|
3ab5bf6391 | ||
|
|
1891d63a08 | ||
|
|
c782da25bd | ||
|
|
5aaa89ff0d | ||
|
|
3460195737 | ||
|
|
d195ecb9ec | ||
|
|
c34fe21c5f | ||
|
|
324b8ce0e9 | ||
|
|
ce63da5b3b | ||
|
|
0d3b8b502e | ||
|
|
2320cdc287 | ||
|
|
95193d6d48 | ||
|
|
9aeedd9a81 | ||
|
|
72d75bd883 | ||
|
|
473e4d8fe5 | ||
|
|
3cb8cff23d | ||
|
|
f36eef7a2f | ||
|
|
ec4649be90 | ||
|
|
1771151f64 | ||
|
|
f5db46ebcb | ||
|
|
dc58db7220 | ||
|
|
0e7d36a67f | ||
|
|
e5b6990d51 | ||
|
|
c3f248a282 | ||
|
|
a9926985f9 | ||
|
|
07b100f2a1 | ||
|
|
515629a013 | ||
|
|
0981b5ec00 | ||
|
|
c101335f33 | ||
|
|
1482e9180a | ||
|
|
3e7640a17e | ||
|
|
f6f61ea575 | ||
|
|
084885eaca |
@@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
Before filing this issue:
|
||||
* If the issue happens on JRuby or TruffleRuby, and does not happen on CRuby (please check), file an issue there instead. It's very unlikely ruby/setup-ruby is the cause.
|
||||
* Try to reproduce the issue locally by following the workflow steps (including all all commands done by ruby/setup-ruby, except for `Downloading Ruby` & `Extracting Ruby`). If it does reproduce locally, it's not a ruby/setup-ruby issue.
|
||||
|
||||
Please provide:
|
||||
* the code of or a link to the workflow used
|
||||
* the link to the log of a failed workflow job
|
||||
* the command and output of the step failing
|
||||
-->
|
||||
@@ -15,23 +15,20 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0, windows-2016, windows-2019 ]
|
||||
os: [ 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, '3.0', 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, '3.0', ruby-head, 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: '3.0' }
|
||||
- { os: windows-2016, ruby: debug }
|
||||
- { os: windows-2016, ruby: truffleruby }
|
||||
- { os: windows-2016, ruby: truffleruby-head }
|
||||
- { os: windows-2019, ruby: '3.0' }
|
||||
- { os: windows-2019, ruby: debug }
|
||||
- { os: windows-2019, ruby: truffleruby }
|
||||
- { os: windows-2019, ruby: truffleruby-head }
|
||||
- { os: macos-11.0, ruby: truffleruby }
|
||||
|
||||
name: ${{ matrix.os }} ${{ matrix.ruby }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
@@ -102,6 +99,61 @@ jobs:
|
||||
if: startsWith(matrix.os, 'windows') && startsWith(matrix.ruby, 'jruby')
|
||||
run: gem install sassc -N
|
||||
|
||||
testExactBundlerVersion:
|
||||
name: "Test with an exact Bundler version"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
bundler: 2.2.3
|
||||
- run: bundle --version | grep -F "Bundler version 2.2.3"
|
||||
|
||||
testDependencyOnBundler1:
|
||||
name: "Test gemfile depending on Bundler 1"
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BUNDLE_GEMFILE: gemfiles/bundler1.gemfile
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
ruby-version: 2.7
|
||||
bundler: 1
|
||||
bundler-cache: true
|
||||
- run: bundle --version | grep -F "Bundler version 1."
|
||||
|
||||
testGemfileMatrix:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
gemfile: [ rails5, rails6 ]
|
||||
name: "Test with ${{ matrix.gemfile }} gemfile"
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
bundler-cache: true
|
||||
- run: bundle exec rails --version
|
||||
|
||||
testTruffleRubyNokogiri:
|
||||
name: "Test installing a Gemfile with nokogiri on TruffleRuby"
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BUNDLE_GEMFILE: gemfiles/nokogiri.gemfile
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
ruby-version: truffleruby-head
|
||||
bundler-cache: true
|
||||
- run: bundle list | grep nokogiri
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
|
||||
@@ -14,9 +14,9 @@ This action currently supports these versions of MRI, JRuby and TruffleRuby:
|
||||
|
||||
| Interpreter | Versions |
|
||||
| ----------- | -------- |
|
||||
| `ruby` | 2.1.9, 2.2, 2.3.0 - 2.3.8, 2.4.0 - 2.4.10, 2.5.0 - 2.5.8, 2.6.0 - 2.6.6, 2.7.2, head, debug, mingw, mswin |
|
||||
| `ruby` | 2.1.9, 2.2, 2.3.0 - 2.3.8, 2.4.0 - 2.4.10, 2.5.0 - 2.5.8, 2.6.0 - 2.6.6, 2.7.2, 3.0.0, head, debug, mingw, mswin |
|
||||
| `jruby` | 9.1.17.0, 9.2.9.0 - 9.2.13.0, head |
|
||||
| `truffleruby` | 19.3.0 - 20.3.0, head |
|
||||
| `truffleruby` | 19.3.0 - 21.0.0, head |
|
||||
|
||||
`ruby-debug` is the same as `ruby-head` but with assertions enabled (`-DRUBY_DEBUG=1`).
|
||||
On Windows, `mingw` and `mswin` are `ruby-head` builds using the MSYS2/MinGW and the MSVC toolchains respectively.
|
||||
@@ -57,7 +57,7 @@ for Ubuntu and macOS and in [windows-versions.js](windows-versions.js) for Windo
|
||||
|
||||
```yaml
|
||||
name: My workflow
|
||||
on: [push]
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -70,21 +70,21 @@ jobs:
|
||||
- run: bundle exec rake
|
||||
```
|
||||
|
||||
### Matrix
|
||||
### Matrix of Ruby Versions
|
||||
|
||||
This matrix tests all stable releases and `head` versions of MRI, JRuby and TruffleRuby on Ubuntu and macOS.
|
||||
|
||||
```yaml
|
||||
name: My workflow
|
||||
on: [push]
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu, macos]
|
||||
ruby: [2.5, 2.6, 2.7, head, debug, jruby, jruby-head, truffleruby, truffleruby-head]
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
@@ -94,6 +94,29 @@ jobs:
|
||||
- run: bundle exec rake
|
||||
```
|
||||
|
||||
### Matrix of Gemfiles
|
||||
|
||||
```yaml
|
||||
name: My workflow
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
gemfile: [ rails5, rails6 ]
|
||||
runs-on: ubuntu-latest
|
||||
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
||||
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
||||
- run: bundle exec rake
|
||||
```
|
||||
|
||||
See the GitHub Actions documentation for more details about the
|
||||
[workflow syntax](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions)
|
||||
and the [condition and expression syntax](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions).
|
||||
@@ -116,10 +139,10 @@ if they are not at the root of the repository, see [action.yml](action.yml) for
|
||||
### Bundler
|
||||
|
||||
By default, if there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` or `gems.locked`) with a `BUNDLED WITH` section,
|
||||
the latest version of Bundler with the same major version will be installed.
|
||||
that version of Bundler will be installed and used.
|
||||
Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
|
||||
|
||||
This behavior can be customized, see [action.yml](action.yml) for details about the `bundler` input.
|
||||
This behavior can be customized, see [action.yml](action.yml) for more details about the `bundler` input.
|
||||
|
||||
### Caching `bundle install` automatically
|
||||
|
||||
@@ -136,26 +159,31 @@ This caching speeds up installing gems significantly and avoids too many request
|
||||
It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory).
|
||||
If there is a `Gemfile.lock` (or `$BUNDLE_GEMFILE.lock` or `gems.locked`), `bundle config --local deployment true` is used.
|
||||
|
||||
To use a `Gemfile` which is not at the root or has a different name, set `BUNDLE_GEMFILE` in the `env` at the job level, so it is set for all steps:
|
||||
```yaml
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BUNDLE_GEMFILE: subdir/mygemfile
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
bundler-cache: true
|
||||
- run: bundle exec rake
|
||||
```
|
||||
Of course you can also use a matrix of gemfiles if you need to test multiple gemfiles.
|
||||
To use a `Gemfile` which is not at the root or has a different name, set `BUNDLE_GEMFILE` in the `env` at the job level
|
||||
as shown in the [example](#matrix-of-gemfiles).
|
||||
|
||||
To perform caching, this action will use `bundle config --local path vendor/bundle`.
|
||||
#### bundle config
|
||||
|
||||
When using `bundler-cache: true` you might notice there is no good place to run `bundle config ...` commands.
|
||||
These can be replaced by `BUNDLE_*` environment variables, which are also faster.
|
||||
They should be set the `env` at the job level as shown in the [example](#matrix-of-gemfiles).
|
||||
See the [Bundler docs](https://bundler.io/man/bundle-config.1.html) or look at `.bundle/config` locally for the environment variable names,
|
||||
|
||||
To perform caching, this action will use `bundle config --local path $PWD/vendor/bundle`.
|
||||
Therefore, the Bundler `path` should not be changed in your workflow for the cache to work (no `bundle config path`).
|
||||
|
||||
#### How it Works
|
||||
|
||||
When there is no lockfile, one is generated with `bundle lock`, which is the same as `bundle install` would do first before actually fetching any gem.
|
||||
In other words, it works exactly like `bundle install`.
|
||||
The hash of the generated lockfile is then used for caching, which is the only correct approach.
|
||||
|
||||
#### Caching `bundle install` manually
|
||||
|
||||
It is also possible to cache gems manually, but this is not recommended because it is verbose and *very difficult* to do correctly.
|
||||
There are many concerns which means using `actions/cache` is never enough for caching gems (e.g., incomplete cache key, cleaning old gems when restoring from another key, correctly hashing the lockfile if not checked in, OS versions, ABI compatibility for `ruby-head`, etc).
|
||||
So, please use `bundler-cache: true` instead and report any issue.
|
||||
|
||||
## Windows
|
||||
|
||||
Note that running CI on Windows can be quite challenging if you are not very familiar with Windows.
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ inputs:
|
||||
default: 'default'
|
||||
bundler:
|
||||
description: |
|
||||
The version of Bundler to install. Either 'none', 1, 2, 'latest' or 'Gemfile.lock'.
|
||||
The version of Bundler to install. Either 'none', 'latest', 'Gemfile.lock', or a version number (e.g., 1, 2, 2.1.4).
|
||||
For 'Gemfile.lock', the version is determined based on the BUNDLED WITH section from the file Gemfile.lock, $BUNDLE_GEMFILE.lock or gems.locked.
|
||||
Defaults to 'Gemfile.lock' if the file exists and 'latest' otherwise.
|
||||
required: false
|
||||
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const core = require('@actions/core')
|
||||
const exec = require('@actions/exec')
|
||||
const cache = require('@actions/cache')
|
||||
const common = require('./common')
|
||||
|
||||
// The returned gemfile is guaranteed to exist, the lockfile might not exist
|
||||
export function detectGemfiles() {
|
||||
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
|
||||
if (fs.existsSync(gemfilePath)) {
|
||||
return [gemfilePath, `${gemfilePath}.lock`]
|
||||
} else if (process.env['BUNDLE_GEMFILE']) {
|
||||
throw new Error(`$BUNDLE_GEMFILE is set to ${gemfilePath} but does not exist`)
|
||||
}
|
||||
|
||||
if (fs.existsSync("gems.rb")) {
|
||||
return ["gems.rb", "gems.locked"]
|
||||
}
|
||||
|
||||
return [null, null]
|
||||
}
|
||||
|
||||
function readBundledWithFromGemfileLock(lockFile) {
|
||||
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()))
|
||||
if (bundledWithLine !== -1) {
|
||||
const nextLine = lines[bundledWithLine+1]
|
||||
if (nextLine && /^\d+/.test(nextLine.trim())) {
|
||||
const bundlerVersion = nextLine.trim()
|
||||
console.log(`Using Bundler ${bundlerVersion} from ${lockFile} BUNDLED WITH ${bundlerVersion}`)
|
||||
return bundlerVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async function afterLockFile(lockFile, platform, engine) {
|
||||
if (engine === 'truffleruby' && platform.startsWith('ubuntu-')) {
|
||||
const contents = fs.readFileSync(lockFile, 'utf8')
|
||||
if (contents.includes('nokogiri')) {
|
||||
await common.measure('Installing libxml2-dev libxslt-dev, required to install nokogiri on TruffleRuby', async () =>
|
||||
exec.exec('sudo', ['apt-get', '-yqq', 'install', 'libxml2-dev', 'libxslt-dev'], { silent: true }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
|
||||
let bundlerVersion = bundlerVersionInput
|
||||
|
||||
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
|
||||
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
|
||||
|
||||
if (!bundlerVersion) {
|
||||
bundlerVersion = 'latest'
|
||||
}
|
||||
}
|
||||
|
||||
if (bundlerVersion === 'latest') {
|
||||
bundlerVersion = '2'
|
||||
}
|
||||
|
||||
if (/^\d+/.test(bundlerVersion)) {
|
||||
// OK
|
||||
} else {
|
||||
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
|
||||
}
|
||||
|
||||
if (engine === 'ruby' && rubyVersion.match(/^2\.[012]/)) {
|
||||
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2')
|
||||
bundlerVersion = '1'
|
||||
} else if (engine === 'ruby' && rubyVersion.match(/^2\.3\.[01]/)) {
|
||||
console.log('Ruby 2.3.0 and 2.3.1 have shipped with an old rubygems that only works with Bundler 1')
|
||||
bundlerVersion = '1'
|
||||
} else if (engine === 'jruby' && rubyVersion.startsWith('9.1')) { // JRuby 9.1 targets Ruby 2.3, treat it the same
|
||||
console.log('JRuby 9.1 has a bug with Bundler 2 (https://github.com/ruby/setup-ruby/issues/108), using Bundler 1 instead on JRuby 9.1')
|
||||
bundlerVersion = '1'
|
||||
}
|
||||
|
||||
if (common.isHeadVersion(rubyVersion) && common.isBundler2Default(engine, rubyVersion) && bundlerVersion.startsWith('2')) {
|
||||
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
|
||||
} else if (engine === 'truffleruby' && !common.isHeadVersion(rubyVersion) && bundlerVersion.startsWith('1')) {
|
||||
console.log(`Using Bundler 1 shipped with ${engine}`)
|
||||
} else {
|
||||
const gem = path.join(rubyPrefix, 'bin', 'gem')
|
||||
const bundlerVersionConstraint = bundlerVersion.match(/^\d+\.\d+\.\d+/) ? bundlerVersion : `~> ${bundlerVersion}`
|
||||
await exec.exec(gem, ['install', 'bundler', '-v', bundlerVersionConstraint, '--no-document'])
|
||||
}
|
||||
|
||||
return bundlerVersion
|
||||
}
|
||||
|
||||
export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion) {
|
||||
if (gemfile === null) {
|
||||
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
||||
return false
|
||||
}
|
||||
|
||||
let envOptions = {}
|
||||
if (bundlerVersion.startsWith('1') && common.isBundler2Default(engine, rubyVersion)) {
|
||||
// If Bundler 1 is specified on Rubies which ship with Bundler 2,
|
||||
// we need to specify which Bundler version to use explicitly until the lockfile exists.
|
||||
console.log(`Setting BUNDLER_VERSION=${bundlerVersion} for "bundle config|lock" commands below to ensure Bundler 1 is used`)
|
||||
envOptions = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
|
||||
}
|
||||
|
||||
// config
|
||||
const cachePath = 'vendor/bundle'
|
||||
// An absolute path, so it is reliably under $PWD/vendor/bundle, and not relative to the gemfile's directory
|
||||
const bundleCachePath = path.join(process.cwd(), cachePath)
|
||||
|
||||
await exec.exec('bundle', ['config', '--local', 'path', bundleCachePath], envOptions)
|
||||
|
||||
if (fs.existsSync(lockFile)) {
|
||||
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], envOptions)
|
||||
} 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'], envOptions)
|
||||
}
|
||||
|
||||
await afterLockFile(lockFile, platform, engine)
|
||||
|
||||
// cache key
|
||||
const paths = [cachePath]
|
||||
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile)
|
||||
const key = `${baseKey}-${await common.hashFile(lockFile)}`
|
||||
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
|
||||
const restoreKeys = [`${baseKey}-`]
|
||||
console.log(`Cache key: ${key}`)
|
||||
|
||||
// restore cache & install
|
||||
let cachedKey = null
|
||||
try {
|
||||
cachedKey = await cache.restoreCache(paths, key, restoreKeys)
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
throw error;
|
||||
} else {
|
||||
core.info(`[warning] There was an error restoring the cache ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (cachedKey) {
|
||||
console.log(`Found cache for key: ${cachedKey}`)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems
|
||||
await exec.exec('bundle', ['clean'])
|
||||
}
|
||||
|
||||
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
|
||||
console.log('Saving cache')
|
||||
try {
|
||||
await cache.saveCache(paths, key)
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
throw error;
|
||||
} else if (error.name === cache.ReserveCacheError.name) {
|
||||
core.info(error.message);
|
||||
} else {
|
||||
core.info(`[warning]${error.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async function computeBaseKey(platform, engine, version, lockFile) {
|
||||
let key = `setup-ruby-bundler-cache-v3-${platform}-${engine}-${version}`
|
||||
|
||||
if (engine !== 'jruby' && common.isHeadVersion(version)) {
|
||||
let revision = '';
|
||||
await exec.exec('ruby', ['-e', 'print RUBY_REVISION'], {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
revision += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
key += `-revision-${revision}`
|
||||
}
|
||||
|
||||
key += `-${lockFile}`
|
||||
return key
|
||||
}
|
||||
@@ -19,8 +19,10 @@ export function partition(string, separator) {
|
||||
return [string.slice(0, i), string.slice(i + separator.length, string.length)]
|
||||
}
|
||||
|
||||
let inGroup = false
|
||||
|
||||
export async function measure(name, block) {
|
||||
return await core.group(name, async () => {
|
||||
const body = async () => {
|
||||
const start = performance.now()
|
||||
try {
|
||||
return await block()
|
||||
@@ -29,7 +31,20 @@ export async function measure(name, block) {
|
||||
const duration = (end - start) / 1000.0
|
||||
console.log(`Took ${duration.toFixed(2).padStart(6)} seconds`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (inGroup) {
|
||||
// Nested groups are not yet supported on GitHub Actions
|
||||
console.log(`> ${name}`)
|
||||
return await body()
|
||||
} else {
|
||||
inGroup = true
|
||||
try {
|
||||
return await core.group(name, body)
|
||||
} finally {
|
||||
inGroup = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isHeadVersion(rubyVersion) {
|
||||
@@ -40,6 +55,25 @@ export function isStableVersion(rubyVersion) {
|
||||
return /^\d+(\.\d+)*$/.test(rubyVersion)
|
||||
}
|
||||
|
||||
export function isBundler2Default(engine, rubyVersion) {
|
||||
if (engine === 'ruby') {
|
||||
return isHeadVersion(rubyVersion) || floatVersion(rubyVersion) >= 2.7
|
||||
} else if (engine === 'truffleruby') {
|
||||
return isHeadVersion(rubyVersion)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function floatVersion(rubyVersion) {
|
||||
const match = rubyVersion.match(/^\d+\.\d+/)
|
||||
if (match) {
|
||||
return parseFloat(match[0])
|
||||
} else {
|
||||
return 0.0
|
||||
}
|
||||
}
|
||||
|
||||
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')
|
||||
|
||||
+1315
-600
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem "bundler", "~> 1.0"
|
||||
@@ -0,0 +1,3 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "nokogiri"
|
||||
@@ -0,0 +1,3 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 5.2.0"
|
||||
@@ -0,0 +1,3 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 6.0.0"
|
||||
@@ -30,4 +30,4 @@ versions['mingw'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/rub
|
||||
versions['mswin'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z'
|
||||
|
||||
js = "export const versions = #{JSON.pretty_generate(versions)}\n"
|
||||
File.write 'windows-versions.js', js
|
||||
File.binwrite 'windows-versions.js', js
|
||||
|
||||
@@ -2,9 +2,8 @@ const os = require('os')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const core = require('@actions/core')
|
||||
const exec = require('@actions/exec')
|
||||
const cache = require('@actions/cache')
|
||||
const common = require('./common')
|
||||
const bundler = require('./bundler')
|
||||
|
||||
const windows = common.windows
|
||||
|
||||
@@ -39,7 +38,7 @@ export async function setupRuby(options = {}) {
|
||||
const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version'])
|
||||
|
||||
let installer
|
||||
if (platform.startsWith('windows-') && engine === 'ruby') {
|
||||
if (platform.startsWith('windows-') && engine !== 'jruby') {
|
||||
installer = require('./windows')
|
||||
} else {
|
||||
installer = require('./ruby-builder')
|
||||
@@ -61,34 +60,20 @@ export async function setupRuby(options = {}) {
|
||||
}
|
||||
|
||||
if (inputs['bundler'] !== 'none') {
|
||||
const [gemfile, lockFile] = detectGemfiles()
|
||||
const [gemfile, lockFile] = bundler.detectGemfiles()
|
||||
|
||||
const bundlerVersion = await common.measure('Installing Bundler', async () =>
|
||||
installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version))
|
||||
bundler.installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version))
|
||||
|
||||
if (inputs['bundler-cache'] === 'true') {
|
||||
await common.measure('bundle install', async () =>
|
||||
bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion))
|
||||
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion))
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
return [gemfilePath, `${gemfilePath}.lock`]
|
||||
}
|
||||
|
||||
if (fs.existsSync("gems.rb")) {
|
||||
return ["gems.rb", "gems.locked"]
|
||||
}
|
||||
|
||||
return [null, null]
|
||||
}
|
||||
|
||||
function parseRubyEngineAndVersion(rubyVersion) {
|
||||
if (rubyVersion === 'default') {
|
||||
if (fs.existsSync('.ruby-version')) {
|
||||
@@ -172,159 +157,4 @@ function envPreInstall() {
|
||||
}
|
||||
}
|
||||
|
||||
function readBundledWithFromGemfileLock(lockFile) {
|
||||
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()))
|
||||
if (bundledWithLine !== -1) {
|
||||
const nextLine = lines[bundledWithLine+1]
|
||||
if (nextLine && /^\d+/.test(nextLine.trim())) {
|
||||
const bundlerVersion = nextLine.trim()
|
||||
const majorVersion = bundlerVersion.match(/^\d+/)[0]
|
||||
console.log(`Using Bundler ${majorVersion} from ${lockFile} BUNDLED WITH ${bundlerVersion}`)
|
||||
return majorVersion
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
|
||||
let bundlerVersion = bundlerVersionInput
|
||||
|
||||
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
|
||||
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
|
||||
|
||||
if (!bundlerVersion) {
|
||||
bundlerVersion = 'latest'
|
||||
}
|
||||
}
|
||||
|
||||
if (bundlerVersion === 'latest') {
|
||||
bundlerVersion = '2'
|
||||
}
|
||||
|
||||
if (/^\d+/.test(bundlerVersion)) {
|
||||
// OK
|
||||
} else {
|
||||
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
|
||||
}
|
||||
|
||||
if (engine === 'ruby' && rubyVersion.match(/^2\.[12]/)) {
|
||||
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby <= 2.2')
|
||||
bundlerVersion = '1'
|
||||
} else if (engine === 'ruby' && rubyVersion.startsWith('2.3')) {
|
||||
console.log('Ruby 2.3 has a bug with Bundler 2 (https://github.com/rubygems/rubygems/issues/3570), using Bundler 1 instead on Ruby 2.3')
|
||||
bundlerVersion = '1'
|
||||
} else if (engine === 'jruby' && rubyVersion.startsWith('9.1.')) { // JRuby 9.1 targets Ruby 2.3, treat it the same
|
||||
console.log('JRuby 9.1 has a bug with Bundler 2 (https://github.com/ruby/setup-ruby/issues/108), using Bundler 1 instead on JRuby 9.1')
|
||||
bundlerVersion = '1'
|
||||
}
|
||||
|
||||
if ((engine === 'ruby' || engine === 'truffleruby') && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') {
|
||||
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
|
||||
} else if (engine === 'truffleruby' && !common.isHeadVersion(rubyVersion) && bundlerVersion === '1') {
|
||||
console.log(`Using Bundler 1 shipped with ${engine}`)
|
||||
} else {
|
||||
const gem = path.join(rubyPrefix, 'bin', 'gem')
|
||||
await exec.exec(gem, ['install', 'bundler', '-v', `~> ${bundlerVersion}`, '--no-document'])
|
||||
}
|
||||
|
||||
return bundlerVersion
|
||||
}
|
||||
|
||||
async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion) {
|
||||
if (gemfile === null) {
|
||||
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
||||
return false
|
||||
}
|
||||
|
||||
// Before the lockfile exists, we need to specify which Bundler version to use explicitly
|
||||
const optionsWithBundlerVersion = { env: { ...process.env, BUNDLER_VERSION: bundlerVersion } }
|
||||
|
||||
// config
|
||||
const path = 'vendor/bundle'
|
||||
|
||||
await exec.exec('bundle', ['config', '--local', 'path', path], optionsWithBundlerVersion)
|
||||
|
||||
if (fs.existsSync(lockFile)) {
|
||||
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'], optionsWithBundlerVersion)
|
||||
} 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'], optionsWithBundlerVersion)
|
||||
}
|
||||
|
||||
// cache key
|
||||
const paths = [path]
|
||||
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile)
|
||||
const key = `${baseKey}-${await common.hashFile(lockFile)}`
|
||||
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
|
||||
const restoreKeys = [`${baseKey}-`]
|
||||
console.log(`Cache key: ${key}`)
|
||||
|
||||
// restore cache & install
|
||||
let cachedKey = null
|
||||
try {
|
||||
cachedKey = await cache.restoreCache(paths, key, restoreKeys)
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
throw error;
|
||||
} else {
|
||||
core.info(`[warning] There was an error restoring the cache ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (cachedKey) {
|
||||
console.log(`Found cache for key: ${cachedKey}`)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems
|
||||
await exec.exec('bundle', ['clean'])
|
||||
}
|
||||
|
||||
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
|
||||
console.log('Saving cache')
|
||||
try {
|
||||
await cache.saveCache(paths, key)
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
throw error;
|
||||
} else if (error.name === cache.ReserveCacheError.name) {
|
||||
core.info(error.message);
|
||||
} else {
|
||||
core.info(`[warning]${error.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
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'], {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
revision += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
key += `-revision-${revision}`
|
||||
}
|
||||
|
||||
key += `-${lockFile}`
|
||||
return key
|
||||
}
|
||||
|
||||
if (__filename.endsWith('index.js')) { run() }
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/ruby/setup-ruby",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^1.0.2",
|
||||
"@actions/cache": "^1.0.5",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.3",
|
||||
"@actions/io": "^1.0.2",
|
||||
|
||||
@@ -8,17 +8,18 @@ export function getVersions(platform) {
|
||||
"2.5.0", "2.5.1", "2.5.2", "2.5.3", "2.5.4", "2.5.5", "2.5.6", "2.5.7", "2.5.8",
|
||||
"2.6.0", "2.6.1", "2.6.2", "2.6.3", "2.6.4", "2.6.5", "2.6.6",
|
||||
"2.7.0", "2.7.1", "2.7.2",
|
||||
"3.0.0-preview1", "3.0.0-preview2",
|
||||
"3.0.0-preview1", "3.0.0-preview2", "3.0.0-rc1", "3.0.0",
|
||||
"head", "debug",
|
||||
],
|
||||
"jruby": [
|
||||
"9.1.17.0",
|
||||
"9.2.9.0", "9.2.10.0", "9.2.11.0", "9.2.11.1", "9.2.12.0", "9.2.13.0",
|
||||
"9.2.9.0", "9.2.10.0", "9.2.11.0", "9.2.11.1", "9.2.12.0", "9.2.13.0", "9.2.14.0",
|
||||
"head"
|
||||
],
|
||||
"truffleruby": [
|
||||
"19.3.0", "19.3.1",
|
||||
"20.0.0", "20.1.0", "20.2.0", "20.3.0",
|
||||
"21.0.0",
|
||||
"head"
|
||||
]
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,17 +19,18 @@ export const versions = {
|
||||
"2.5.5": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.5.5-1/rubyinstaller-2.5.5-1-x64.7z",
|
||||
"2.5.6": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.5.6-1/rubyinstaller-2.5.6-1-x64.7z",
|
||||
"2.5.7": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.5.7-1/rubyinstaller-2.5.7-1-x64.7z",
|
||||
"2.5.8": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.5.8-1/rubyinstaller-2.5.8-1-x64.7z",
|
||||
"2.5.8": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.5.8-2/rubyinstaller-2.5.8-2-x64.7z",
|
||||
"2.6.0": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.0-1/rubyinstaller-2.6.0-1-x64.7z",
|
||||
"2.6.1": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.1-1/rubyinstaller-2.6.1-1-x64.7z",
|
||||
"2.6.2": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.2-1/rubyinstaller-2.6.2-1-x64.7z",
|
||||
"2.6.3": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.3-1/rubyinstaller-2.6.3-1-x64.7z",
|
||||
"2.6.4": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.4-1/rubyinstaller-2.6.4-1-x64.7z",
|
||||
"2.6.5": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.5-1/rubyinstaller-2.6.5-1-x64.7z",
|
||||
"2.6.6": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.6-1/rubyinstaller-2.6.6-1-x64.7z",
|
||||
"2.6.6": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.6.6-2/rubyinstaller-2.6.6-2-x64.7z",
|
||||
"2.7.0": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.7.0-1/rubyinstaller-2.7.0-1-x64.7z",
|
||||
"2.7.1": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.7.1-1/rubyinstaller-2.7.1-1-x64.7z",
|
||||
"2.7.2": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-2.7.2-1/rubyinstaller-2.7.2-1-x64.7z",
|
||||
"3.0.0": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.0.0-1/rubyinstaller-3.0.0-1-x64.7z",
|
||||
"head": "https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x64.7z",
|
||||
"mingw": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z",
|
||||
"mswin": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z"
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@actions/cache@^1.0.2":
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@actions/cache/-/cache-1.0.2.tgz#a223dcc752c7f988016d28ee7232f930f85cec61"
|
||||
integrity sha512-CzAseaJ4cKmOI58EIWUb/LfeYdM7Y25s39OEMtWAhEPrPPzrbSEjGHCLaYjJ0V8C4iojo8vBYh5B3OIJ37EiJw==
|
||||
"@actions/cache@^1.0.5":
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@actions/cache/-/cache-1.0.5.tgz#ba98725d38611b5426fc57a2f00bd8b0d9202f36"
|
||||
integrity sha512-TcvJOduwsPP27KLmIa5cqXsQYFK2GzILcEpnhvYmhGwi1aYx9XwhKmp6Im8X6DJMBxbvupKPsOntG6f6sSkIPA==
|
||||
dependencies:
|
||||
"@actions/core" "^1.2.4"
|
||||
"@actions/core" "^1.2.6"
|
||||
"@actions/exec" "^1.0.1"
|
||||
"@actions/glob" "^0.1.0"
|
||||
"@actions/http-client" "^1.0.8"
|
||||
"@actions/http-client" "^1.0.9"
|
||||
"@actions/io" "^1.0.1"
|
||||
"@azure/ms-rest-js" "^2.0.7"
|
||||
"@azure/storage-blob" "^12.1.2"
|
||||
semver "^6.1.0"
|
||||
uuid "^3.3.3"
|
||||
|
||||
"@actions/core@^1.2.0", "@actions/core@^1.2.3", "@actions/core@^1.2.4", "@actions/core@^1.2.6":
|
||||
"@actions/core@^1.2.0", "@actions/core@^1.2.3", "@actions/core@^1.2.6":
|
||||
version "1.2.6"
|
||||
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.6.tgz#a78d49f41a4def18e88ce47c2cac615d5694bf09"
|
||||
integrity sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==
|
||||
@@ -44,6 +44,13 @@
|
||||
dependencies:
|
||||
tunnel "0.0.6"
|
||||
|
||||
"@actions/http-client@^1.0.9":
|
||||
version "1.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@actions/http-client/-/http-client-1.0.9.tgz#af1947d020043dbc6a3b4c5918892095c30ffb52"
|
||||
integrity sha512-0O4SsJ7q+MK0ycvXPl2e6bMXV7dxAXOGjrXS1eTF9s2S401Tp6c/P3c3Joz04QefC1J6Gt942Wl2jbm3f4mLcg==
|
||||
dependencies:
|
||||
tunnel "0.0.6"
|
||||
|
||||
"@actions/io@^1.0.1", "@actions/io@^1.0.2":
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.2.tgz#2f614b6e69ce14d191180451eb38e6576a6e6b27"
|
||||
|
||||
Reference in New Issue
Block a user