1#!/bin/sh 2set -e 3# Shell script to update nghttp3 in the source tree to a specific version 4 5BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) 6DEPS_DIR="$BASE_DIR/deps" 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 13NEW_VERSION="$("$NODE" --input-type=module <<'EOF' 14const res = await fetch('https://api.github.com/repos/ngtcp2/nghttp3/releases'); 15if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); 16const releases = await res.json() 17const { tag_name } = releases.at(0); 18console.log(tag_name.replace('v', '')); 19EOF 20)" 21 22NGHTTP3_VERSION_H="$DEPS_DIR/ngtcp2/nghttp3/lib/includes/nghttp3/version.h" 23 24CURRENT_VERSION=$(grep "#define NGHTTP3_VERSION" "$NGHTTP3_VERSION_H" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p") 25 26echo "Comparing $NEW_VERSION with $CURRENT_VERSION" 27 28if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then 29 echo "Skipped because http3 is on the latest version." 30 exit 0 31fi 32 33WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') 34 35cleanup () { 36 EXIT_CODE=$? 37 [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" 38 exit $EXIT_CODE 39} 40 41trap cleanup INT TERM EXIT 42 43NGHTTP3_REF="v$NEW_VERSION" 44NGHTTP3_ZIP="nghttp3-$NEW_VERSION" 45 46cd "$WORKSPACE" 47 48echo "Fetching nghttp3 source archive..." 49curl -sL -o "$NGHTTP3_ZIP.zip" "https://github.com/ngtcp2/nghttp3/archive/refs/tags/$NGHTTP3_REF.zip" 50log_and_verify_sha256sum "nghttp3" "$NGHTTP3_ZIP.zip" 51unzip "$NGHTTP3_ZIP.zip" 52rm "$NGHTTP3_ZIP.zip" 53mv "$NGHTTP3_ZIP" nghttp3 54 55cd nghttp3 56 57autoreconf -i 58 59./configure --prefix="$PWD/build" --enable-lib-only 60 61cp -R lib/* "$DEPS_DIR/ngtcp2/nghttp3/lib/" 62 63echo "All done!" 64echo "" 65echo "Please git add nghttp3, commit the new version:" 66echo "" 67echo "$ git add -A deps/nghttp3" 68echo "$ git commit -m \"deps: update nghttp3 to $NEW_VERSION\"" 69echo "" 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. 73echo "NEW_VERSION=$NEW_VERSION" 74