summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMarco Ippolito <marcoippolito54@gmail.com>2023-03-25 09:24:55 +0100
committerGitHub <noreply@github.com>2023-03-25 08:24:55 +0000
commita64469dcf10adb81fdc5b1e5248ce58520858761 (patch)
treeabbc22c60343059b8aff7ac023362b7e7191aa96 /tools
parent5e4f5e122c06744967f539def1e51473abb5db62 (diff)
downloadnode-new-a64469dcf10adb81fdc5b1e5248ce58520858761.tar.gz
tools: standardize update-nghttp2.sh
PR-URL: https://github.com/nodejs/node/pull/47197 Refs: https://github.com/nodejs/security-wg/issues/828 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/dep_updaters/update-nghttp2.sh (renamed from tools/update-nghttp2.sh)36
1 files changed, 27 insertions, 9 deletions
diff --git a/tools/update-nghttp2.sh b/tools/dep_updaters/update-nghttp2.sh
index ba01f8d6bd..c53a620ba0 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"