diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index 5e286f98f75c7a..c8fbd5b4eddd53 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -142,12 +142,10 @@ jobs: subsystem: deps label: dependencies run: | - NEW_VERSION=$(gh api repos/nghttp2/nghttp2/releases/latest -q '.tag_name|ltrimstr("v")') - CURRENT_VERSION=$(grep "#define NGHTTP2_VERSION" ./deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h | sed -n "s/^.*VERSION \(.*\)/\1/p") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/update-nghttp2.sh "$NEW_VERSION" - fi + ./tools/dep_updaters/nghttp2.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: llhttp subsystem: deps label: dependencies diff --git a/doc/contributing/maintaining-nghttp2.md b/doc/contributing/maintaining-nghttp2.md index e75240f107aa35..41ba0b58508513 100644 --- a/doc/contributing/maintaining-nghttp2.md +++ b/doc/contributing/maintaining-nghttp2.md @@ -13,16 +13,9 @@ directory and C++ code in the ## Step 1: Updating nghttp2 -The `tools/update-nghttp2.sh` script automates the update of the +The `tools/dep_updaters/update-nghttp2.sh` script automates the update of the postject source files. -In the following examples, `x.y.z` should match the nghttp2 -version to update to. - -```console -$ ./tools/update-nghttp2.sh x.y.z -``` - ## Step 2: Test the build ```console diff --git a/tools/update-nghttp2.sh b/tools/dep_updaters/update-nghttp2.sh similarity index 52% rename from tools/update-nghttp2.sh rename to tools/dep_updaters/update-nghttp2.sh index ba01f8d6bdef9f..c53a620ba096ec 100755 --- a/tools/update-nghttp2.sh +++ b/tools/dep_updaters/update-nghttp2.sh @@ -2,13 +2,27 @@ set -e # Shell script to update nghttp2 in the source tree to specific version -BASE_DIR=$(cd "$(dirname "$0")/.." && pwd) +BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) DEPS_DIR="$BASE_DIR/deps" -NGHTTP2_VERSION=$1 -if [ "$#" -le 0 ]; then - echo "Error: please provide an nghttp2 version to update to" - exit 1 +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) + +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' +const res = await fetch('https://api.github.com/repos/nghttp2/nghttp2/releases/latest'); +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); +const { tag_name } = await res.json(); +console.log(tag_name.replace('v', '')); +EOF +)" + +CURRENT_VERSION=$(grep "#define NGHTTP2_VERSION" ./deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p") + +echo "Comparing $NEW_VERSION with $CURRENT_VERSION" + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because nghttp2 is on the latest version." + exit 0 fi echo "Making temporary workspace" @@ -23,8 +37,8 @@ cleanup () { trap cleanup INT TERM EXIT -NGHTTP2_REF="v$NGHTTP2_VERSION" -NGHTTP2_TARBALL="nghttp2-$NGHTTP2_VERSION.tar.gz" +NGHTTP2_REF="v$NEW_VERSION" +NGHTTP2_TARBALL="nghttp2-$NEW_VERSION.tar.gz" cd "$WORKSPACE" @@ -32,7 +46,7 @@ echo "Fetching nghttp2 source archive" curl -sL -o "$NGHTTP2_TARBALL" "https://github.com/nghttp2/nghttp2/releases/download/$NGHTTP2_REF/$NGHTTP2_TARBALL" gzip -dc "$NGHTTP2_TARBALL" | tar xf - rm "$NGHTTP2_TARBALL" -mv "nghttp2-$NGHTTP2_VERSION" nghttp2 +mv "nghttp2-$NEW_VERSION" nghttp2 echo "Removing everything, except lib/ and COPYING" cd nghttp2 @@ -59,5 +73,9 @@ echo "" echo "Please git add nghttp2, commit the new version:" echo "" echo "$ git add -A deps/nghttp2" -echo "$ git commit -m \"deps: update nghttp2 to $NGHTTP2_VERSION\"" +echo "$ git commit -m \"deps: update nghttp2 to $NEW_VERSION\"" echo "" + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION"