Skip to content

Commit 6dca79f

Browse files
marco-ippolitoRafaelGSS
authored andcommitted
tools: standardize update-nghttp2.sh
PR-URL: #47197 Refs: nodejs/security-wg#828 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent ca981be commit 6dca79f

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

.github/workflows/tools.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,10 @@ jobs:
142142
subsystem: deps
143143
label: dependencies
144144
run: |
145-
NEW_VERSION=$(gh api repos/nghttp2/nghttp2/releases/latest -q '.tag_name|ltrimstr("v")')
146-
CURRENT_VERSION=$(grep "#define NGHTTP2_VERSION" ./deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h | sed -n "s/^.*VERSION \(.*\)/\1/p")
147-
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
148-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
149-
./tools/update-nghttp2.sh "$NEW_VERSION"
150-
fi
145+
./tools/dep_updaters/nghttp2.sh > temp-output
146+
cat temp-output
147+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
148+
rm temp-output
151149
- id: llhttp
152150
subsystem: deps
153151
label: dependencies

doc/contributing/maintaining-nghttp2.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,9 @@ directory and C++ code in the
1313

1414
## Step 1: Updating nghttp2
1515

16-
The `tools/update-nghttp2.sh` script automates the update of the
16+
The `tools/dep_updaters/update-nghttp2.sh` script automates the update of the
1717
postject source files.
1818

19-
In the following examples, `x.y.z` should match the nghttp2
20-
version to update to.
21-
22-
```console
23-
$ ./tools/update-nghttp2.sh x.y.z
24-
```
25-
2619
## Step 2: Test the build
2720

2821
```console

tools/update-nghttp2.sh tools/dep_updaters/update-nghttp2.sh

+27-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
set -e
33
# Shell script to update nghttp2 in the source tree to specific version
44

5-
BASE_DIR=$(cd "$(dirname "$0")/.." && pwd)
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
66
DEPS_DIR="$BASE_DIR/deps"
7-
NGHTTP2_VERSION=$1
87

9-
if [ "$#" -le 0 ]; then
10-
echo "Error: please provide an nghttp2 version to update to"
11-
exit 1
8+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
9+
[ -x "$NODE" ] || NODE=$(command -v node)
10+
11+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
12+
const res = await fetch('https://api.github.com/repos/nghttp2/nghttp2/releases/latest');
13+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
14+
const { tag_name } = await res.json();
15+
console.log(tag_name.replace('v', ''));
16+
EOF
17+
)"
18+
19+
CURRENT_VERSION=$(grep "#define NGHTTP2_VERSION" ./deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
20+
21+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
22+
23+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
24+
echo "Skipped because nghttp2 is on the latest version."
25+
exit 0
1226
fi
1327

1428
echo "Making temporary workspace"
@@ -23,16 +37,16 @@ cleanup () {
2337

2438
trap cleanup INT TERM EXIT
2539

26-
NGHTTP2_REF="v$NGHTTP2_VERSION"
27-
NGHTTP2_TARBALL="nghttp2-$NGHTTP2_VERSION.tar.gz"
40+
NGHTTP2_REF="v$NEW_VERSION"
41+
NGHTTP2_TARBALL="nghttp2-$NEW_VERSION.tar.gz"
2842

2943
cd "$WORKSPACE"
3044

3145
echo "Fetching nghttp2 source archive"
3246
curl -sL -o "$NGHTTP2_TARBALL" "https://github.com/nghttp2/nghttp2/releases/download/$NGHTTP2_REF/$NGHTTP2_TARBALL"
3347
gzip -dc "$NGHTTP2_TARBALL" | tar xf -
3448
rm "$NGHTTP2_TARBALL"
35-
mv "nghttp2-$NGHTTP2_VERSION" nghttp2
49+
mv "nghttp2-$NEW_VERSION" nghttp2
3650

3751
echo "Removing everything, except lib/ and COPYING"
3852
cd nghttp2
@@ -59,5 +73,9 @@ echo ""
5973
echo "Please git add nghttp2, commit the new version:"
6074
echo ""
6175
echo "$ git add -A deps/nghttp2"
62-
echo "$ git commit -m \"deps: update nghttp2 to $NGHTTP2_VERSION\""
76+
echo "$ git commit -m \"deps: update nghttp2 to $NEW_VERSION\""
6377
echo ""
78+
79+
# The last line of the script should always print the new version,
80+
# as we need to add it to $GITHUB_ENV variable.
81+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)