Compare commits

..
16 Commits
Author SHA1 Message Date
Benoit Daloze ec106b438a Document the consequences of using a specific version or commit sha 2020-04-09 19:25:18 +02:00
Benoit Daloze d7f9647ad8 Move Versioning earlier in README 2020-04-09 19:09:20 +02:00
Benoit Daloze f25e77d702 Do not show a "Installing Bundler" group if bundler: none
* That was rather confusing.
2020-04-05 20:04:22 +02:00
Benoit Daloze 463c3a8161 Simplify conditions 2020-04-05 14:46:21 +02:00
Benoit Daloze 63190648f4 Add some spacing in workflow 2020-04-05 14:44:43 +02:00
Benoit Daloze aec70617e0 Let CI run on pushes to master 2020-04-05 14:43:13 +02:00
Benoit Daloze 759c98774b Merge CI in a single workflow with the new include syntax 2020-04-05 14:25:26 +02:00
Benoit Daloze 24d7979773 Simplify os syntax in CI to avoid so many '-latest' 2020-04-05 14:18:41 +02:00
Benoit Daloze 56996937ab Clarify messages about the shipped Bundler being reused 2020-04-05 14:16:21 +02:00
Benoit Daloze e9b0369f85 Add groups to clarify output and measure the time each group takes 2020-04-05 14:09:18 +02:00
Benoit Daloze 045dd42354 Fix indentation 2020-04-05 13:51:43 +02:00
Benoit Daloze 152ff008a3 Extract utility methods to common.js 2020-04-05 13:27:45 +02:00
Benoit Daloze d4f9058279 Reorder 2020-04-03 23:59:35 +02:00
Benoit Daloze c40ce85201 Do not install Bundler 2 for ruby-head since it already ships a version that might work better 2020-04-03 23:58:23 +02:00
Benoit Daloze c68e25cb8c Explicitly use Bundler 2 if there is no version specified
* Avoid issues when using --conservative as seen in
  https://github.com/ruby/setup-ruby/pull/48, clarifies what's getting
  installed and simplifies the following logic.
