22set -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)
66DEPS_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
1226fi
1327
1428echo " Making temporary workspace"
@@ -23,16 +37,16 @@ cleanup () {
2337
2438trap 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
2943cd " $WORKSPACE "
3044
3145echo " Fetching nghttp2 source archive"
3246curl -sL -o " $NGHTTP2_TARBALL " " https://github.com/nghttp2/nghttp2/releases/download/$NGHTTP2_REF /$NGHTTP2_TARBALL "
3347gzip -dc " $NGHTTP2_TARBALL " | tar xf -
3448rm " $NGHTTP2_TARBALL "
35- mv " nghttp2-$NGHTTP2_VERSION " nghttp2
49+ mv " nghttp2-$NEW_VERSION " nghttp2
3650
3751echo " Removing everything, except lib/ and COPYING"
3852cd nghttp2
@@ -59,5 +73,9 @@ echo ""
5973echo " Please git add nghttp2, commit the new version:"
6074echo " "
6175echo " $ 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 \" "
6377echo " "
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