Skip to content

Commit 7793e4a

Browse files
tools: automate ngtcp2 and nghttp3 update
1 parent 81bb1b0 commit 7793e4a

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

.github/workflows/tools.yml

+16
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,22 @@ jobs:
167167
cat temp-output
168168
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
169169
rm temp-output
170+
- id: ngtcp2
171+
subsystem: deps
172+
label: dependencies
173+
run: |
174+
./tools/dep_updaters/update-ngtcp2.sh > temp-output
175+
cat temp-output
176+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
177+
rm temp-output
178+
- id: nghttp3
179+
subsystem: deps
180+
label: dependencies
181+
run: |
182+
./tools/dep_updaters/update-nghttp3.sh > temp-output
183+
cat temp-output
184+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
185+
rm temp-output
170186
steps:
171187
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
172188
with:
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ngtcp2 and nghttp3
2+
3+
The ngtcp2 and nghttp3 dependencies provide the core functionality for
4+
QUIC and HTTP/3.
5+
6+
The sources are pulled from:
7+
8+
* ngtcp2: <https://github.com/ngtcp2/ngtcp2>
9+
* nghttp3: <https://github.com/ngtcp2/nghttp3>
10+
11+
In both the `ngtcp2` and `nghttp3` git repos, the active development occurs
12+
in the default branch (currently named `main` in each). Tagged versions do not
13+
always point to the default branch.
14+
15+
We only use a subset of the sources for each.
16+
17+
## Updating
18+
19+
The `nghttp3` library depends on `ngtcp2`. Both should always be updated
20+
together. From `ngtcp2` we only want the contents of the `lib` and `crypto`
21+
directories; from `nghttp3` we only want the contents of the `lib` directory.
22+
23+
After updating either dependency, check if any source files or include
24+
directories have been added or removed and update `ngtcp2.gyp` accordingly.
25+
26+
### Updating ngtcp2
27+
28+
The `tools/dep_updaters/update-ngtcp2.sh` script automates the update of the
29+
ngtcp2 source files.
30+
31+
Check that Node.js still builds and tests.
32+
33+
1. Add ngtcp2:
34+
```console
35+
$ git add deps/ngtcp2
36+
```
37+
2. Commit the changes: `git commit`.
38+
3. Add a message like:
39+
```text
40+
deps: update ngtcp2 to <version>
41+
42+
Updated as described in doc/contributing/maintaining-ngtcp2.md.
43+
```
44+
45+
### Updating nghttp3
46+
47+
The `tools/dep_updaters/update-nghttp3.sh` script automates the update of the
48+
nghttp3 source files.
49+
50+
Check that Node.js still builds and tests.
51+
52+
1. Add nghttp3:
53+
```console
54+
$ git add deps/ngtcp2
55+
```
56+
2. Commit the changes: `git commit`.
57+
3. Add a message like:
58+
```text
59+
deps: update nghttp3 to <version>
60+
61+
Updated as described in doc/contributing/maintaining-ngtcp2.md.
62+
```

tools/dep_updaters/update-nghttp3.sh

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update http3 in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
8+
[ -x "$NODE" ] || NODE=$(command -v node)
9+
10+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
11+
const res = await fetch('https://api.github.com/repos/ngtcp2/nghttp3/releases');
12+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
13+
const releases = await res.json()
14+
const { tag_name } = releases.at(0);
15+
console.log(tag_name.replace('v', ''));
16+
EOF
17+
)"
18+
19+
NGHTTP3_VERSION_H="$DEPS_DIR/ngtcp2/nghttp3/lib/includes/nghttp3/version.h"
20+
21+
CURRENT_VERSION=$(grep "#define NGHTTP3_VERSION" "$NGHTTP3_VERSION_H" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
22+
23+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
24+
echo "Skipped because http3 is on the latest version."
25+
exit 0
26+
fi
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+
NGHTTP3_REF="v$NEW_VERSION"
39+
NGHTTP3_ZIP="nghttp3-$NEW_VERSION"
40+
41+
cd "$WORKSPACE"
42+
43+
echo "Fetching nghttp3 source archive..."
44+
curl -sL -o "$NGHTTP3_ZIP.zip" "https://github.com/ngtcp2/nghttp3/archive/refs/tags/$NGHTTP3_REF.zip"
45+
unzip "$NGHTTP3_ZIP.zip"
46+
rm "$NGHTTP3_ZIP.zip"
47+
mv $NGHTTP3_ZIP nghttp3
48+
49+
cd nghttp3
50+
51+
autoreconf -i
52+
53+
./configure --prefix=$PWD/build --enable-lib-only
54+
55+
cp -R lib/* $DEPS_DIR/ngtcp2/nghttp3/lib/
56+
57+
echo "All done!"
58+
echo ""
59+
echo "Please git add nghttp3, commit the new version:"
60+
echo ""
61+
echo "$ git add -A deps/nghttp3"
62+
echo "$ git commit -m \"deps: update nghttp3 to $NEW_VERSION\""
63+
echo ""
64+
65+
# The last line of the script should always print the new version,
66+
# as we need to add it to $GITHUB_ENV variable.
67+
echo "NEW_VERSION=$NEW_VERSION"

tools/dep_updaters/update-ngtcp2.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update ngtcp2 in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
8+
[ -x "$NODE" ] || NODE=$(command -v node)
9+
10+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
11+
const res = await fetch('https://api.github.com/repos/ngtcp2/ngtcp2/releases');
12+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
13+
const releases = await res.json()
14+
const { tag_name } = releases.at(0);
15+
console.log(tag_name.replace('v', ''));
16+
EOF
17+
)"
18+
19+
NGTCP2_VERSION_H="$DEPS_DIR/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h"
20+
21+
CURRENT_VERSION=$(grep "#define NGTCP2_VERSION" "$NGTCP2_VERSION_H" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
22+
23+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
24+
echo "Skipped because ngtcp2 is on the latest version."
25+
exit 0
26+
fi
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+
NGTCP2_REF="v$NEW_VERSION"
39+
NGTCP2_ZIP="ngtcp2-$NEW_VERSION"
40+
41+
cd "$WORKSPACE"
42+
43+
echo "Fetching ngtcp2 source archive..."
44+
curl -sL -o "$NGTCP2_ZIP.zip" "https://github.com/ngtcp2/ngtcp2/archive/refs/tags/$NGTCP2_REF.zip"
45+
unzip "$NGTCP2_ZIP.zip"
46+
rm "$NGTCP2_ZIP.zip"
47+
mv $NGTCP2_ZIP ngtcp2
48+
49+
cd ngtcp2
50+
51+
autoreconf -i
52+
53+
# For Mac users who have installed libev with MacPorts, append
54+
# ',-L/opt/local/lib' to LDFLAGS, and also pass
55+
# CPPFLAGS="-I/opt/local/include" to ./configure.
56+
57+
./configure --prefix=$PWD/build --enable-lib-only
58+
59+
cp -R lib/* $DEPS_DIR/ngtcp2/ngtcp2/lib/
60+
61+
cp -R crypto/* $DEPS_DIR/ngtcp2/ngtcp2/crypto/
62+
63+
echo "All done!"
64+
echo ""
65+
echo "Please git add ngtcp2, commit the new version:"
66+
echo ""
67+
echo "$ git add -A deps/ngtcp2"
68+
echo "$ git commit -m \"deps: update ngtcp2 to $NEW_VERSION\""
69+
echo ""
70+
71+
# The last line of the script should always print the new version,
72+
# as we need to add it to $GITHUB_ENV variable.
73+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)