1#!/bin/sh 2set -e 3# Shell script to update ngtcp2 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/ngtcp2/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 22NGTCP2_VERSION_H="$DEPS_DIR/ngtcp2/ngtcp2/lib/includes/ngtcp2/version.h" 23 24CURRENT_VERSION=$(grep "#define NGTCP2_VERSION" "$NGTCP2_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 ngtcp2 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 43NGTCP2_REF="v$NEW_VERSION" 44NGTCP2_ZIP="ngtcp2-$NEW_VERSION" 45 46cd "$WORKSPACE" 47 48echo "Fetching ngtcp2 source archive..." 49curl -sL -o "$NGTCP2_ZIP.zip" "https://github.com/ngtcp2/ngtcp2/archive/refs/tags/$NGTCP2_REF.zip" 50log_and_verify_sha256sum "ngtcp2" "$NGTCP2_ZIP.zip" 51unzip "$NGTCP2_ZIP.zip" 52rm "$NGTCP2_ZIP.zip" 53mv "$NGTCP2_ZIP" ngtcp2 54 55cd ngtcp2 56 57autoreconf -i 58 59# For Mac users who have installed libev with MacPorts, append 60# ',-L/opt/local/lib' to LDFLAGS, and also pass 61# CPPFLAGS="-I/opt/local/include" to ./configure. 62 63./configure --prefix="$PWD/build" --enable-lib-only 64 65cp -R lib/* "$DEPS_DIR/ngtcp2/ngtcp2/lib/" 66 67cp -R crypto/* "$DEPS_DIR/ngtcp2/ngtcp2/crypto/" 68 69echo "All done!" 70echo "" 71echo "Please git add ngtcp2, commit the new version:" 72echo "" 73echo "$ git add -A deps/ngtcp2" 74echo "$ git commit -m \"deps: update ngtcp2 to $NEW_VERSION\"" 75echo "" 76 77# The last line of the script should always print the new version, 78# as we need to add it to $GITHUB_ENV variable. 79echo "NEW_VERSION=$NEW_VERSION" 80