Skip to content

Commit

Permalink
tools: standardize update-nghttp2.sh
Browse files Browse the repository at this point in the history
PR-URL: #47197
Refs: nodejs/security-wg#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>
  • Loading branch information
marco-ippolito authored and RafaelGSS committed Apr 6, 2023
1 parent 7effda9 commit b0e94a7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions doc/contributing/maintaining-nghttp2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 27 additions & 9 deletions tools/update-nghttp2.sh → tools/dep_updaters/update-nghttp2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,16 +37,16 @@ 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"

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
Expand All @@ -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"

0 comments on commit b0e94a7

Please sign in to comment.