1#!/bin/sh 2set -e 3# Shell script to update nghttp2 in the source tree to specific version 4 5BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) 6DEPS_DIR="$BASE_DIR/deps" 7 8[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" 9[ -x "$NODE" ] || NODE=$(command -v node) 10 11# shellcheck disable=SC1091 12. "$BASE_DIR/tools/dep_updaters/utils.sh" 13 14NEW_VERSION="$("$NODE" --input-type=module <<'EOF' 15const res = await fetch('https://api.github.com/repos/nghttp2/nghttp2/releases/latest'); 16if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); 17const { tag_name } = await res.json(); 18console.log(tag_name.replace('v', '')); 19EOF 20)" 21 22CURRENT_VERSION=$(grep "#define NGHTTP2_VERSION" ./deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p") 23 24echo "Comparing $NEW_VERSION with $CURRENT_VERSION" 25 26if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then 27 echo "Skipped because nghttp2 is on the latest version." 28 exit 0 29fi 30 31echo "Making temporary workspace" 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 43NGHTTP2_REF="v$NEW_VERSION" 44NGHTTP2_TARBALL="nghttp2-$NEW_VERSION.tar.gz" 45 46cd "$WORKSPACE" 47 48echo "Fetching nghttp2 source archive" 49curl -sL -o "$NGHTTP2_TARBALL" "https://github.com/nghttp2/nghttp2/releases/download/$NGHTTP2_REF/$NGHTTP2_TARBALL" 50 51DEPOSITED_CHECKSUM=$(curl -sL "https://github.com/nghttp2/nghttp2/releases/download/$NGHTTP2_REF/checksums.txt" | grep "$NGHTTP2_TARBALL") 52 53log_and_verify_sha256sum "nghttp2" "$NGHTTP2_TARBALL" "$DEPOSITED_CHECKSUM" 54 55gzip -dc "$NGHTTP2_TARBALL" | tar xf - 56rm "$NGHTTP2_TARBALL" 57mv "nghttp2-$NEW_VERSION" nghttp2 58 59echo "Removing everything, except lib/ and COPYING" 60cd nghttp2 61for dir in *; do 62 if [ "$dir" = "lib" ] || [ "$dir" = "COPYING" ]; then 63 continue 64 fi 65 rm -rf "$dir" 66done 67 68# Refs: https://github.com/nodejs/node/issues/45572 69echo "Copying config.h file" 70cp "$DEPS_DIR/nghttp2/lib/includes/config.h" "$WORKSPACE/nghttp2/lib/includes" 71 72echo "Copying existing gyp files" 73cp "$DEPS_DIR/nghttp2/nghttp2.gyp" "$WORKSPACE/nghttp2" 74 75echo "Replacing existing nghttp2" 76rm -rf "$DEPS_DIR/nghttp2" 77mv "$WORKSPACE/nghttp2" "$DEPS_DIR/" 78 79echo "All done!" 80echo "" 81echo "Please git add nghttp2, commit the new version:" 82echo "" 83echo "$ git add -A deps/nghttp2" 84echo "$ git commit -m \"deps: update nghttp2 to $NEW_VERSION\"" 85echo "" 86 87# The last line of the script should always print the new version, 88# as we need to add it to $GITHUB_ENV variable. 89echo "NEW_VERSION=$NEW_VERSION" 90