Skip to content

Commit 182b754

Browse files
committed
use js
1 parent f489aea commit 182b754

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- run: echo '{}' > deno.json
12+
- uses: ./
13+
- run: echo $PATH
14+
- run: env
15+
- run: deno --version

action.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ runs:
1515
if [ -n "${{ inputs.path }}" ]; then
1616
cd "${{ inputs.path }}"
1717
fi
18-
19-
for ln in $(pkgx --internal.activate "$PWD"); do
20-
case "$ln" in
21-
PATH=*)
22-
echo "$ln" | sed -e's/^PATH=//' | tr : \\n >> $GITHUB_PATH;;
23-
*=*)
24-
echo "$ln" >> $GITHUB_ENV;;
25-
esac
26-
done
18+
pkgx --internal.activate "$PWD" > file
19+
node parse.js
2720
shell: bash

parse.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require('fs');
2+
const readline = require('readline');
3+
4+
const readInterface = readline.createInterface({
5+
input: fs.createReadStream('file'),
6+
output: process.stdout,
7+
terminal: false
8+
});
9+
10+
const stripQuotes = (str) => str.startsWith('"') || str.startsWith("'") ? str.slice(1, -1) : str;
11+
12+
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+
});
17+
};
18+
19+
readInterface.on('line', (line) => {
20+
const match = line.match(/^export ([^=]+)=(.*)$/);
21+
if (match) {
22+
const [_, key, value_] = match;
23+
const value = stripQuotes(value_);
24+
if (key === 'PATH') {
25+
value.split(':').forEach((path) => {
26+
if (!path.startsWith("$")) {
27+
fs.appendFileSync(process.env['GITHUB_PATH'], `${path}\n`);
28+
}
29+
});
30+
} else {
31+
let v = replaceEnvVars(value);
32+
fs.appendFileSync(process.env['GITHUB_ENV'], `${key}=${v}\n`);
33+
}
34+
}
35+
});

0 commit comments

Comments
 (0)