Skip to content

Commit 4b8b92f

Browse files
committedMay 3, 2024
tools: automate gyp-next update
PR-URL: #52014 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 590decf commit 4b8b92f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
 

‎.github/workflows/tools.yml

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ on:
2525
- eslint
2626
- github_reporter
2727
- googletest
28+
- gyp-next
2829
- histogram
2930
- icu
3031
# - libuv
@@ -157,6 +158,14 @@ jobs:
157158
cat temp-output
158159
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
159160
rm temp-output
161+
- id: gyp-next
162+
subsystem: tools
163+
label: tools
164+
run: |
165+
./tools/dep_updaters/update-gyp-next.sh > temp-output
166+
cat temp-output
167+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
168+
rm temp-output
160169
- id: histogram
161170
subsystem: deps
162171
label: dependencies

‎tools/dep_updaters/update-gyp-next.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update gyp-next in the source tree to specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
7+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
8+
[ -x "$NODE" ] || NODE=$(command -v node)
9+
10+
# shellcheck disable=SC1091
11+
. "$BASE_DIR/tools/dep_updaters/utils.sh"
12+
13+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
14+
const res = await fetch('https://api.github.com/repos/nodejs/gyp-next/releases/latest');
15+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
16+
const { tag_name } = await res.json();
17+
console.log(tag_name.replace('v', ''));
18+
EOF
19+
)"
20+
21+
CURRENT_VERSION=$(grep -m 1 version ./tools/gyp/pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
22+
23+
# This function exit with 0 if new version and current version are the same
24+
compare_dependency_version "gyp-next" "$NEW_VERSION" "$CURRENT_VERSION"
25+
26+
echo "Making temporary workspace"
27+
28+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
29+
30+
cleanup () {
31+
EXIT_CODE=$?
32+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
33+
exit $EXIT_CODE
34+
}
35+
36+
trap cleanup INT TERM EXIT
37+
38+
GYP_NEXT_TARBALL="$NEW_VERSION.tar.gz"
39+
40+
cd "$WORKSPACE"
41+
42+
curl -sL -o "$GYP_NEXT_TARBALL" "https://github.com/nodejs/gyp-next/archive/refs/tags/v$NEW_VERSION.tar.gz"
43+
44+
log_and_verify_sha256sum "gyp-next" "$GYP_NEXT_TARBALL"
45+
46+
gzip -dc "$GYP_NEXT_TARBALL" | tar xf -
47+
48+
rm "$GYP_NEXT_TARBALL"
49+
50+
mv "gyp-next-$NEW_VERSION" gyp
51+
52+
rm -rf "$BASE_DIR/tools/gyp"
53+
54+
mv "$WORKSPACE/gyp" "$BASE_DIR/tools/"
55+
56+
echo "All done!"
57+
echo ""
58+
echo "Please git add gyp-next and commit the new version:"
59+
echo ""
60+
echo "$ git add -A tools/gyp"
61+
echo "$ git commit -m \"tools: update gyp-next to $NEW_VERSION\""
62+
echo ""
63+
64+
# The last line of the script should always print the new version,
65+
# as we need to add it to $GITHUB_ENV variable.
66+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)
Please sign in to comment.