mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 14:34:21 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0effb2cc50 | ||
|
|
b62e5d53aa | ||
|
|
1c172ef5dc | ||
|
|
4cbbce6b48 |
@@ -115,7 +115,7 @@ if they are not at the root of the repository, see [action.yml](action.yml) for
|
|||||||
|
|
||||||
### Bundler
|
### Bundler
|
||||||
|
|
||||||
By default, if there is a `Gemfile.lock` file (or `$BUNDLE_GEMFILE.lock` if `$BUNDLE_GEMFILE` is set) with a `BUNDLED WITH` section,
|
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.
|
the latest version of Bundler with the same major version will be installed.
|
||||||
Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
|
Otherwise, the latest compatible Bundler version is installed (Bundler 2 on Ruby >= 2.4, Bundler 1 on Ruby < 2.4).
|
||||||
|
|
||||||
@@ -131,9 +131,8 @@ This action provides a way to automatically run `bundle install` and cache the r
|
|||||||
```
|
```
|
||||||
|
|
||||||
This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org.
|
This caching speeds up installing gems significantly and avoids too many requests to RubyGems.org.
|
||||||
It needs a `Gemfile` (or `$BUNDLE_GEMFILE`) under the [`working-directory`](#working-directory).
|
It needs a `Gemfile` (or `$BUNDLE_GEMFILE` or `gems.rb`) under the [`working-directory`](#working-directory).
|
||||||
The caching works whether there is a `Gemfile.lock` or not.
|
If there is a `Gemfile.lock` (or `$BUNDLE_GEMFILE.lock` or `gems.locked`), `bundle config --local deployment true` is used.
|
||||||
If there is a `Gemfile.lock`, `bundle config --local deployment true` is used.
|
|
||||||
|
|
||||||
To perform caching, this action will use `bundle config --local path vendor/bundle`.
|
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.
|
Therefore, the Bundler `path` should not be changed in your workflow for the cache to work.
|
||||||
|
|||||||
+2
-2
@@ -12,8 +12,8 @@ inputs:
|
|||||||
bundler:
|
bundler:
|
||||||
description: |
|
description: |
|
||||||
The version of Bundler to install. Either 'none', 1, 2, 'latest' or 'Gemfile.lock'.
|
The version of Bundler to install. Either 'none', 1, 2, 'latest' or 'Gemfile.lock'.
|
||||||
For 'Gemfile.lock', the version is determined based on the BUNDLED WITH section from the file ($BUNDLE_GEMFILE || Gemfile).lock.
|
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 it exists and 'latest' otherwise.
|
Defaults to 'Gemfile.lock' if the file exists and 'latest' otherwise.
|
||||||
required: false
|
required: false
|
||||||
default: 'default'
|
default: 'default'
|
||||||
bundler-cache:
|
bundler-cache:
|
||||||
|
|||||||
+55
-20
@@ -33971,6 +33971,12 @@ function convertBody(buffer, headers) {
|
|||||||
// html4
|
// html4
|
||||||
if (!res && str) {
|
if (!res && str) {
|
||||||
res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);
|
res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);
|
||||||
|
if (!res) {
|
||||||
|
res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str);
|
||||||
|
if (res) {
|
||||||
|
res.pop(); // drop last quote
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
res = /charset=(.*)/i.exec(res.pop());
|
res = /charset=(.*)/i.exec(res.pop());
|
||||||
@@ -34978,7 +34984,7 @@ function fetch(url, opts) {
|
|||||||
// HTTP fetch step 5.5
|
// HTTP fetch step 5.5
|
||||||
switch (request.redirect) {
|
switch (request.redirect) {
|
||||||
case 'error':
|
case 'error':
|
||||||
reject(new FetchError(`redirect mode is set to error: ${request.url}`, 'no-redirect'));
|
reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));
|
||||||
finalize();
|
finalize();
|
||||||
return;
|
return;
|
||||||
case 'manual':
|
case 'manual':
|
||||||
@@ -35017,7 +35023,8 @@ function fetch(url, opts) {
|
|||||||
method: request.method,
|
method: request.method,
|
||||||
body: request.body,
|
body: request.body,
|
||||||
signal: request.signal,
|
signal: request.signal,
|
||||||
timeout: request.timeout
|
timeout: request.timeout,
|
||||||
|
size: request.size
|
||||||
};
|
};
|
||||||
|
|
||||||
// HTTP-redirect fetch step 9
|
// HTTP-redirect fetch step 9
|
||||||
@@ -51411,18 +51418,44 @@ async function setupRuby(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inputs['bundler'] !== 'none') {
|
if (inputs['bundler'] !== 'none') {
|
||||||
|
const [gemfile, lockFile] = detectGemfiles()
|
||||||
|
|
||||||
await common.measure('Installing Bundler', async () =>
|
await common.measure('Installing Bundler', async () =>
|
||||||
installBundler(inputs['bundler'], platform, rubyPrefix, engine, version))
|
installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version))
|
||||||
|
|
||||||
if (inputs['bundler-cache'] === 'true') {
|
if (inputs['bundler-cache'] === 'true') {
|
||||||
await common.measure('bundle install', async () =>
|
await common.measure('bundle install', async () =>
|
||||||
bundleInstall(platform, engine, version))
|
bundleInstall(gemfile, lockFile, platform, engine, version))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput('ruby-prefix', rubyPrefix)
|
core.setOutput('ruby-prefix', rubyPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gemsRbPath = "gems.rb"
|
||||||
|
if (fs.existsSync(gemsRbPath)) {
|
||||||
|
const lockPath = "gems.locked"
|
||||||
|
if (fs.existsSync(lockPath)) {
|
||||||
|
return [gemsRbPath, lockPath]
|
||||||
|
} else {
|
||||||
|
return [gemsRbPath, null]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [null, null]
|
||||||
|
}
|
||||||
|
|
||||||
function parseRubyEngineAndVersion(rubyVersion) {
|
function parseRubyEngineAndVersion(rubyVersion) {
|
||||||
if (rubyVersion === 'default') {
|
if (rubyVersion === 'default') {
|
||||||
if (fs.existsSync('.ruby-version')) {
|
if (fs.existsSync('.ruby-version')) {
|
||||||
@@ -51500,9 +51533,9 @@ function envPreInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBundledWithFromGemfileLock(path) {
|
function readBundledWithFromGemfileLock(lockFile) {
|
||||||
if (fs.existsSync(path)) {
|
if (lockFile !== null) {
|
||||||
const contents = fs.readFileSync(path, 'utf8')
|
const contents = fs.readFileSync(lockFile, 'utf8')
|
||||||
const lines = contents.split(/\r?\n/)
|
const lines = contents.split(/\r?\n/)
|
||||||
const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
|
const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
|
||||||
if (bundledWithLine !== -1) {
|
if (bundledWithLine !== -1) {
|
||||||
@@ -51510,7 +51543,7 @@ function readBundledWithFromGemfileLock(path) {
|
|||||||
if (nextLine && /^\d+/.test(nextLine.trim())) {
|
if (nextLine && /^\d+/.test(nextLine.trim())) {
|
||||||
const bundlerVersion = nextLine.trim()
|
const bundlerVersion = nextLine.trim()
|
||||||
const majorVersion = bundlerVersion.match(/^\d+/)[0]
|
const majorVersion = bundlerVersion.match(/^\d+/)[0]
|
||||||
console.log(`Using Bundler ${majorVersion} from ${path} BUNDLED WITH ${bundlerVersion}`)
|
console.log(`Using Bundler ${majorVersion} from ${lockFile} BUNDLED WITH ${bundlerVersion}`)
|
||||||
return majorVersion
|
return majorVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51518,12 +51551,12 @@ function readBundledWithFromGemfileLock(path) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
|
async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
|
||||||
var bundlerVersion = bundlerVersionInput
|
var bundlerVersion = bundlerVersionInput
|
||||||
|
|
||||||
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
|
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
|
||||||
const gemfilePath = `${process.env['BUNDLE_GEMFILE'] || 'Gemfile'}.lock`
|
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
|
||||||
bundlerVersion = readBundledWithFromGemfileLock(gemfilePath)
|
|
||||||
if (!bundlerVersion) {
|
if (!bundlerVersion) {
|
||||||
bundlerVersion = 'latest'
|
bundlerVersion = 'latest'
|
||||||
}
|
}
|
||||||
@@ -51559,16 +51592,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bundleInstall(platform, engine, version) {
|
async function bundleInstall(gemfile, lockFile, platform, engine, version) {
|
||||||
if (!fs.existsSync('Gemfile')) {
|
if (gemfile === null) {
|
||||||
console.log('No Gemfile, skipping "bundle install" and caching')
|
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// config
|
// config
|
||||||
const path = 'vendor/bundle'
|
const path = 'vendor/bundle'
|
||||||
const hasGemfileLock = fs.existsSync('Gemfile.lock');
|
|
||||||
if (hasGemfileLock) {
|
if (lockFile !== null) {
|
||||||
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
|
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
|
||||||
}
|
}
|
||||||
await exec.exec('bundle', ['config', '--local', 'path', path])
|
await exec.exec('bundle', ['config', '--local', 'path', path])
|
||||||
@@ -51578,10 +51611,10 @@ async function bundleInstall(platform, engine, version) {
|
|||||||
const baseKey = await computeBaseKey(platform, engine, version)
|
const baseKey = await computeBaseKey(platform, engine, version)
|
||||||
let key = baseKey
|
let key = baseKey
|
||||||
let restoreKeys
|
let restoreKeys
|
||||||
if (hasGemfileLock) {
|
if (lockFile !== null) {
|
||||||
key += `-Gemfile.lock-${await common.hashFile('Gemfile.lock')}`
|
key += `-${lockFile}-${await common.hashFile(lockFile)}`
|
||||||
// If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache)
|
// If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache)
|
||||||
restoreKeys = [`${baseKey}-Gemfile.lock-`]
|
restoreKeys = [`${baseKey}-${lockFile}-`]
|
||||||
} else {
|
} else {
|
||||||
// Only exact key, to never mix native gems of different platforms or Ruby versions
|
// Only exact key, to never mix native gems of different platforms or Ruby versions
|
||||||
restoreKeys = []
|
restoreKeys = []
|
||||||
@@ -51627,6 +51660,8 @@ async function bundleInstall(platform, engine, version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function computeBaseKey(platform, engine, version) {
|
async function computeBaseKey(platform, engine, version) {
|
||||||
|
|||||||
@@ -61,18 +61,44 @@ export async function setupRuby(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inputs['bundler'] !== 'none') {
|
if (inputs['bundler'] !== 'none') {
|
||||||
|
const [gemfile, lockFile] = detectGemfiles()
|
||||||
|
|
||||||
await common.measure('Installing Bundler', async () =>
|
await common.measure('Installing Bundler', async () =>
|
||||||
installBundler(inputs['bundler'], platform, rubyPrefix, engine, version))
|
installBundler(inputs['bundler'], lockFile, platform, rubyPrefix, engine, version))
|
||||||
|
|
||||||
if (inputs['bundler-cache'] === 'true') {
|
if (inputs['bundler-cache'] === 'true') {
|
||||||
await common.measure('bundle install', async () =>
|
await common.measure('bundle install', async () =>
|
||||||
bundleInstall(platform, engine, version))
|
bundleInstall(gemfile, lockFile, platform, engine, version))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput('ruby-prefix', rubyPrefix)
|
core.setOutput('ruby-prefix', rubyPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gemsRbPath = "gems.rb"
|
||||||
|
if (fs.existsSync(gemsRbPath)) {
|
||||||
|
const lockPath = "gems.locked"
|
||||||
|
if (fs.existsSync(lockPath)) {
|
||||||
|
return [gemsRbPath, lockPath]
|
||||||
|
} else {
|
||||||
|
return [gemsRbPath, null]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [null, null]
|
||||||
|
}
|
||||||
|
|
||||||
function parseRubyEngineAndVersion(rubyVersion) {
|
function parseRubyEngineAndVersion(rubyVersion) {
|
||||||
if (rubyVersion === 'default') {
|
if (rubyVersion === 'default') {
|
||||||
if (fs.existsSync('.ruby-version')) {
|
if (fs.existsSync('.ruby-version')) {
|
||||||
@@ -150,9 +176,9 @@ function envPreInstall() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBundledWithFromGemfileLock(path) {
|
function readBundledWithFromGemfileLock(lockFile) {
|
||||||
if (fs.existsSync(path)) {
|
if (lockFile !== null) {
|
||||||
const contents = fs.readFileSync(path, 'utf8')
|
const contents = fs.readFileSync(lockFile, 'utf8')
|
||||||
const lines = contents.split(/\r?\n/)
|
const lines = contents.split(/\r?\n/)
|
||||||
const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
|
const bundledWithLine = lines.findIndex(line => /^BUNDLED WITH$/.test(line.trim()))
|
||||||
if (bundledWithLine !== -1) {
|
if (bundledWithLine !== -1) {
|
||||||
@@ -160,7 +186,7 @@ function readBundledWithFromGemfileLock(path) {
|
|||||||
if (nextLine && /^\d+/.test(nextLine.trim())) {
|
if (nextLine && /^\d+/.test(nextLine.trim())) {
|
||||||
const bundlerVersion = nextLine.trim()
|
const bundlerVersion = nextLine.trim()
|
||||||
const majorVersion = bundlerVersion.match(/^\d+/)[0]
|
const majorVersion = bundlerVersion.match(/^\d+/)[0]
|
||||||
console.log(`Using Bundler ${majorVersion} from ${path} BUNDLED WITH ${bundlerVersion}`)
|
console.log(`Using Bundler ${majorVersion} from ${lockFile} BUNDLED WITH ${bundlerVersion}`)
|
||||||
return majorVersion
|
return majorVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,12 +194,12 @@ function readBundledWithFromGemfileLock(path) {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
|
async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
|
||||||
var bundlerVersion = bundlerVersionInput
|
var bundlerVersion = bundlerVersionInput
|
||||||
|
|
||||||
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
|
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
|
||||||
const gemfilePath = `${process.env['BUNDLE_GEMFILE'] || 'Gemfile'}.lock`
|
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
|
||||||
bundlerVersion = readBundledWithFromGemfileLock(gemfilePath)
|
|
||||||
if (!bundlerVersion) {
|
if (!bundlerVersion) {
|
||||||
bundlerVersion = 'latest'
|
bundlerVersion = 'latest'
|
||||||
}
|
}
|
||||||
@@ -209,16 +235,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bundleInstall(platform, engine, version) {
|
async function bundleInstall(gemfile, lockFile, platform, engine, version) {
|
||||||
if (!fs.existsSync('Gemfile')) {
|
if (gemfile === null) {
|
||||||
console.log('No Gemfile, skipping "bundle install" and caching')
|
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// config
|
// config
|
||||||
const path = 'vendor/bundle'
|
const path = 'vendor/bundle'
|
||||||
const hasGemfileLock = fs.existsSync('Gemfile.lock');
|
|
||||||
if (hasGemfileLock) {
|
if (lockFile !== null) {
|
||||||
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
|
await exec.exec('bundle', ['config', '--local', 'deployment', 'true'])
|
||||||
}
|
}
|
||||||
await exec.exec('bundle', ['config', '--local', 'path', path])
|
await exec.exec('bundle', ['config', '--local', 'path', path])
|
||||||
@@ -228,10 +254,10 @@ async function bundleInstall(platform, engine, version) {
|
|||||||
const baseKey = await computeBaseKey(platform, engine, version)
|
const baseKey = await computeBaseKey(platform, engine, version)
|
||||||
let key = baseKey
|
let key = baseKey
|
||||||
let restoreKeys
|
let restoreKeys
|
||||||
if (hasGemfileLock) {
|
if (lockFile !== null) {
|
||||||
key += `-Gemfile.lock-${await common.hashFile('Gemfile.lock')}`
|
key += `-${lockFile}-${await common.hashFile(lockFile)}`
|
||||||
// If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache)
|
// If only Gemfile.lock we can reuse some of the cache (but it will keep old gem versions in the cache)
|
||||||
restoreKeys = [`${baseKey}-Gemfile.lock-`]
|
restoreKeys = [`${baseKey}-${lockFile}-`]
|
||||||
} else {
|
} else {
|
||||||
// Only exact key, to never mix native gems of different platforms or Ruby versions
|
// Only exact key, to never mix native gems of different platforms or Ruby versions
|
||||||
restoreKeys = []
|
restoreKeys = []
|
||||||
@@ -277,6 +303,8 @@ async function bundleInstall(platform, engine, version) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function computeBaseKey(platform, engine, version) {
|
async function computeBaseKey(platform, engine, version) {
|
||||||
|
|||||||
@@ -331,9 +331,9 @@ minimatch@^3.0.4:
|
|||||||
brace-expansion "^1.1.7"
|
brace-expansion "^1.1.7"
|
||||||
|
|
||||||
node-fetch@^2.6.0:
|
node-fetch@^2.6.0:
|
||||||
version "2.6.0"
|
version "2.6.1"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||||
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
|
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||||
|
|
||||||
process@^0.11.10:
|
process@^0.11.10:
|
||||||
version "0.11.10"
|
version "0.11.10"
|
||||||
|
|||||||
Reference in New Issue
Block a user