Skip to content

Commit 6ead459

Browse files
MSP-Gregeregon
authored andcommitted
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
1 parent 45ec312 commit 6ead459

File tree

5 files changed

+159
-92
lines changed

5 files changed

+159
-92
lines changed

common.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const os = require('os')
2+
const path = require('path')
23
const fs = require('fs')
34
const util = require('util')
45
const stream = require('stream')
56
const crypto = require('crypto')
67
const core = require('@actions/core')
78
const { performance } = require('perf_hooks')
89

10+
const isWin = (os.platform() === 'win32')
11+
912
export async function measure(name, block) {
1013
return await core.group(name, async () => {
1114
const start = performance.now()
@@ -62,3 +65,30 @@ export function win2nix(path) {
6265
}
6366
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
6467
}
68+
69+
export function setupPath(newPathEntries) {
70+
const envPath = isWin ? 'Path' : 'PATH'
71+
const originalPath = process.env[envPath].split(path.delimiter)
72+
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
73+
74+
if (cleanPath.length !== originalPath.length) {
75+
core.startGroup(`Cleaning ${envPath}`)
76+
console.log(`Entries removed from ${envPath} to avoid conflicts with Ruby:`)
77+
for (const entry of originalPath) {
78+
if (!cleanPath.includes(entry)) {
79+
console.log(` ${entry}`)
80+
}
81+
}
82+
core.exportVariable(envPath, cleanPath.join(path.delimiter))
83+
core.endGroup()
84+
}
85+
let newPath
86+
if (isWin) {
87+
// add MSYS2 path to all for bash shell
88+
const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin']
89+
newPath = [...newPathEntries, ...msys2]
90+
} else {
91+
newPath = newPathEntries
92+
}
93+
core.addPath(newPath.join(path.delimiter))
94+
}

dist/index.js

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

index.js

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

9+
const isWin = (os.platform() === 'win32')
10+
911
const inputDefaults = {
1012
'ruby-version': 'default',
1113
'bundler': 'default',
@@ -26,7 +28,7 @@ export async function run() {
2628
export async function setupRuby(options = {}) {
2729
const inputs = { ...options }
2830
for (const key in inputDefaults) {
29-
if (!inputs.hasOwnProperty(key)) {
31+
if (!Object.prototype.hasOwnProperty.call(inputs, key)) {
3032
inputs[key] = core.getInput(key) || inputDefaults[key]
3133
}
3234
}
@@ -48,9 +50,10 @@ export async function setupRuby(options = {}) {
4850

4951
createGemRC()
5052

51-
const [rubyPrefix, newPathEntries] = await installer.install(platform, engine, version)
53+
envPreInstall()
54+
55+
const rubyPrefix = await installer.install(platform, engine, version)
5256

53-
setupPath(newPathEntries)
5457

5558
// When setup-ruby is used by other actions, this allows code in them to run
5659
// before 'bundle install'. Installed dependencies may require additional
@@ -135,22 +138,18 @@ function createGemRC() {
135138
}
136139
}
137140

138-
function setupPath(newPathEntries) {
139-
const originalPath = process.env['PATH'].split(path.delimiter)
140-
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
141-
142-
if (cleanPath.length !== originalPath.length) {
143-
core.startGroup('Cleaning PATH')
144-
console.log('Entries removed from PATH to avoid conflicts with Ruby:')
145-
for (const entry of originalPath) {
146-
if (!cleanPath.includes(entry)) {
147-
console.log(` ${entry}`)
148-
}
149-
}
150-
core.endGroup()
141+
// sets up ENV variables
142+
// currrently only used on Windows runners
143+
function envPreInstall() {
144+
const ENV = process.env
145+
if (isWin) {
146+
// puts normal Ruby temp folder on SSD
147+
core.exportVariable('TMPDIR', ENV['RUNNER_TEMP'])
148+
// bash - sets home to match native windows, normally C:\Users\<user name>
149+
core.exportVariable('HOME', ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
150+
// bash - needed to maintain Path from Windows
151+
core.exportVariable('MSYS2_PATH_TYPE', 'inherit')
151152
}
152-
153-
core.exportVariable('PATH', [...newPathEntries, ...cleanPath].join(path.delimiter))
154153
}
155154

156155
function readBundledWithFromGemfileLock(path) {

0 commit comments

Comments
 (0)