* We'll probably need changes when Bundler 3 comes out anyway.
2020-04-03 23:57:16 +02:00
MSP-Greg 95135e9903 README.md - remove reference to MSP-Greg/actions-ruby
Preferred repo is now MSP-Greg/setup-ruby-pkgs
2020-04-03 23:42:22 +02:00
7 changed files with 244 additions and 181 deletions
+18 -64
View File
@@ -3,7 +3,6 @@ on:
pull_request: pull_request:
push: push:
branches-ignore: branches-ignore:
- master
- v1 - v1
tags-ignore: tags-ignore:
- '*' - '*'
@@ -14,27 +13,32 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ] os: [ ubuntu, macos, windows ]
# Use various version syntaxes 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, 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, jruby-9.1, jruby, jruby-head, truffleruby, truffleruby-head ]
include:
- { os: ubuntu, ruby: rubinius }
- { os: windows, ruby: mingw }
- { os: windows, ruby: mswin }
exclude: exclude:
- os: windows-latest - { os: windows, ruby: truffleruby }
ruby: truffleruby - { os: windows, ruby: truffleruby-head }
- os: windows-latest
ruby: truffleruby-head
name: ${{ matrix.os }} ${{ matrix.ruby }} name: ${{ matrix.os }} ${{ matrix.ruby }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: ./ - uses: ./
with: with:
ruby-version: ${{ matrix.ruby }} ruby-version: ${{ matrix.ruby }}
- run: ruby -v - run: ruby -v
- name: build compiler - name: build compiler
run: | run: |
ruby -e "puts 'build compiler: ' + RbConfig::CONFIG.fetch('CC_VERSION_MESSAGE', 'unknown').lines.first" ruby -e "puts 'build compiler: ' + RbConfig::CONFIG.fetch('CC_VERSION_MESSAGE', 'unknown').lines.first"
- name: gcc and ridk version (mingw) - name: gcc and ridk version (mingw)
if: startsWith(matrix.os, 'windows') if: matrix.os == 'windows'
run: | run: |
$abi, $plat = $(ruby -e "STDOUT.write RbConfig::CONFIG['ruby_version'] + ' ' + RUBY_PLATFORM").split(' ') $abi, $plat = $(ruby -e "STDOUT.write RbConfig::CONFIG['ruby_version'] + ' ' + RUBY_PLATFORM").split(' ')
if ($plat.Contains('mingw')) { if ($plat.Contains('mingw')) {
@@ -45,22 +49,25 @@ jobs:
echo 'ridk is unavailable' echo 'ridk is unavailable'
} }
} }
- name: Subprocess test - name: Subprocess test
run: ruby test_subprocess.rb run: ruby test_subprocess.rb
- name: OpenSSL version - name: OpenSSL version
run: ruby -ropenssl -e 'puts OpenSSL::OPENSSL_LIBRARY_VERSION' run: ruby -ropenssl -e 'puts OpenSSL::OPENSSL_LIBRARY_VERSION'
- name: OpenSSL test - name: OpenSSL test
run: ruby -ropen-uri -e 'puts open(%{https://rubygems.org/}) { |f| f.read(1024) }' run: ruby -ropen-uri -e 'puts open(%{https://rubygems.org/}) { |f| f.read(1024) }'
- name: C extension test - name: C extension test
run: gem install json:2.2.0 --no-document run: gem install json:2.2.0 --no-document
- run: bundle --version - run: bundle --version
- run: bundle install - run: bundle install
- run: bundle exec rake --version - run: bundle exec rake --version
- name: which ruby, rake - name: which ruby, rake
if: startsWith(matrix.os, 'windows') == false if: matrix.os != 'windows'
run: which -a ruby rake run: which -a ruby rake
- name: where ruby, rake - name: where ruby, rake
if: startsWith(matrix.os, 'windows') if: matrix.os == 'windows'
run: | run: |
$ErrorActionPreference = 'Continue' $ErrorActionPreference = 'Continue'
$where = 'ruby', 'rake' $where = 'ruby', 'rake'
@@ -71,59 +78,6 @@ jobs:
echo '' echo ''
} }
specials:
strategy:
fail-fast: false
matrix:
cfg:
- { ruby: rubinius, os: ubuntu-18.04 }
- { ruby: mingw , os: windows-latest }
- { ruby: mswin , os: windows-latest }
name: ${{ matrix.cfg.os }} ${{ matrix.cfg.ruby }}
runs-on: ${{ matrix.cfg.os }}
steps:
- uses: actions/checkout@v2
- uses: ./
with:
ruby-version: ${{ matrix.cfg.ruby }}
- run: ruby -v
- name: build compiler
run: |
ruby -e "puts 'build compiler: ' + RbConfig::CONFIG.fetch('CC_VERSION_MESSAGE', 'unknown').lines.first"
- name: gcc and ridk version (mingw)
if: startsWith(matrix.os, 'windows')
run: |
$abi, $plat = $(ruby -e "STDOUT.write RbConfig::CONFIG['ruby_version'] + ' ' + RUBY_PLATFORM").split(' ')
if ($plat.Contains('mingw')) {
gcc --version
if ($abi -ge '2.4') {
ridk version
} else {
echo 'ridk is unavailable'
}
}
- name: Subprocess test
run: ruby test_subprocess.rb
- name: OpenSSL version
run: ruby -ropenssl -e 'puts OpenSSL::OPENSSL_LIBRARY_VERSION'
- name: OpenSSL test
run: ruby -ropen-uri -e 'puts open(%{https://rubygems.org/}) { |f| f.read(1024) }'
- name: C extension test
run: gem install json:2.2.0 --no-document
- run: bundle --version
- run: bundle install
- run: bundle exec rake --version
- name: where ruby, rake
if: startsWith(matrix.cfg.os, 'windows')
run: |
$ErrorActionPreference = 'Continue'
$where = 'ruby', 'rake'
foreach ($e in $where) {
$rslt = where.exe $e 2>&1 | Out-String
if ($rslt.contains($e)) { echo $rslt.Trim() }
else { echo "Can't find $e" }
echo ''
}
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
+12 -5
View File
@@ -146,15 +146,22 @@ It is recommended to first get your build working on Ubuntu and macOS before try
* For Ruby < 2.4, the DevKit MSYS tools are installed and prepended to the `Path`. * For Ruby < 2.4, the DevKit MSYS tools are installed and prepended to the `Path`.
* JRuby on Windows has a known bug that `bundle exec rake` [fails](https://github.com/ruby/setup-ruby/issues/18). * JRuby on Windows has a known bug that `bundle exec rake` [fails](https://github.com/ruby/setup-ruby/issues/18).
## Limitations
* This action currently only works with GitHub-hosted runners, not private runners.
## Versioning ## Versioning
It is highly recommended to use `ruby/setup-ruby@v1` for the version of this action.
This will provide the best experience by automatically getting bug fixes, new Ruby versions and new features.
If you instead choose a specific version (v1.2.3) or a commit sha, there will be no automatic bug fixes and
it will be your responsibility to update every time the action no longer works.
Make sure to always use the latest release before reporting an issue on GitHub.
This action follows semantic versioning with a moving `v1` branch. This action follows semantic versioning with a moving `v1` branch.
This follows the [recommendations](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) of GitHub Actions. This follows the [recommendations](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) of GitHub Actions.
## Limitations
* This action currently only works with GitHub-hosted runners, not private runners.
## History ## History
This action used to be at `eregon/use-ruby-action` and was moved to the `ruby` organization. This action used to be at `eregon/use-ruby-action` and was moved to the `ruby` organization.
@@ -163,5 +170,5 @@ Please [update](https://github.com/ruby/setup-ruby/releases/tag/v1.13.0) if you
## Credits ## Credits
The current maintainer of this action is @eregon. The current maintainer of this action is @eregon.
Most of the Windows logic is from https://github.com/MSP-Greg/actions-ruby by MSP-Greg. Most of the Windows logic is based on work by MSP-Greg.
Many thanks to MSP-Greg and Lars Kanis for the help with Ruby Installer. Many thanks to MSP-Greg and Lars Kanis for the help with Ruby Installer.
+40
View File
@@ -0,0 +1,40 @@
const os = require('os')
const fs = require('fs')
const core = require('@actions/core')
const { performance } = require('perf_hooks')
export async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
try {
return await block()
} finally {
const end = performance.now()
const duration = (end - start) / 1000.0
console.log(`Took ${duration.toFixed(2).padStart(6)} seconds`)
}
})
}
export function getVirtualEnvironmentName() {
const platform = os.platform()
if (platform === 'linux') {
return `ubuntu-${findUbuntuVersion()}`
} else if (platform === 'darwin') {
return 'macos-latest'
} else if (platform === 'win32') {
return 'windows-latest'
} else {
throw new Error(`Unknown platform ${platform}`)
}
}
function findUbuntuVersion() {
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
if (match) {
return match[1]
} else {
throw new Error('Could not find Ubuntu version')
}
}
Generated Vendored
+116 -56
View File
@@ -961,10 +961,11 @@ const fs = __webpack_require__(747)
const path = __webpack_require__(622) const path = __webpack_require__(622)
const core = __webpack_require__(470) const core = __webpack_require__(470)
const exec = __webpack_require__(986) const exec = __webpack_require__(986)
const common = __webpack_require__(239)
async function run() { async function run() {
try { try {
const platform = getVirtualEnvironmentName() const platform = common.getVirtualEnvironmentName()
const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version')) const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
let installer let installer
@@ -983,7 +984,10 @@ async function run() {
setupPath(ruby, newPathEntries) setupPath(ruby, newPathEntries)
await installBundler(platform, rubyPrefix, engine, version) if (core.getInput('bundler') !== 'none') {
await common.measure('Installing Bundler', async () =>
installBundler(platform, rubyPrefix, engine, version))
}
core.setOutput('ruby-prefix', rubyPrefix) core.setOutput('ruby-prefix', rubyPrefix)
} catch (error) { } catch (error) {
@@ -1054,19 +1058,21 @@ function createGemRC() {
} }
function setupPath(ruby, newPathEntries) { function setupPath(ruby, newPathEntries) {
const originalPath = process.env['PATH'].split(path.delimiter) const originalPath = process.env['PATH'].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry)) let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
if (cleanPath.length !== originalPath.length) { if (cleanPath.length !== originalPath.length) {
console.log("Entries removed from PATH to avoid conflicts with Ruby:") core.startGroup('Cleaning PATH')
for (const entry of originalPath) { console.log('Entries removed from PATH to avoid conflicts with Ruby:')
if (!cleanPath.includes(entry)) { for (const entry of originalPath) {
console.log(` ${entry}`) if (!cleanPath.includes(entry)) {
} console.log(` ${entry}`)
} }
} }
core.endGroup()
}
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter)) core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
} }
function readBundledWithFromGemfileLock() { function readBundledWithFromGemfileLock() {
@@ -1089,9 +1095,6 @@ function readBundledWithFromGemfileLock() {
async function installBundler(platform, rubyPrefix, engine, rubyVersion) { async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler') var bundlerVersion = core.getInput('bundler')
if (bundlerVersion === 'none') {
return
}
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock() bundlerVersion = readBundledWithFromGemfileLock()
@@ -1100,48 +1103,33 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
} }
} }
let versionArray if (bundlerVersion === 'latest') {
bundlerVersion = '2'
}
if (rubyVersion.startsWith('2.2')) { if (rubyVersion.startsWith('2.2')) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2') console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
versionArray = ['-v', '~> 1'] bundlerVersion = '1'
} else if (/^\d+/.test(bundlerVersion)) { } else if (/^\d+/.test(bundlerVersion)) {
versionArray = ['-v', `~> ${bundlerVersion}`] // OK
} else if (bundlerVersion === 'latest') {
versionArray = []
} else { } else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`) throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
} }
if (engine === 'rubinius') { if (engine === 'ruby' && isHeadVersion(rubyVersion) && bundlerVersion === '2') {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
} else if (engine === 'truffleruby' && bundlerVersion === '1') {
console.log(`Using Bundler 1 shipped with ${engine}`)
} else if (engine === 'rubinius') {
console.log(`Rubinius only supports the version of Bundler shipped with it`) console.log(`Rubinius only supports the version of Bundler shipped with it`)
} else if (bundlerVersion === '1' && engine === 'truffleruby') {
console.log(`Using the Bundler version shipped with ${engine}`)
} else { } else {
await exec.exec(path.join(rubyPrefix, 'bin', 'gem'), ['install', 'bundler', ...versionArray, '--no-document']) const gem = path.join(rubyPrefix, 'bin', 'gem')
await exec.exec(gem, ['install', 'bundler', '-v', `~> ${bundlerVersion}`, '--no-document'])
} }
} }
function getVirtualEnvironmentName() { function isHeadVersion(rubyVersion) {
const platform = os.platform() return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
if (platform === 'linux') {
return `ubuntu-${findUbuntuVersion()}`
} else if (platform === 'darwin') {
return 'macos-latest'
} else if (platform === 'win32') {
return 'windows-latest'
} else {
throw new Error(`Unknown platform ${platform}`)
}
}
function findUbuntuVersion() {
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
if (match) {
return match[1]
} else {
throw new Error('Could not find Ubuntu version')
}
} }
if (__filename.endsWith('index.js')) { run() } if (__filename.endsWith('index.js')) { run() }
@@ -1489,6 +1477,57 @@ function getVersions(platform) {
module.exports = require("https"); module.exports = require("https");
/***/ }),
/***/ 239:
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "measure", function() { return measure; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVirtualEnvironmentName", function() { return getVirtualEnvironmentName; });
const os = __webpack_require__(87)
const fs = __webpack_require__(747)
const core = __webpack_require__(470)
const { performance } = __webpack_require__(630)
async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
try {
return await block()
} finally {
const end = performance.now()
const duration = (end - start) / 1000.0
console.log(`Took ${duration.toFixed(2).padStart(6)} seconds`)
}
})
}
function getVirtualEnvironmentName() {
const platform = os.platform()
if (platform === 'linux') {
return `ubuntu-${findUbuntuVersion()}`
} else if (platform === 'darwin') {
return 'macos-latest'
} else if (platform === 'win32') {
return 'windows-latest'
} else {
throw new Error(`Unknown platform ${platform}`)
}
}
function findUbuntuVersion() {
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
if (match) {
return match[1]
} else {
throw new Error('Could not find Ubuntu version')
}
}
/***/ }), /***/ }),
/***/ 280: /***/ 280:
@@ -3473,6 +3512,7 @@ const path = __webpack_require__(622)
const exec = __webpack_require__(986) const exec = __webpack_require__(986)
const io = __webpack_require__(1) const io = __webpack_require__(1)
const tc = __webpack_require__(533) const tc = __webpack_require__(533)
const common = __webpack_require__(239)
const rubyBuilderVersions = __webpack_require__(156) const rubyBuilderVersions = __webpack_require__(156)
const builderReleaseTag = 'enable-shared' const builderReleaseTag = 'enable-shared'
@@ -3497,12 +3537,15 @@ async function downloadAndExtract(platform, ruby) {
const rubiesDir = path.join(os.homedir(), '.rubies') const rubiesDir = path.join(os.homedir(), '.rubies')
await io.mkdirP(rubiesDir) await io.mkdirP(rubiesDir)
const url = await getDownloadURL(platform, ruby) const downloadPath = await common.measure('Downloading Ruby', async () => {
console.log(url) const url = getDownloadURL(platform, ruby)
console.log(url)
return await tc.downloadTool(url)
})
const downloadPath = await tc.downloadTool(url)
const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar' const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar'
await exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ]) await common.measure('Extracting Ruby', async () =>
exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ]))
return path.join(rubiesDir, ruby) return path.join(rubiesDir, ruby)
} }
@@ -4595,6 +4638,13 @@ module.exports = require("path");
/***/ }), /***/ }),
/***/ 630:
/***/ (function(module) {
module.exports = require("perf_hooks");
/***/ }),
/***/ 631: /***/ 631:
/***/ (function(module) { /***/ (function(module) {
@@ -4875,6 +4925,7 @@ const cp = __webpack_require__(129)
const core = __webpack_require__(470) const core = __webpack_require__(470)
const exec = __webpack_require__(986) const exec = __webpack_require__(986)
const tc = __webpack_require__(533) const tc = __webpack_require__(533)
const common = __webpack_require__(239)
const rubyInstallerVersions = __webpack_require__(471).versions const rubyInstallerVersions = __webpack_require__(471).versions
// Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14 // Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14
@@ -4903,15 +4954,19 @@ function getAvailableVersions(platform, engine) {
async function install(platform, ruby) { async function install(platform, ruby) {
const version = ruby.split('-', 2)[1] const version = ruby.split('-', 2)[1]
const url = rubyInstallerVersions[version] const url = rubyInstallerVersions[version]
console.log(url)
if (!url.endsWith('.7z')) { if (!url.endsWith('.7z')) {
throw new Error('URL should end in .7z') throw new Error(`URL should end in .7z: ${url}`)
} }
const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length) const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length)
const downloadPath = await tc.downloadTool(url) const downloadPath = await common.measure('Downloading Ruby', async () => {
await exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }) console.log(url)
return await tc.downloadTool(url)
})
await common.measure('Extracting Ruby', async () =>
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }))
const rubyPrefix = `${drive}:\\${base}` const rubyPrefix = `${drive}:\\${base}`
let toolchainPaths = (version === 'mswin') ? let toolchainPaths = (version === 'mswin') ?
@@ -4930,7 +4985,8 @@ async function symLinkToEmbeddedMSYS2() {
} }
const latestVersion = toolCacheVersions.slice(-1)[0] const latestVersion = toolCacheVersions.slice(-1)[0]
const hostedRuby = tc.find('Ruby', latestVersion) const hostedRuby = tc.find('Ruby', latestVersion)
await exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`) await common.measure('Linking MSYS2', async () =>
exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`))
} }
async function setupMingw(version) { async function setupMingw(version) {
@@ -4938,7 +4994,8 @@ async function setupMingw(version) {
if (version.startsWith('2.2') || version.startsWith('2.3')) { if (version.startsWith('2.2') || version.startsWith('2.3')) {
core.exportVariable('SSL_CERT_FILE', certFile) core.exportVariable('SSL_CERT_FILE', certFile)
await installMSYS(version) await common.measure('Installing MSYS1', async () =>
installMSYS(version))
return msysPathEntries return msysPathEntries
} else { } else {
@@ -4985,7 +5042,10 @@ async function setupMSWin() {
await symLinkToEmbeddedMSYS2() await symLinkToEmbeddedMSYS2()
} }
return [...addVCVARSEnv(), ...msys2PathEntries] const VCPathEntries = await common.measure('Setting up MSVC environment', async () =>
addVCVARSEnv())
return [...VCPathEntries, ...msys2PathEntries]
} }
/* Sets MSVC environment for use in Actions /* Sets MSVC environment for use in Actions
+33 -45
View File
@@ -3,10 +3,11 @@ const fs = require('fs')
const path = require('path') const path = require('path')
const core = require('@actions/core') const core = require('@actions/core')
const exec = require('@actions/exec') const exec = require('@actions/exec')
const common = require('./common')
export async function run() { export async function run() {
try { try {
const platform = getVirtualEnvironmentName() const platform = common.getVirtualEnvironmentName()
const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version')) const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
let installer let installer
@@ -25,7 +26,10 @@ export async function run() {
setupPath(ruby, newPathEntries) setupPath(ruby, newPathEntries)
await installBundler(platform, rubyPrefix, engine, version) if (core.getInput('bundler') !== 'none') {
await common.measure('Installing Bundler', async () =>
installBundler(platform, rubyPrefix, engine, version))
}
core.setOutput('ruby-prefix', rubyPrefix) core.setOutput('ruby-prefix', rubyPrefix)
} catch (error) { } catch (error) {
@@ -96,19 +100,21 @@ function createGemRC() {
} }
function setupPath(ruby, newPathEntries) { function setupPath(ruby, newPathEntries) {
const originalPath = process.env['PATH'].split(path.delimiter) const originalPath = process.env['PATH'].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry)) let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
if (cleanPath.length !== originalPath.length) { if (cleanPath.length !== originalPath.length) {
console.log("Entries removed from PATH to avoid conflicts with Ruby:") core.startGroup('Cleaning PATH')
for (const entry of originalPath) { console.log('Entries removed from PATH to avoid conflicts with Ruby:')
if (!cleanPath.includes(entry)) { for (const entry of originalPath) {
console.log(` ${entry}`) if (!cleanPath.includes(entry)) {
} console.log(` ${entry}`)
} }
} }
core.endGroup()
}
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter)) core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
} }
function readBundledWithFromGemfileLock() { function readBundledWithFromGemfileLock() {
@@ -131,9 +137,6 @@ function readBundledWithFromGemfileLock() {
async function installBundler(platform, rubyPrefix, engine, rubyVersion) { async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
var bundlerVersion = core.getInput('bundler') var bundlerVersion = core.getInput('bundler')
if (bundlerVersion === 'none') {
return
}
if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') {
bundlerVersion = readBundledWithFromGemfileLock() bundlerVersion = readBundledWithFromGemfileLock()
@@ -142,48 +145,33 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
} }
} }
let versionArray if (bundlerVersion === 'latest') {
bundlerVersion = '2'
}
if (rubyVersion.startsWith('2.2')) { if (rubyVersion.startsWith('2.2')) {
console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2') console.log('Bundler 2 requires Ruby 2.3+, using Bundler 1 on Ruby 2.2')
versionArray = ['-v', '~> 1'] bundlerVersion = '1'
} else if (/^\d+/.test(bundlerVersion)) { } else if (/^\d+/.test(bundlerVersion)) {
versionArray = ['-v', `~> ${bundlerVersion}`] // OK
} else if (bundlerVersion === 'latest') {
versionArray = []
} else { } else {
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`) throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
} }
if (engine === 'rubinius') { if (engine === 'ruby' && isHeadVersion(rubyVersion) && bundlerVersion === '2') {
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
} else if (engine === 'truffleruby' && bundlerVersion === '1') {
console.log(`Using Bundler 1 shipped with ${engine}`)
} else if (engine === 'rubinius') {
console.log(`Rubinius only supports the version of Bundler shipped with it`) console.log(`Rubinius only supports the version of Bundler shipped with it`)
} else if (bundlerVersion === '1' && engine === 'truffleruby') {
console.log(`Using the Bundler version shipped with ${engine}`)
} else { } else {
await exec.exec(path.join(rubyPrefix, 'bin', 'gem'), ['install', 'bundler', ...versionArray, '--no-document']) const gem = path.join(rubyPrefix, 'bin', 'gem')
await exec.exec(gem, ['install', 'bundler', '-v', `~> ${bundlerVersion}`, '--no-document'])
} }
} }
function getVirtualEnvironmentName() { function isHeadVersion(rubyVersion) {
const platform = os.platform() return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
if (platform === 'linux') {
return `ubuntu-${findUbuntuVersion()}`
} else if (platform === 'darwin') {
return 'macos-latest'
} else if (platform === 'win32') {
return 'windows-latest'
} else {
throw new Error(`Unknown platform ${platform}`)
}
}
function findUbuntuVersion() {
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
if (match) {
return match[1]
} else {
throw new Error('Could not find Ubuntu version')
}
} }
if (__filename.endsWith('index.js')) { run() } if (__filename.endsWith('index.js')) { run() }
+8 -4
View File
@@ -3,6 +3,7 @@ const path = require('path')
const exec = require('@actions/exec') const exec = require('@actions/exec')
const io = require('@actions/io') const io = require('@actions/io')
const tc = require('@actions/tool-cache') const tc = require('@actions/tool-cache')
const common = require('./common')
const rubyBuilderVersions = require('./ruby-builder-versions') const rubyBuilderVersions = require('./ruby-builder-versions')
const builderReleaseTag = 'enable-shared' const builderReleaseTag = 'enable-shared'
@@ -27,12 +28,15 @@ async function downloadAndExtract(platform, ruby) {
const rubiesDir = path.join(os.homedir(), '.rubies') const rubiesDir = path.join(os.homedir(), '.rubies')
await io.mkdirP(rubiesDir) await io.mkdirP(rubiesDir)
const url = await getDownloadURL(platform, ruby) const downloadPath = await common.measure('Downloading Ruby', async () => {
console.log(url) const url = getDownloadURL(platform, ruby)
console.log(url)
return await tc.downloadTool(url)
})
const downloadPath = await tc.downloadTool(url)
const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar' const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar'
await exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ]) await common.measure('Extracting Ruby', async () =>
exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ]))
return path.join(rubiesDir, ruby) return path.join(rubiesDir, ruby)
} }
+17 -7
View File
@@ -7,6 +7,7 @@ const cp = require('child_process')
const core = require('@actions/core') const core = require('@actions/core')
const exec = require('@actions/exec') const exec = require('@actions/exec')
const tc = require('@actions/tool-cache') const tc = require('@actions/tool-cache')
const common = require('./common')
const rubyInstallerVersions = require('./windows-versions').versions const rubyInstallerVersions = require('./windows-versions').versions
// Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14 // Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14
@@ -35,15 +36,19 @@ export function getAvailableVersions(platform, engine) {
export async function install(platform, ruby) { export async function install(platform, ruby) {
const version = ruby.split('-', 2)[1] const version = ruby.split('-', 2)[1]
const url = rubyInstallerVersions[version] const url = rubyInstallerVersions[version]
console.log(url)
if (!url.endsWith('.7z')) { if (!url.endsWith('.7z')) {
throw new Error('URL should end in .7z') throw new Error(`URL should end in .7z: ${url}`)
} }
const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length) const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length)
const downloadPath = await tc.downloadTool(url) const downloadPath = await common.measure('Downloading Ruby', async () => {
await exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }) console.log(url)
return await tc.downloadTool(url)
})
await common.measure('Extracting Ruby', async () =>
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true }))
const rubyPrefix = `${drive}:\\${base}` const rubyPrefix = `${drive}:\\${base}`
let toolchainPaths = (version === 'mswin') ? let toolchainPaths = (version === 'mswin') ?
@@ -62,7 +67,8 @@ async function symLinkToEmbeddedMSYS2() {
} }
const latestVersion = toolCacheVersions.slice(-1)[0] const latestVersion = toolCacheVersions.slice(-1)[0]
const hostedRuby = tc.find('Ruby', latestVersion) const hostedRuby = tc.find('Ruby', latestVersion)
await exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`) await common.measure('Linking MSYS2', async () =>
exec.exec(`cmd /c mklink /D ${msys2} ${hostedRuby}\\msys64`))
} }
async function setupMingw(version) { async function setupMingw(version) {
@@ -70,7 +76,8 @@ async function setupMingw(version) {
if (version.startsWith('2.2') || version.startsWith('2.3')) { if (version.startsWith('2.2') || version.startsWith('2.3')) {
core.exportVariable('SSL_CERT_FILE', certFile) core.exportVariable('SSL_CERT_FILE', certFile)
await installMSYS(version) await common.measure('Installing MSYS1', async () =>
installMSYS(version))
return msysPathEntries return msysPathEntries
} else { } else {
@@ -117,7 +124,10 @@ async function setupMSWin() {
await symLinkToEmbeddedMSYS2() await symLinkToEmbeddedMSYS2()
} }
return [...addVCVARSEnv(), ...msys2PathEntries] const VCPathEntries = await common.measure('Setting up MSVC environment', async () =>
addVCVARSEnv())
return [...VCPathEntries, ...msys2PathEntries]
} }
/* Sets MSVC environment for use in Actions /* Sets MSVC environment for use in Actions