Skip to content

Commit 5cc0705

Browse files
authored
Fix this action since pkgx 1.1 (#3)
1 parent 60cbecc commit 5cc0705

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ on:
22
push:
33
branches:
44
- main
5+
pull_request:
56

67
jobs:
78
test:

action.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ inputs:
99
runs:
1010
using: composite
1111
steps:
12-
- uses: pkgxdev/setup@v1
12+
- uses: pkgxdev/setup@v2
1313

1414
- run: |
15-
if [ -n "${{ inputs.path }}" ]; then
16-
cd "${{ inputs.path }}"
17-
fi
18-
pkgx --internal.activate "$PWD" > file
19-
if ! command -v node >/dev/null 2>&1; then
15+
TMP="$(mktemp)"
16+
pkgx --internal.activate "$PWD" > "$TMP"
17+
echo "file=$TMP" >> $GITHUB_OUTPUT
18+
id: env
19+
working-directory: ${{ inputs.path }}
20+
shell: bash
21+
22+
- run: |
23+
if ! node --version >/dev/null 2>&1; then
2024
eval "$(pkgx +node)"
2125
fi
22-
node $GITHUB_ACTION_PATH/parse.js
26+
node "$GITHUB_ACTION_PATH"/parse.js ${{ steps.env.outputs.file }}
2327
shell: bash

parse.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ const fs = require('fs');
22
const readline = require('readline');
33

44
const readInterface = readline.createInterface({
5-
input: fs.createReadStream('file'),
5+
input: fs.createReadStream(process.argv[2]),
66
output: process.stdout,
77
terminal: false
88
});
99

1010
const stripQuotes = (str) => str.startsWith('"') || str.startsWith("'") ? str.slice(1, -1) : str;
1111

1212
const replaceEnvVars = (str) => {
13-
return str.replace(/(:?)\$\{([^}]+)\}/g, (match, precedingColon, varName) => {
14-
const envValue = process.env[varName];
15-
return envValue ? `${precedingColon}${envValue}` : (precedingColon ? '' : envValue);
16-
});
13+
const value = str
14+
.replaceAll(/\$\{([a-zA-Z0-9_]+):\+:\$[a-zA-Z0-9_]+\}/g, (_, key) => (v => v ? `:${v}` : '')(process.env[key]))
15+
.replaceAll(/\$\{([a-zA-Z0-9_]+)\}/g, (_, key) => process.env[key] ?? '')
16+
.replaceAll(/\$([a-zA-Z0-9_]+)/g, (_, key) => process.env[key] ?? '')
17+
console.error("FOO", str, value)
18+
return value
1719
};
1820

1921
readInterface.on('line', (line) => {
@@ -22,10 +24,12 @@ readInterface.on('line', (line) => {
2224
const [_, key, value_] = match;
2325
const value = stripQuotes(value_);
2426
if (key === 'PATH') {
25-
value.split(':').forEach((path) => {
26-
if (!path.startsWith("$")) {
27-
fs.appendFileSync(process.env['GITHUB_PATH'], `${path}\n`);
28-
}
27+
value
28+
.replaceAll('${PATH:+:$PATH}', '')
29+
.replaceAll('$PATH', '')
30+
.replaceAll('${PATH}', '')
31+
.split(':').forEach(path => {
32+
fs.appendFileSync(process.env['GITHUB_PATH'], `${path}\n`);
2933
});
3034
} else {
3135
let v = replaceEnvVars(value);

0 commit comments

Comments
 (0)