Skip to content

Commit 37d1273

Browse files
marco-ippolitoRafaelGSS
authored andcommitted
tools: automate cjs-module-lexer dependency update
PR-URL: #47446 Refs: nodejs/security-wg#828 Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 8e673bd commit 37d1273

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

.github/workflows/tools.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ jobs:
172172
label: crypto, notable-change
173173
run: |
174174
node ./tools/dep_updaters/update-root-certs.mjs -v -f "$GITHUB_ENV"
175+
- id: cjs-module-lexer
176+
subsystem: deps
177+
label: dependencies
178+
run: |
179+
./tools/dep_updaters/update-cjs-module-lexer.sh > temp-output
180+
cat temp-output
181+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
182+
rm temp-output
175183
steps:
176184
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
177185
with:
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update cjs-module-lexer in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
7+
DEPS_DIR="$BASE_DIR/deps"
8+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
9+
[ -x "$NODE" ] || NODE=$(command -v node)
10+
11+
NPM="$DEPS_DIR/npm/bin/npm-cli.js"
12+
13+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
14+
const res = await fetch('https://api.github.com/repos/nodejs/cjs-module-lexer/tags');
15+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
16+
const tags = await res.json();
17+
const { name } = tags.at(0)
18+
console.log(name);
19+
EOF
20+
)"
21+
22+
CURRENT_VERSION=$("$NODE" -p "require('./deps/cjs-module-lexer/package.json').version")
23+
24+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
25+
26+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
27+
echo "Skipped because ada is on the latest version."
28+
exit 0
29+
fi
30+
31+
echo "Making temporary workspace"
32+
33+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
34+
35+
cleanup () {
36+
EXIT_CODE=$?
37+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
38+
exit $EXIT_CODE
39+
}
40+
41+
trap cleanup INT TERM EXIT
42+
43+
cd "$WORKSPACE"
44+
45+
"$NODE" "$NPM" init --yes
46+
47+
"$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts cjs-module-lexer
48+
49+
rm -rf "$DEPS_DIR/cjs-module-lexer"
50+
51+
mv node_modules/cjs-module-lexer "$DEPS_DIR/cjs-module-lexer"
52+
53+
echo "All done!"
54+
echo ""
55+
echo "Please git add cjs-module-lexer, commit the new version:"
56+
echo ""
57+
echo "$ git add -A deps/cjs-module-lexer"
58+
echo "$ git commit -m \"deps: update cjs-module-lexer to $NEW_VERSION\""
59+
echo ""
60+
61+
# The last line of the script should always print the new version,
62+
# as we need to add it to $GITHUB_ENV variable.
63+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)