Compare commits

...
12 Commits
Author SHA1 Message Date
Benoit Daloze 0effb2cc50 Document that gems.rb/gems.locked is supported now 2020-09-19 11:43:36 +02:00
Benoit Daloze b62e5d53aa Take advantage that detectGemfiles() only returns existing paths
* So use !== null instead of redoing the existsSync() check.
* Rename a few variables for consistency.
2020-09-19 11:31:18 +02:00
Samuel Williams 1c172ef5dc Add support for gems.rb/gems.locked during bundle install (#84)
* Extract detection of gemfile and lockfile.
2020-09-19 11:18:52 +02:00
dependabot[bot] 4cbbce6b48 Bump node-fetch from 2.6.0 to 2.6.1
Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-09-13 13:21:14 +02:00
Benoit Daloze 108b3a2c8a Various cleanups 2020-09-03 13:42:03 +02:00
Benoit Daloze 25ccf0aad8 Fix interpolation in addVCVARSEnv() 2020-09-03 13:42:03 +02:00
Benoit Daloze 9ec93a2370 Print the full $PATH with bash to help debugging 2020-09-03 13:21:50 +02:00
MSP-Greg a096b998ad Add Actions 'bash test' and 'Windows JRuby' (gem install sassc) steps 2020-09-03 12:13:49 +02:00
MSP-Greg 6ead459c74 Add envPreInstall, common.setupPath, use MSYS2 bash for Windows bash
envPreInstall - sets ENV values for runners

common.setupPath - collects all Path operations into one function, runs before Ruby install

Add MSYS2 paths to all Windows builds for MSYS2 Bash use
2020-09-03 12:13:49 +02:00
MSP-Greg 45ec312a6e windows.js - remove code for embedded MSYS2 2020-09-03 12:13:49 +02:00
Benoit Daloze 568cdbf232 Revert "Add support for gems.rb/gems.locked during bundle install."
* This reverts commit 638e8fff19.
* Needs some fixes and review.
2020-09-03 11:58:37 +02:00
Samuel Williams 638e8fff19 Add support for gems.rb/gems.locked during bundle install. 2020-09-03 10:48:45 +12:00
9 changed files with 293 additions and 211 deletions
+9
View File
@@ -41,6 +41,9 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- run: ruby -v
- name: PATH
shell: bash
run: echo $PATH
- name: build compiler
run: |
@@ -85,6 +88,12 @@ jobs:
else { echo "Can't find $e" }
echo ''
}
- name: bash test
shell: bash
run: echo ~
- name: Windows JRuby
if: startsWith(matrix.os, 'windows') && startsWith(matrix.ruby, 'jruby')
run: gem install sassc -N
lint:
runs-on: ubuntu-latest
+3 -4
View File
@@ -115,7 +115,7 @@ 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` 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.
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.
It needs a `Gemfile` (or `$BUNDLE_GEMFILE`) under the [`working-directory`](#working-directory).
The caching works whether there is a `Gemfile.lock` or not.
If there is a `Gemfile.lock`, `bundle config --local deployment true` is used.
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 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.
+2 -2
View File
@@ -12,8 +12,8 @@ inputs:
bundler:
description: |
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.
Defaults to 'Gemfile.lock' if it exists and 'latest' otherwise.
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
default: 'default'
bundler-cache:
+36 -1
View File
@@ -1,4 +1,5 @@
const os = require('os')
const path = require('path')
const fs = require('fs')
const util = require('util')
const stream = require('stream')
@@ -6,6 +7,10 @@ const crypto = require('crypto')
const core = require('@actions/core')
const { performance } = require('perf_hooks')
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 async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
@@ -55,10 +60,40 @@ function findUbuntuVersion() {
}
// convert windows path like C:\Users\runneradmin to /c/Users/runneradmin
export function win2nix(path) {
export function win2nix(path) {
if (/^[A-Z]:/i.test(path)) {
// path starts with drive
path = `/${path[0].toLowerCase()}${path.split(':', 2)[1]}`
}
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
}
export function setupPath(newPathEntries) {
const envPath = windows ? 'Path' : 'PATH'
const originalPath = process.env[envPath].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
// First remove the conflicting path entries
if (cleanPath.length !== originalPath.length) {
core.startGroup(`Cleaning ${envPath}`)
console.log(`Entries removed from ${envPath} to avoid conflicts with Ruby:`)
for (const entry of originalPath) {
if (!cleanPath.includes(entry)) {
console.log(` ${entry}`)
}
}
core.exportVariable(envPath, cleanPath.join(path.delimiter))
core.endGroup()
}
// Then add new path entries using core.addPath()
let newPath
if (windows) {
// add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain
const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin']
newPath = [...newPathEntries, ...msys2]
} else {
newPath = newPathEntries
}
core.addPath(newPath.join(path.delimiter))
}
Generated Vendored
+144 -102
View File
@@ -27670,20 +27670,14 @@ const tc = __webpack_require__(188)
const common = __webpack_require__(390)
const rubyInstallerVersions = __webpack_require__(223).versions
// Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14
const drive = (process.env['GITHUB_WORKSPACE'] || 'C')[0]
const drive = common.drive
// needed for 2.1, 2.2, 2.3, and mswin, cert file used by Git for Windows
const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem'
// standard MSYS2 location, found by 'devkit.rb'
const msys2 = 'C:\\msys64'
const msys2PathEntries = [`${msys2}\\mingw64\\bin`, `${msys2}\\usr\\bin`]
// location & path for old RubyInstaller DevKit (MSYS), Ruby 2.1, 2.2 and 2.3
const msys = `${drive}:\\DevKit64`
const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`,
`${msys}\\mingw\\bin`, `${msys}\\bin`]
const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`, `${msys}\\mingw\\bin`, `${msys}\\bin`]
function getAvailableVersions(platform, engine) {
if (engine === 'ruby') {
@@ -27701,6 +27695,12 @@ async function install(platform, engine, version) {
}
const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length)
const rubyPrefix = `${drive}:\\${base}`
let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version)
common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths])
const downloadPath = await common.measure('Downloading Ruby', async () => {
console.log(url)
return await tc.downloadTool(url)
@@ -27708,26 +27708,8 @@ async function install(platform, engine, version) {
await common.measure('Extracting Ruby', async () =>
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }))
const rubyPrefix = `${drive}:\\${base}`
let toolchainPaths = (version === 'mswin') ?
await setupMSWin() : await setupMingw(version)
const newPathEntries = [`${rubyPrefix}\\bin`, ...toolchainPaths]
return [rubyPrefix, newPathEntries]
}
// Remove when Actions Windows image contains MSYS2 install
async function symLinkToEmbeddedMSYS2() {
const toolCacheVersions = tc.findAllVersions('Ruby')
toolCacheVersions.sort()
if (toolCacheVersions.length === 0) {
throw new Error('Could not find MSYS2 in the toolcache')
}
const latestVersion = toolCacheVersions.slice(-1)[0]
const hostedRuby = tc.find('Ruby', latestVersion)
await common.measure('Linking MSYS2', async () =>
exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`))
return rubyPrefix
}
async function setupMingw(version) {
@@ -27735,17 +27717,10 @@ async function setupMingw(version) {
if (version.match(/^2\.[123]/)) {
core.exportVariable('SSL_CERT_FILE', certFile)
await common.measure('Installing MSYS1', async () =>
installMSYS(version))
await common.measure('Installing MSYS', async () => installMSYS(version))
return msysPathEntries
} else {
// Remove when Actions Windows image contains MSYS2 install
if (!fs.existsSync(msys2)) {
await symLinkToEmbeddedMSYS2()
}
return msys2PathEntries
return []
}
}
@@ -27778,15 +27753,7 @@ async function setupMSWin() {
fs.copyFileSync(certFile, cert)
}
// Remove when Actions Windows image contains MSYS2 install
if (!fs.existsSync(msys2)) {
await symLinkToEmbeddedMSYS2()
}
const VCPathEntries = await common.measure('Setting up MSVC environment', async () =>
addVCVARSEnv())
return [...VCPathEntries, ...msys2PathEntries]
return await common.measure('Setting up MSVC environment', async () => addVCVARSEnv())
}
/* Sets MSVC environment for use in Actions
@@ -27809,8 +27776,9 @@ function addVCVARSEnv() {
let newPathEntries = undefined
for (let [k, v] of newEnv) {
if (process.env[k] !== v) {
if (k === 'Path') {
newPathEntries = v.replace(process.env['Path'], '').split(path.delimiter)
if (/^Path$/i.test(k)) {
const newPathStr = v.replace(`${path.delimiter}${process.env['Path']}`, '')
newPathEntries = newPathStr.split(path.delimiter)
} else {
core.exportVariable(k, v)
}
@@ -32085,12 +32053,16 @@ exports.default = _default;
"use strict";
__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__, "measure", function() { return measure; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isHeadVersion", function() { return isHeadVersion; });
/* 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__, "win2nix", function() { return win2nix; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setupPath", function() { return setupPath; });
const os = __webpack_require__(87)
const path = __webpack_require__(622)
const fs = __webpack_require__(747)
const util = __webpack_require__(669)
const stream = __webpack_require__(413)
@@ -32098,6 +32070,10 @@ const crypto = __webpack_require__(373)
const core = __webpack_require__(186)
const { performance } = __webpack_require__(630)
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)
async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
@@ -32147,7 +32123,7 @@ function findUbuntuVersion() {
}
// convert windows path like C:\Users\runneradmin to /c/Users/runneradmin
function win2nix(path) {
function win2nix(path) {
if (/^[A-Z]:/i.test(path)) {
// path starts with drive
path = `/${path[0].toLowerCase()}${path.split(':', 2)[1]}`
@@ -32155,6 +32131,36 @@ function win2nix(path) {
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
}
function setupPath(newPathEntries) {
const envPath = windows ? 'Path' : 'PATH'
const originalPath = process.env[envPath].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
// First remove the conflicting path entries
if (cleanPath.length !== originalPath.length) {
core.startGroup(`Cleaning ${envPath}`)
console.log(`Entries removed from ${envPath} to avoid conflicts with Ruby:`)
for (const entry of originalPath) {
if (!cleanPath.includes(entry)) {
console.log(` ${entry}`)
}
}
core.exportVariable(envPath, cleanPath.join(path.delimiter))
core.endGroup()
}
// Then add new path entries using core.addPath()
let newPath
if (windows) {
// add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain
const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin']
newPath = [...newPathEntries, ...msys2]
} else {
newPath = newPathEntries
}
core.addPath(newPath.join(path.delimiter))
}
/***/ }),
/* 391 */,
@@ -33965,6 +33971,12 @@ function convertBody(buffer, headers) {
// html4
if (!res && 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) {
res = /charset=(.*)/i.exec(res.pop());
@@ -34972,7 +34984,7 @@ function fetch(url, opts) {
// HTTP fetch step 5.5
switch (request.redirect) {
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();
return;
case 'manual':
@@ -35011,7 +35023,8 @@ function fetch(url, opts) {
method: request.method,
body: request.body,
signal: request.signal,
timeout: request.timeout
timeout: request.timeout,
size: request.size
};
// HTTP-redirect fetch step 9
@@ -51350,6 +51363,8 @@ const exec = __webpack_require__(514)
const cache = __webpack_require__(799)
const common = __webpack_require__(390)
const windows = common.windows
const inputDefaults = {
'ruby-version': 'default',
'bundler': 'default',
@@ -51370,7 +51385,7 @@ async function run() {
async function setupRuby(options = {}) {
const inputs = { ...options }
for (const key in inputDefaults) {
if (!inputs.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(inputs, key)) {
inputs[key] = core.getInput(key) || inputDefaults[key]
}
}
@@ -51391,10 +51406,9 @@ async function setupRuby(options = {}) {
const version = validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVersion)
createGemRC()
envPreInstall()
const [rubyPrefix, newPathEntries] = await installer.install(platform, engine, version)
setupPath(newPathEntries)
const rubyPrefix = await installer.install(platform, engine, version)
// When setup-ruby is used by other actions, this allows code in them to run
// before 'bundle install'. Installed dependencies may require additional
@@ -51404,18 +51418,44 @@ async function setupRuby(options = {}) {
}
if (inputs['bundler'] !== 'none') {
const [gemfile, lockFile] = detectGemfiles()
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') {
await common.measure('bundle install', async () =>
bundleInstall(platform, engine, version))
bundleInstall(gemfile, lockFile, platform, engine, version))
}
}
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) {
if (rubyVersion === 'default') {
if (fs.existsSync('.ruby-version')) {
@@ -51479,27 +51519,23 @@ function createGemRC() {
}
}
function setupPath(newPathEntries) {
const originalPath = process.env['PATH'].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
if (cleanPath.length !== originalPath.length) {
core.startGroup('Cleaning PATH')
console.log('Entries removed from PATH to avoid conflicts with Ruby:')
for (const entry of originalPath) {
if (!cleanPath.includes(entry)) {
console.log(` ${entry}`)
}
}
core.endGroup()
// sets up ENV variables
// currently only used on Windows runners
function envPreInstall() {
const ENV = process.env
if (windows) {
// puts normal Ruby temp folder on SSD
core.exportVariable('TMPDIR', ENV['RUNNER_TEMP'])
// bash - sets home to match native windows, normally C:\Users\<user name>
core.exportVariable('HOME', ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
// bash - needed to maintain Path from Windows
core.exportVariable('MSYS2_PATH_TYPE', 'inherit')
}
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
}
function readBundledWithFromGemfileLock(path) {
if (fs.existsSync(path)) {
const contents = fs.readFileSync(path, 'utf8')
function readBundledWithFromGemfileLock(lockFile) {
if (lockFile !== null) {
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) {
@@ -51507,7 +51543,7 @@ function readBundledWithFromGemfileLock(path) {
if (nextLine && /^\d+/.test(nextLine.trim())) {
const bundlerVersion = nextLine.trim()
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
}
}
@@ -51515,12 +51551,12 @@ function readBundledWithFromGemfileLock(path) {
return null
}
async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = bundlerVersionInput
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
const gemfilePath = `${process.env['BUNDLE_GEMFILE'] || 'Gemfile'}.lock`
bundlerVersion = readBundledWithFromGemfileLock(gemfilePath)
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
if (!bundlerVersion) {
bundlerVersion = 'latest'
}
@@ -51556,16 +51592,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine,
}
}
async function bundleInstall(platform, engine, version) {
if (!fs.existsSync('Gemfile')) {
console.log('No Gemfile, skipping "bundle install" and caching')
return
async function bundleInstall(gemfile, lockFile, platform, engine, version) {
if (gemfile === null) {
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
return false
}
// config
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', 'path', path])
@@ -51575,10 +51611,10 @@ async function bundleInstall(platform, engine, version) {
const baseKey = await computeBaseKey(platform, engine, version)
let key = baseKey
let restoreKeys
if (hasGemfileLock) {
key += `-Gemfile.lock-${await common.hashFile('Gemfile.lock')}`
if (lockFile !== null) {
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)
restoreKeys = [`${baseKey}-Gemfile.lock-`]
restoreKeys = [`${baseKey}-${lockFile}-`]
} else {
// Only exact key, to never mix native gems of different platforms or Ruby versions
restoreKeys = []
@@ -51624,6 +51660,8 @@ async function bundleInstall(platform, engine, version) {
}
}
}
return true
}
async function computeBaseKey(platform, engine, version) {
@@ -53066,23 +53104,28 @@ const rubyBuilderVersions = __webpack_require__(694)
const builderReleaseTag = 'enable-shared'
const releasesURL = 'https://github.com/ruby/ruby-builder/releases'
const windows = common.windows
function getAvailableVersions(platform, engine) {
return rubyBuilderVersions.getVersions(platform)[engine]
}
async function install(platform, engine, version) {
const rubyPrefix = await downloadAndExtract(platform, engine, version)
let newPathEntries
if (engine === 'rubinius') {
newPathEntries = [path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')]
} else {
newPathEntries = [path.join(rubyPrefix, 'bin')]
}
return [rubyPrefix, newPathEntries]
return await downloadAndExtract(platform, engine, version)
}
async function downloadAndExtract(platform, engine, version) {
const rubiesDir = path.join(os.homedir(), '.rubies')
const rubiesDir = windows ? `${common.drive}:` : path.join(os.homedir(), '.rubies')
const rubyPrefix = path.join(rubiesDir, `${engine}-${version}`)
// Set the PATH now, so the MSYS2 'tar' is in Path on Windows
if (engine === 'rubinius') {
common.setupPath([path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')])
} else {
common.setupPath([path.join(rubyPrefix, 'bin')])
}
await io.mkdirP(rubiesDir)
const downloadPath = await common.measure('Downloading Ruby', async () => {
@@ -53092,16 +53135,15 @@ async function downloadAndExtract(platform, engine, version) {
})
await common.measure('Extracting Ruby', async () => {
if (process.env.ImageOS === 'win16') {
const tar = '"C:\\Program Files\\Git\\usr\\bin\\tar.exe"'
await exec.exec(tar, [ '-xz', '-C', common.win2nix(rubiesDir), '-f', common.win2nix(downloadPath) ])
if (windows) {
// Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
await exec.exec('tar', [ '-xz', '-C', common.win2nix(rubiesDir), '-f', common.win2nix(downloadPath) ])
} else {
const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar'
await exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ])
await exec.exec('tar', [ '-xz', '-C', rubiesDir, '-f', downloadPath ])
}
})
return path.join(rubiesDir, `${engine}-${version}`)
return rubyPrefix
}
function getDownloadURL(platform, engine, version) {
+62 -37
View File
@@ -6,6 +6,8 @@ const exec = require('@actions/exec')
const cache = require('@actions/cache')
const common = require('./common')
const windows = common.windows
const inputDefaults = {
'ruby-version': 'default',
'bundler': 'default',
@@ -26,7 +28,7 @@ export async function run() {
export async function setupRuby(options = {}) {
const inputs = { ...options }
for (const key in inputDefaults) {
if (!inputs.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(inputs, key)) {
inputs[key] = core.getInput(key) || inputDefaults[key]
}
}
@@ -47,10 +49,9 @@ export async function setupRuby(options = {}) {
const version = validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVersion)
createGemRC()
envPreInstall()
const [rubyPrefix, newPathEntries] = await installer.install(platform, engine, version)
setupPath(newPathEntries)
const rubyPrefix = await installer.install(platform, engine, version)
// When setup-ruby is used by other actions, this allows code in them to run
// before 'bundle install'. Installed dependencies may require additional
@@ -60,18 +61,44 @@ export async function setupRuby(options = {}) {
}
if (inputs['bundler'] !== 'none') {
const [gemfile, lockFile] = detectGemfiles()
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') {
await common.measure('bundle install', async () =>
bundleInstall(platform, engine, version))
bundleInstall(gemfile, lockFile, platform, engine, version))
}
}
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) {
if (rubyVersion === 'default') {
if (fs.existsSync('.ruby-version')) {
@@ -135,27 +162,23 @@ function createGemRC() {
}
}
function setupPath(newPathEntries) {
const originalPath = process.env['PATH'].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
if (cleanPath.length !== originalPath.length) {
core.startGroup('Cleaning PATH')
console.log('Entries removed from PATH to avoid conflicts with Ruby:')
for (const entry of originalPath) {
if (!cleanPath.includes(entry)) {
console.log(` ${entry}`)
}
}
core.endGroup()
// sets up ENV variables
// currently only used on Windows runners
function envPreInstall() {
const ENV = process.env
if (windows) {
// puts normal Ruby temp folder on SSD
core.exportVariable('TMPDIR', ENV['RUNNER_TEMP'])
// bash - sets home to match native windows, normally C:\Users\<user name>
core.exportVariable('HOME', ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
// bash - needed to maintain Path from Windows
core.exportVariable('MSYS2_PATH_TYPE', 'inherit')
}
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
}
function readBundledWithFromGemfileLock(path) {
if (fs.existsSync(path)) {
const contents = fs.readFileSync(path, 'utf8')
function readBundledWithFromGemfileLock(lockFile) {
if (lockFile !== null) {
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) {
@@ -163,7 +186,7 @@ function readBundledWithFromGemfileLock(path) {
if (nextLine && /^\d+/.test(nextLine.trim())) {
const bundlerVersion = nextLine.trim()
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
}
}
@@ -171,12 +194,12 @@ function readBundledWithFromGemfileLock(path) {
return null
}
async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine, rubyVersion) {
async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = bundlerVersionInput
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
const gemfilePath = `${process.env['BUNDLE_GEMFILE'] || 'Gemfile'}.lock`
bundlerVersion = readBundledWithFromGemfileLock(gemfilePath)
bundlerVersion = readBundledWithFromGemfileLock(lockFile)
if (!bundlerVersion) {
bundlerVersion = 'latest'
}
@@ -212,16 +235,16 @@ async function installBundler(bundlerVersionInput, platform, rubyPrefix, engine,
}
}
async function bundleInstall(platform, engine, version) {
if (!fs.existsSync('Gemfile')) {
console.log('No Gemfile, skipping "bundle install" and caching')
return
async function bundleInstall(gemfile, lockFile, platform, engine, version) {
if (gemfile === null) {
console.log('Could not determine gemfile path, skipping "bundle install" and caching')
return false
}
// config
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', 'path', path])
@@ -231,10 +254,10 @@ async function bundleInstall(platform, engine, version) {
const baseKey = await computeBaseKey(platform, engine, version)
let key = baseKey
let restoreKeys
if (hasGemfileLock) {
key += `-Gemfile.lock-${await common.hashFile('Gemfile.lock')}`
if (lockFile !== null) {
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)
restoreKeys = [`${baseKey}-Gemfile.lock-`]
restoreKeys = [`${baseKey}-${lockFile}-`]
} else {
// Only exact key, to never mix native gems of different platforms or Ruby versions
restoreKeys = []
@@ -280,6 +303,8 @@ async function bundleInstall(platform, engine, version) {
}
}
}
return true
}
async function computeBaseKey(platform, engine, version) {
+19 -15
View File
@@ -9,23 +9,28 @@ const rubyBuilderVersions = require('./ruby-builder-versions')
const builderReleaseTag = 'enable-shared'
const releasesURL = 'https://github.com/ruby/ruby-builder/releases'
const windows = common.windows
export function getAvailableVersions(platform, engine) {
return rubyBuilderVersions.getVersions(platform)[engine]
}
export async function install(platform, engine, version) {
const rubyPrefix = await downloadAndExtract(platform, engine, version)
let newPathEntries
if (engine === 'rubinius') {
newPathEntries = [path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')]
} else {
newPathEntries = [path.join(rubyPrefix, 'bin')]
}
return [rubyPrefix, newPathEntries]
return await downloadAndExtract(platform, engine, version)
}
async function downloadAndExtract(platform, engine, version) {
const rubiesDir = path.join(os.homedir(), '.rubies')
const rubiesDir = windows ? `${common.drive}:` : path.join(os.homedir(), '.rubies')
const rubyPrefix = path.join(rubiesDir, `${engine}-${version}`)
// Set the PATH now, so the MSYS2 'tar' is in Path on Windows
if (engine === 'rubinius') {
common.setupPath([path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')])
} else {
common.setupPath([path.join(rubyPrefix, 'bin')])
}
await io.mkdirP(rubiesDir)
const downloadPath = await common.measure('Downloading Ruby', async () => {
@@ -35,16 +40,15 @@ async function downloadAndExtract(platform, engine, version) {
})
await common.measure('Extracting Ruby', async () => {
if (process.env.ImageOS === 'win16') {
const tar = '"C:\\Program Files\\Git\\usr\\bin\\tar.exe"'
await exec.exec(tar, [ '-xz', '-C', common.win2nix(rubiesDir), '-f', common.win2nix(downloadPath) ])
if (windows) {
// Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
await exec.exec('tar', [ '-xz', '-C', common.win2nix(rubiesDir), '-f', common.win2nix(downloadPath) ])
} else {
const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar'
await exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ])
await exec.exec('tar', [ '-xz', '-C', rubiesDir, '-f', downloadPath ])
}
})
return path.join(rubiesDir, `${engine}-${version}`)
return rubyPrefix
}
function getDownloadURL(platform, engine, version) {
+15 -47
View File
@@ -10,20 +10,14 @@ const tc = require('@actions/tool-cache')
const common = require('./common')
const rubyInstallerVersions = require('./windows-versions').versions
// Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14
const drive = (process.env['GITHUB_WORKSPACE'] || 'C')[0]
const drive = common.drive
// needed for 2.1, 2.2, 2.3, and mswin, cert file used by Git for Windows
const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem'
// standard MSYS2 location, found by 'devkit.rb'
const msys2 = 'C:\\msys64'
const msys2PathEntries = [`${msys2}\\mingw64\\bin`, `${msys2}\\usr\\bin`]
// location & path for old RubyInstaller DevKit (MSYS), Ruby 2.1, 2.2 and 2.3
const msys = `${drive}:\\DevKit64`
const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`,
`${msys}\\mingw\\bin`, `${msys}\\bin`]
const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`, `${msys}\\mingw\\bin`, `${msys}\\bin`]
export function getAvailableVersions(platform, engine) {
if (engine === 'ruby') {
@@ -41,6 +35,12 @@ export async function install(platform, engine, version) {
}
const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length)
const rubyPrefix = `${drive}:\\${base}`
let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version)
common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths])
const downloadPath = await common.measure('Downloading Ruby', async () => {
console.log(url)
return await tc.downloadTool(url)
@@ -48,26 +48,8 @@ export async function install(platform, engine, version) {
await common.measure('Extracting Ruby', async () =>
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }))
const rubyPrefix = `${drive}:\\${base}`
let toolchainPaths = (version === 'mswin') ?
await setupMSWin() : await setupMingw(version)
const newPathEntries = [`${rubyPrefix}\\bin`, ...toolchainPaths]
return [rubyPrefix, newPathEntries]
}
// Remove when Actions Windows image contains MSYS2 install
async function symLinkToEmbeddedMSYS2() {
const toolCacheVersions = tc.findAllVersions('Ruby')
toolCacheVersions.sort()
if (toolCacheVersions.length === 0) {
throw new Error('Could not find MSYS2 in the toolcache')
}
const latestVersion = toolCacheVersions.slice(-1)[0]
const hostedRuby = tc.find('Ruby', latestVersion)
await common.measure('Linking MSYS2', async () =>
exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`))
return rubyPrefix
}
async function setupMingw(version) {
@@ -75,17 +57,10 @@ async function setupMingw(version) {
if (version.match(/^2\.[123]/)) {
core.exportVariable('SSL_CERT_FILE', certFile)
await common.measure('Installing MSYS1', async () =>
installMSYS(version))
await common.measure('Installing MSYS', async () => installMSYS(version))
return msysPathEntries
} else {
// Remove when Actions Windows image contains MSYS2 install
if (!fs.existsSync(msys2)) {
await symLinkToEmbeddedMSYS2()
}
return msys2PathEntries
return []
}
}
@@ -118,15 +93,7 @@ async function setupMSWin() {
fs.copyFileSync(certFile, cert)
}
// Remove when Actions Windows image contains MSYS2 install
if (!fs.existsSync(msys2)) {
await symLinkToEmbeddedMSYS2()
}
const VCPathEntries = await common.measure('Setting up MSVC environment', async () =>
addVCVARSEnv())
return [...VCPathEntries, ...msys2PathEntries]
return await common.measure('Setting up MSVC environment', async () => addVCVARSEnv())
}
/* Sets MSVC environment for use in Actions
@@ -149,8 +116,9 @@ export function addVCVARSEnv() {
let newPathEntries = undefined
for (let [k, v] of newEnv) {
if (process.env[k] !== v) {
if (k === 'Path') {
newPathEntries = v.replace(process.env['Path'], '').split(path.delimiter)
if (/^Path$/i.test(k)) {
const newPathStr = v.replace(`${path.delimiter}${process.env['Path']}`, '')
newPathEntries = newPathStr.split(path.delimiter)
} else {
core.exportVariable(k, v)
}
Generated
+3 -3
View File
@@ -331,9 +331,9 @@ minimatch@^3.0.4:
brace-expansion "^1.1.7"
node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
process@^0.11.10:
version "0.11.10"