Skip to content

Commit 108b3a2

Browse files
committed
Various cleanups
1 parent 25ccf0a commit 108b3a2

File tree

5 files changed

+58
-64
lines changed

5 files changed

+58
-64
lines changed

common.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const crypto = require('crypto')
77
const core = require('@actions/core')
88
const { performance } = require('perf_hooks')
99

10-
const isWin = (os.platform() === 'win32')
10+
export const windows = (os.platform() === 'win32')
11+
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
12+
export const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined)
1113

1214
export async function measure(name, block) {
1315
return await core.group(name, async () => {
@@ -58,7 +60,7 @@ function findUbuntuVersion() {
5860
}
5961

6062
// convert windows path like C:\Users\runneradmin to /c/Users/runneradmin
61-
export function win2nix(path) {
63+
export function win2nix(path) {
6264
if (/^[A-Z]:/i.test(path)) {
6365
// path starts with drive
6466
path = `/${path[0].toLowerCase()}${path.split(':', 2)[1]}`
@@ -67,10 +69,11 @@ export function win2nix(path) {
6769
}
6870

6971
export function setupPath(newPathEntries) {
70-
const envPath = isWin ? 'Path' : 'PATH'
72+
const envPath = windows ? 'Path' : 'PATH'
7173
const originalPath = process.env[envPath].split(path.delimiter)
7274
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
7375

76+
// First remove the conflicting path entries
7477
if (cleanPath.length !== originalPath.length) {
7578
core.startGroup(`Cleaning ${envPath}`)
7679
console.log(`Entries removed from ${envPath} to avoid conflicts with Ruby:`)
@@ -82,9 +85,11 @@ export function setupPath(newPathEntries) {
8285
core.exportVariable(envPath, cleanPath.join(path.delimiter))
8386
core.endGroup()
8487
}
88+
89+
// Then add new path entries using core.addPath()
8590
let newPath
86-
if (isWin) {
87-
// add MSYS2 path to all for bash shell
91+
if (windows) {
92+
// add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain
8893
const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin']
8994
newPath = [...newPathEntries, ...msys2]
9095
} else {

dist/index.js

Lines changed: 30 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const exec = require('@actions/exec')
66
const cache = require('@actions/cache')
77
const common = require('./common')
88

9-
const isWin = (os.platform() === 'win32')
9+
const windows = common.windows
1010

1111
const inputDefaults = {
1212
'ruby-version': 'default',
@@ -49,12 +49,10 @@ export async function setupRuby(options = {}) {
4949
const version = validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVersion)
5050

5151
createGemRC()
52-
5352
envPreInstall()
5453

5554
const rubyPrefix = await installer.install(platform, engine, version)
5655

57-
5856
// When setup-ruby is used by other actions, this allows code in them to run
5957
// before 'bundle install'. Installed dependencies may require additional
6058
// libraries & headers, build tools, etc.
@@ -139,10 +137,10 @@ function createGemRC() {
139137
}
140138

141139
// sets up ENV variables
142-
// currrently only used on Windows runners
140+
// currently only used on Windows runners
143141
function envPreInstall() {
144142
const ENV = process.env
145-
if (isWin) {
143+
if (windows) {
146144
// puts normal Ruby temp folder on SSD
147145
core.exportVariable('TMPDIR', ENV['RUNNER_TEMP'])
148146
// bash - sets home to match native windows, normally C:\Users\<user name>

ruby-builder.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,27 @@ const rubyBuilderVersions = require('./ruby-builder-versions')
99
const builderReleaseTag = 'enable-shared'
1010
const releasesURL = 'https://github.com/ruby/ruby-builder/releases'
1111

12-
const isWin = (os.platform() === 'win32')
12+
const windows = common.windows
1313

1414
export function getAvailableVersions(platform, engine) {
1515
return rubyBuilderVersions.getVersions(platform)[engine]
1616
}
1717

1818
export async function install(platform, engine, version) {
19-
const rubyPrefix = await downloadAndExtract(platform, engine, version)
20-
return rubyPrefix
19+
return await downloadAndExtract(platform, engine, version)
2120
}
2221

2322
async function downloadAndExtract(platform, engine, version) {
24-
const rubiesDir = isWin ?
25-
`${(process.env.GITHUB_WORKSPACE || 'C')[0]}:` :
26-
path.join(os.homedir(), '.rubies')
23+
const rubiesDir = windows ? `${common.drive}:` : path.join(os.homedir(), '.rubies')
2724

2825
const rubyPrefix = path.join(rubiesDir, `${engine}-${version}`)
29-
const newPathEntries = (engine === 'rubinius') ?
30-
[path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')] :
31-
[path.join(rubyPrefix, 'bin')]
3226

33-
common.setupPath(newPathEntries)
27+
// Set the PATH now, so the MSYS2 'tar' is in Path on Windows
28+
if (engine === 'rubinius') {
29+
common.setupPath([path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')])
30+
} else {
31+
common.setupPath([path.join(rubyPrefix, 'bin')])
32+
}
3433

3534
await io.mkdirP(rubiesDir)
3635

@@ -41,8 +40,8 @@ async function downloadAndExtract(platform, engine, version) {
4140
})
4241

4342
await common.measure('Extracting Ruby', async () => {
44-
// Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
45-
if (isWin) {
43+
if (windows) {
44+
// Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
4645
await exec.exec('tar', [ '-xz', '-C', common.win2nix(rubiesDir), '-f', common.win2nix(downloadPath) ])
4746
} else {
4847
await exec.exec('tar', [ '-xz', '-C', rubiesDir, '-f', downloadPath ])

windows.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@ const tc = require('@actions/tool-cache')
1010
const common = require('./common')
1111
const rubyInstallerVersions = require('./windows-versions').versions
1212

13-
// Extract to SSD, see https://github.com/ruby/setup-ruby/pull/14
14-
const drive = (process.env['GITHUB_WORKSPACE'] || 'C')[0]
13+
const drive = common.drive
1514

1615
// needed for 2.1, 2.2, 2.3, and mswin, cert file used by Git for Windows
1716
const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem'
1817

1918
// location & path for old RubyInstaller DevKit (MSYS), Ruby 2.1, 2.2 and 2.3
2019
const msys = `${drive}:\\DevKit64`
21-
const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`,
22-
`${msys}\\mingw\\bin`, `${msys}\\bin`]
20+
const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`, `${msys}\\mingw\\bin`, `${msys}\\bin`]
2321

2422
export function getAvailableVersions(platform, engine) {
2523
if (engine === 'ruby') {
@@ -39,8 +37,7 @@ export async function install(platform, engine, version) {
3937

4038
const rubyPrefix = `${drive}:\\${base}`
4139

42-
let toolchainPaths = (version === 'mswin') ?
43-
await setupMSWin() : await setupMingw(version)
40+
let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version)
4441

4542
common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths])
4643

@@ -96,10 +93,7 @@ async function setupMSWin() {
9693
fs.copyFileSync(certFile, cert)
9794
}
9895

99-
const VCPathEntries = await common.measure('Setting up MSVC environment', async () =>
100-
addVCVARSEnv())
101-
102-
return VCPathEntries
96+
return await common.measure('Setting up MSVC environment', async () => addVCVARSEnv())
10397
}
10498

10599
/* Sets MSVC environment for use in Actions

0 commit comments

Comments
 (0)