Compare commits

...
9 Commits
Author SHA1 Message Date
Benoit Daloze 81be0938f7 Add an exported setupRuby() function which can be called from other actions
* Inputs are passed as simple object properties.
* It is recommended to expose the same inputs for other actions.
* See #58 and #33.
2020-06-06 13:52:42 +02:00
Benoit Daloze b04e5b8846 Use Bundler 1 on Ruby 2.3
* At least until there is a new Bundler 2 release fixing this.
* Fixes https://github.com/ruby/setup-ruby/issues/51
2020-06-06 13:16:46 +02:00
Benoit Daloze a7df86edc6 A separate bundle config path vendor/bundle is needed for older Bundler
* See https://github.com/ruby/setup-ruby/pull/53#issuecomment-624827273
2020-05-16 18:55:34 +02:00
Scott Jacobsen 8137829321 Use the new deployment true config setting 2020-05-16 18:52:00 +02:00
Scott Jacobsen a1d280134e Use the --deployment flag for bundle install
`bundle install --deployment` should be used on CI environments - it sets additional options beyond the install path (ensures the Gemfile.lock is checked in, up to date, etc). https://bundler.io/v2.0/man/bundle-install.1.html#DEPLOYMENT-MODE
2020-05-16 18:52:00 +02:00
Benoit Daloze d01e942f09 Link to condition and expression syntax docs too 2020-05-15 13:48:07 +02:00
Benoit Daloze e74945bcae Update README example workflows
* Show how to continue-on-error for head builds.
* Use the typical `bundle install` + `bundle exec rake` commands.
2020-05-15 13:29:19 +02:00
Benoit Daloze 8bff4379b9 Ruby 2.4 is EOL 2020-05-15 13:22:42 +02:00
Benoit Daloze 23b9735206 Fix checks for head versions
* Always use common.isHeadVersion().
2020-05-15 13:01:01 +02:00
4 changed files with 82 additions and 39 deletions
+2 -2
View File
@@ -15,13 +15,13 @@ jobs:
matrix: matrix:
os: [ ubuntu, macos, windows ] os: [ ubuntu, macos, windows ]
# Use various version syntax here for testing # Use various version syntax here for testing
ruby: [ 2.2, 2.3, 2.4, 2.5, 2.6.6, 2.7, ruby-head, ruby-debug, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ] ruby: [ 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 ]
include: include:
- { os: ubuntu, ruby: rubinius } - { os: ubuntu, ruby: rubinius }
- { os: windows, ruby: mingw } - { os: windows, ruby: mingw }
- { os: windows, ruby: mswin } - { os: windows, ruby: mswin }
exclude: exclude:
- { os: windows, ruby: ruby-debug } - { os: windows, ruby: debug }
- { os: windows, ruby: truffleruby } - { os: windows, ruby: truffleruby }
- { os: windows, ruby: truffleruby-head } - { os: windows, ruby: truffleruby-head }
+17 -9
View File
@@ -64,13 +64,14 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1
with: with:
ruby-version: 2.6 ruby-version: 2.6 # Not needed with a .ruby-version file
- run: ruby -v - run: bundle install
- run: bundle exec rake
``` ```
### Matrix ### Matrix
This matrix tests all stable releases of MRI, JRuby and TruffleRuby on Ubuntu and macOS. This matrix tests all stable releases and `head` versions of MRI, JRuby and TruffleRuby on Ubuntu and macOS.
```yaml ```yaml
name: My workflow name: My workflow
@@ -80,17 +81,23 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ ubuntu-latest, macos-latest ] os: [ubuntu, macos]
ruby: [ 2.4, 2.5, 2.6, 2.7, jruby, truffleruby ] ruby: [2.5, 2.6, 2.7, head, debug, jruby, jruby-head, truffleruby, truffleruby-head]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}-latest
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@v1
with: with:
ruby-version: ${{ matrix.ruby }} ruby-version: ${{ matrix.ruby }}
- run: ruby -v - run: bundle install
- 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).
### Supported Version Syntax ### Supported Version Syntax
* engine-version like `ruby-2.6.5` and `truffleruby-19.3.0` * engine-version like `ruby-2.6.5` and `truffleruby-19.3.0`
@@ -105,7 +112,7 @@ jobs:
By default, if there is a `Gemfile.lock` file with a `BUNDLED WITH` section, By default, if there is a `Gemfile.lock` file with a `BUNDLED WITH` section,
the latest version of Bundler with the same major version will be installed. the latest version of Bundler with the same major version will be installed.
Otherwise, the latest Bundler version is installed (except for Ruby 2.2 where only Bundler 1 is supported). Otherwise, the latest Bundler version is installed (except for Ruby 2.2 and 2.3 where only Bundler 1 is supported).
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 details about the `bundler` input.
@@ -122,8 +129,9 @@ You can cache the installed gems with these two steps:
bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}- bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-
- name: bundle install - name: bundle install
run: | run: |
bundle config deployment true
bundle config path vendor/bundle bundle config path vendor/bundle
bundle install --jobs 4 --retry 3 bundle install --jobs 4
``` ```
When using a single OS, replace `${{ matrix.os }}` with the OS. When using a single OS, replace `${{ matrix.os }}` with the OS.
Generated Vendored
+32 -14
View File
@@ -969,6 +969,7 @@ module.exports = require("os");
"use strict"; "use strict";
__webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "run", function() { return run; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "run", function() { return run; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setupRuby", function() { return setupRuby; });
const os = __webpack_require__(87) const os = __webpack_require__(87)
const fs = __webpack_require__(747) const fs = __webpack_require__(747)
const path = __webpack_require__(622) const path = __webpack_require__(622)
@@ -976,19 +977,31 @@ const core = __webpack_require__(470)
const exec = __webpack_require__(986) const exec = __webpack_require__(986)
const common = __webpack_require__(239) const common = __webpack_require__(239)
const inputDefaults = {
'ruby-version': 'default',
'bundler': 'default',
'working-directory': '.',
}
async function run() { async function run() {
try { try {
await main() const options = {}
for (const key in inputDefaults) {
options[key] = core.getInput(key)
}
await setupRuby(options)
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
} }
} }
async function main() { async function setupRuby(options) {
process.chdir(core.getInput('working-directory')) const inputs = { ...inputDefaults, ...options }
process.chdir(inputs['working-directory'])
const platform = common.getVirtualEnvironmentName() const platform = common.getVirtualEnvironmentName()
const [engine, parsedVersion] = parseRubyEngineAndVersion(core.getInput('ruby-version')) const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version'])
let installer let installer
if (platform === 'windows-latest' && engine !== 'jruby') { if (platform === 'windows-latest' && engine !== 'jruby') {
@@ -1006,9 +1019,9 @@ async function main() {
setupPath(newPathEntries) setupPath(newPathEntries)
if (core.getInput('bundler') !== 'none') { if (inputs['bundler'] !== 'none') {
await common.measure('Installing Bundler', async () => await common.measure('Installing Bundler', async () =>
installBundler(platform, rubyPrefix, engine, version)) installBundler(inputs['bundler'], platform, rubyPrefix, engine, version))
} }
core.setOutput('ruby-prefix', rubyPrefix) core.setOutput('ruby-prefix', rubyPrefix)
@@ -1036,7 +1049,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
} }
let engine, version let engine, version
if (rubyVersion.match(/^(\d+|head|mingw|mswin)/)) { // X.Y.Z => ruby-X.Y.Z if (rubyVersion.match(/^(\d+)/) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z
engine = 'ruby' engine = 'ruby'
version = rubyVersion version = rubyVersion
} else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion
@@ -1057,7 +1070,7 @@ function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVe
let version = parsedVersion let version = parsedVersion
if (!engineVersions.includes(parsedVersion)) { if (!engineVersions.includes(parsedVersion)) {
const latestToFirstVersion = engineVersions.slice().reverse() const latestToFirstVersion = engineVersions.slice().reverse()
const found = latestToFirstVersion.find(v => v !== 'head' && v.startsWith(parsedVersion)) const found = latestToFirstVersion.find(v => !common.isHeadVersion(v) && v.startsWith(parsedVersion))
if (found) { if (found) {
version = found version = found
} else { } else {
@@ -1113,8 +1126,8 @@ function readBundledWithFromGemfileLock() {
return null return null
} }
async function installBundler(platform, rubyPrefix, engine, rubyVersion) { async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler') var bundlerVersion = bundlerVersionInput
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock() bundlerVersion = readBundledWithFromGemfileLock()
@@ -1127,15 +1140,20 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
bundlerVersion = '2' bundlerVersion = '2'
} }
if (rubyVersion.startsWith('2.2')) { if (/^\d+/.test(bundlerVersion)) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
bundlerVersion = '1'
} else if (/^\d+/.test(bundlerVersion)) {
// OK // OK
} else { } else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`) throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
} }
if (rubyVersion.startsWith('2.2')) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
bundlerVersion = '1'
} else if (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'
}
if (engine === 'ruby' && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') { if (engine === 'ruby' && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`) console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
} else if (engine === 'truffleruby' && bundlerVersion === '1') { } else if (engine === 'truffleruby' && bundlerVersion === '1') {
+31 -14
View File
@@ -5,19 +5,31 @@ const core = require('@actions/core')
const exec = require('@actions/exec') const exec = require('@actions/exec')
const common = require('./common') const common = require('./common')
const inputDefaults = {
'ruby-version': 'default',
'bundler': 'default',
'working-directory': '.',
}
export async function run() { export async function run() {
try { try {
await main() const options = {}
for (const key in inputDefaults) {
options[key] = core.getInput(key)
}
await setupRuby(options)
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
} }
} }
async function main() { export async function setupRuby(options) {
process.chdir(core.getInput('working-directory')) const inputs = { ...inputDefaults, ...options }
process.chdir(inputs['working-directory'])
const platform = common.getVirtualEnvironmentName() const platform = common.getVirtualEnvironmentName()
const [engine, parsedVersion] = parseRubyEngineAndVersion(core.getInput('ruby-version')) const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version'])
let installer let installer
if (platform === 'windows-latest' && engine !== 'jruby') { if (platform === 'windows-latest' && engine !== 'jruby') {
@@ -35,9 +47,9 @@ async function main() {
setupPath(newPathEntries) setupPath(newPathEntries)
if (core.getInput('bundler') !== 'none') { if (inputs['bundler'] !== 'none') {
await common.measure('Installing Bundler', async () => await common.measure('Installing Bundler', async () =>
installBundler(platform, rubyPrefix, engine, version)) installBundler(inputs['bundler'], platform, rubyPrefix, engine, version))
} }
core.setOutput('ruby-prefix', rubyPrefix) core.setOutput('ruby-prefix', rubyPrefix)
@@ -65,7 +77,7 @@ function parseRubyEngineAndVersion(rubyVersion) {
} }
let engine, version let engine, version
if (rubyVersion.match(/^(\d+|head|mingw|mswin)/)) { // X.Y.Z => ruby-X.Y.Z if (rubyVersion.match(/^(\d+)/) || common.isHeadVersion(rubyVersion)) { // X.Y.Z => ruby-X.Y.Z
engine = 'ruby' engine = 'ruby'
version = rubyVersion version = rubyVersion
} else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion
@@ -86,7 +98,7 @@ function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVe
let version = parsedVersion let version = parsedVersion
if (!engineVersions.includes(parsedVersion)) { if (!engineVersions.includes(parsedVersion)) {
const latestToFirstVersion = engineVersions.slice().reverse() const latestToFirstVersion = engineVersions.slice().reverse()
const found = latestToFirstVersion.find(v => v !== 'head' && v.startsWith(parsedVersion)) const found = latestToFirstVersion.find(v => !common.isHeadVersion(v) && v.startsWith(parsedVersion))
if (found) { if (found) {
version = found version = found
} else { } else {
@@ -142,8 +154,8 @@ function readBundledWithFromGemfileLock() {
return null return null
} }
async function installBundler(platform, rubyPrefix, engine, rubyVersion) { async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler') var bundlerVersion = bundlerVersionInput
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock() bundlerVersion = readBundledWithFromGemfileLock()
@@ -156,15 +168,20 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
bundlerVersion = '2' bundlerVersion = '2'
} }
if (rubyVersion.startsWith('2.2')) { if (/^\d+/.test(bundlerVersion)) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
bundlerVersion = '1'
} else if (/^\d+/.test(bundlerVersion)) {
// OK // OK
} else { } else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`) throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
} }
if (rubyVersion.startsWith('2.2')) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
bundlerVersion = '1'
} else if (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'
}
if (engine === 'ruby' && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') { if (engine === 'ruby' && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`) console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
} else if (engine === 'truffleruby' && bundlerVersion === '1') { } else if (engine === 'truffleruby' && bundlerVersion === '1') {