Skip to content

Commit 3157403

Browse files
tools: automate cjs-module-lexer dependency update
1 parent 1ff9824 commit 3157403

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
@@ -167,6 +167,14 @@ jobs:
167167
cat temp-output
168168
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
169169
rm temp-output
170+
- id: cjs-module-lexer
171+
subsystem: deps
172+
label: dependencies
173+
run: |
174+
./tools/dep_updaters/update-cjs-module-lexer.sh > temp-output
175+
cat temp-output
176+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
177+
rm temp-output
170178
steps:
171179
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
172180
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)