mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 22:44:20 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b161cb92f0 | ||
|
|
fa2182b2a4 |
@@ -180,6 +180,20 @@ When there is no lockfile, one is generated with `bundle lock`, which is the sam
|
|||||||
In other words, it works exactly like `bundle install`.
|
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.
|
The hash of the generated lockfile is then used for caching, which is the only correct approach.
|
||||||
|
|
||||||
|
#### Dealing with a corrupted cache
|
||||||
|
|
||||||
|
In some rare scenarios (like using gems with C extensions whose functionality depends on libraries found on the system
|
||||||
|
at the time of the gem's build) it may be necessary to ignore contents of the cache and get and build all the gems anew.
|
||||||
|
In order to achieve this, set the `cache-version` option to any value other than `0` (or change it to a new unique value
|
||||||
|
if you have already used it before.)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
bundler-cache: true
|
||||||
|
cache-version: 1
|
||||||
|
```
|
||||||
|
|
||||||
#### Caching `bundle install` manually
|
#### 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.
|
It is also possible to cache gems manually, but this is not recommended because it is verbose and *very difficult* to do correctly.
|
||||||
|
|||||||
@@ -24,6 +24,12 @@ inputs:
|
|||||||
description: 'The working directory to use for resolving paths for .ruby-version, .tool-versions and Gemfile.lock.'
|
description: 'The working directory to use for resolving paths for .ruby-version, .tool-versions and Gemfile.lock.'
|
||||||
required: false
|
required: false
|
||||||
default: '.'
|
default: '.'
|
||||||
|
cache-version:
|
||||||
|
description: |
|
||||||
|
Arbitrary string that will be added to the cache key of the bundler cache. Set or change it if you need
|
||||||
|
to invalidate the cache.
|
||||||
|
required: false
|
||||||
|
default: '0'
|
||||||
outputs:
|
outputs:
|
||||||
ruby-prefix:
|
ruby-prefix:
|
||||||
description: 'The prefix of the installed ruby'
|
description: 'The prefix of the installed ruby'
|
||||||
|
|||||||
+7
-4
@@ -5,6 +5,8 @@ const exec = require('@actions/exec')
|
|||||||
const cache = require('@actions/cache')
|
const cache = require('@actions/cache')
|
||||||
const common = require('./common')
|
const common = require('./common')
|
||||||
|
|
||||||
|
export const DEFAULT_CACHE_VERSION = '0'
|
||||||
|
|
||||||
// The returned gemfile is guaranteed to exist, the lockfile might not exist
|
// The returned gemfile is guaranteed to exist, the lockfile might not exist
|
||||||
export function detectGemfiles() {
|
export function detectGemfiles() {
|
||||||
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
|
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
|
||||||
@@ -95,7 +97,7 @@ export async function installBundler(bundlerVersionInput, lockFile, platform, ru
|
|||||||
return bundlerVersion
|
return bundlerVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion) {
|
export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion, cacheVersion) {
|
||||||
if (gemfile === null) {
|
if (gemfile === null) {
|
||||||
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
||||||
return false
|
return false
|
||||||
@@ -128,7 +130,7 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
|
|||||||
|
|
||||||
// cache key
|
// cache key
|
||||||
const paths = [cachePath]
|
const paths = [cachePath]
|
||||||
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile)
|
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile, cacheVersion)
|
||||||
const key = `${baseKey}-${await common.hashFile(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
|
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
|
||||||
const restoreKeys = [`${baseKey}-`]
|
const restoreKeys = [`${baseKey}-`]
|
||||||
@@ -177,8 +179,9 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function computeBaseKey(platform, engine, version, lockFile) {
|
async function computeBaseKey(platform, engine, version, lockFile, cacheVersion) {
|
||||||
let key = `setup-ruby-bundler-cache-v3-${platform}-${engine}-${version}`
|
const cacheVersionSuffix = DEFAULT_CACHE_VERSION === cacheVersion ? '' : `-cachever:${cacheVersion}`
|
||||||
|
let key = `setup-ruby-bundler-cache-v3-${platform}-${engine}-${version}${cacheVersionSuffix}`
|
||||||
|
|
||||||
if (engine !== 'jruby' && common.isHeadVersion(version)) {
|
if (engine !== 'jruby' && common.isHeadVersion(version)) {
|
||||||
let revision = '';
|
let revision = '';
|
||||||
|
|||||||
+10
-5
@@ -44537,6 +44537,7 @@ module.exports = require("net");
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
__webpack_require__.r(__webpack_exports__);
|
__webpack_require__.r(__webpack_exports__);
|
||||||
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_CACHE_VERSION", function() { return DEFAULT_CACHE_VERSION; });
|
||||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "detectGemfiles", function() { return detectGemfiles; });
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "detectGemfiles", function() { return detectGemfiles; });
|
||||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "installBundler", function() { return installBundler; });
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "installBundler", function() { return installBundler; });
|
||||||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "bundleInstall", function() { return bundleInstall; });
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "bundleInstall", function() { return bundleInstall; });
|
||||||
@@ -44547,6 +44548,8 @@ const exec = __webpack_require__(514)
|
|||||||
const cache = __webpack_require__(799)
|
const cache = __webpack_require__(799)
|
||||||
const common = __webpack_require__(390)
|
const common = __webpack_require__(390)
|
||||||
|
|
||||||
|
const DEFAULT_CACHE_VERSION = '0'
|
||||||
|
|
||||||
// The returned gemfile is guaranteed to exist, the lockfile might not exist
|
// The returned gemfile is guaranteed to exist, the lockfile might not exist
|
||||||
function detectGemfiles() {
|
function detectGemfiles() {
|
||||||
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
|
const gemfilePath = process.env['BUNDLE_GEMFILE'] || 'Gemfile'
|
||||||
@@ -44637,7 +44640,7 @@ async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefi
|
|||||||
return bundlerVersion
|
return bundlerVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion) {
|
async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, bundlerVersion, cacheVersion) {
|
||||||
if (gemfile === null) {
|
if (gemfile === null) {
|
||||||
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
|
||||||
return false
|
return false
|
||||||
@@ -44670,7 +44673,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b
|
|||||||
|
|
||||||
// cache key
|
// cache key
|
||||||
const paths = [cachePath]
|
const paths = [cachePath]
|
||||||
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile)
|
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile, cacheVersion)
|
||||||
const key = `${baseKey}-${await common.hashFile(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
|
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
|
||||||
const restoreKeys = [`${baseKey}-`]
|
const restoreKeys = [`${baseKey}-`]
|
||||||
@@ -44719,8 +44722,9 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function computeBaseKey(platform, engine, version, lockFile) {
|
async function computeBaseKey(platform, engine, version, lockFile, cacheVersion) {
|
||||||
let key = `setup-ruby-bundler-cache-v3-${platform}-${engine}-${version}`
|
const cacheVersionSuffix = DEFAULT_CACHE_VERSION === cacheVersion ? '' : `-cachever:${cacheVersion}`
|
||||||
|
let key = `setup-ruby-bundler-cache-v3-${platform}-${engine}-${version}${cacheVersionSuffix}`
|
||||||
|
|
||||||
if (engine !== 'jruby' && common.isHeadVersion(version)) {
|
if (engine !== 'jruby' && common.isHeadVersion(version)) {
|
||||||
let revision = '';
|
let revision = '';
|
||||||
@@ -52071,6 +52075,7 @@ const inputDefaults = {
|
|||||||
'bundler': 'default',
|
'bundler': 'default',
|
||||||
'bundler-cache': 'true',
|
'bundler-cache': 'true',
|
||||||
'working-directory': '.',
|
'working-directory': '.',
|
||||||
|
'cache-version': bundler.DEFAULT_CACHE_VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
// entry point when this action is run on its own
|
// entry point when this action is run on its own
|
||||||
@@ -52126,7 +52131,7 @@ async function setupRuby(options = {}) {
|
|||||||
|
|
||||||
if (inputs['bundler-cache'] === 'true') {
|
if (inputs['bundler-cache'] === 'true') {
|
||||||
await common.measure('bundle install', async () =>
|
await common.measure('bundle install', async () =>
|
||||||
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion))
|
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion, inputs['cache-version']))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const inputDefaults = {
|
|||||||
'bundler': 'default',
|
'bundler': 'default',
|
||||||
'bundler-cache': 'true',
|
'bundler-cache': 'true',
|
||||||
'working-directory': '.',
|
'working-directory': '.',
|
||||||
|
'cache-version': bundler.DEFAULT_CACHE_VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
// entry point when this action is run on its own
|
// entry point when this action is run on its own
|
||||||
@@ -67,7 +68,7 @@ export async function setupRuby(options = {}) {
|
|||||||
|
|
||||||
if (inputs['bundler-cache'] === 'true') {
|
if (inputs['bundler-cache'] === 'true') {
|
||||||
await common.measure('bundle install', async () =>
|
await common.measure('bundle install', async () =>
|
||||||
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion))
|
bundler.bundleInstall(gemfile, lockFile, platform, engine, version, bundlerVersion, inputs['cache-version']))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user