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
This commit is contained in:
MSP-Greg
2020-09-03 12:13:49 +02:00
committed by Benoit Daloze
parent 45ec312a6e
commit 6ead459c74
5 changed files with 159 additions and 92 deletions
+30
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,8 @@ const crypto = require('crypto')
const core = require('@actions/core')
const { performance } = require('perf_hooks')
const isWin = (os.platform() === 'win32')
export async function measure(name, block) {
return await core.group(name, async () => {
const start = performance.now()
@@ -62,3 +65,30 @@ export function win2nix(path) {
}
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
}
export function setupPath(newPathEntries) {
const envPath = isWin ? 'Path' : 'PATH'
const originalPath = process.env[envPath].split(path.delimiter)
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
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()
}
let newPath
if (isWin) {
// add MSYS2 path to all for bash shell
const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin']
newPath = [...newPathEntries, ...msys2]
} else {
newPath = newPathEntries
}
core.addPath(newPath.join(path.delimiter))
}