1#!/bin/sh 2set -e 3 4# Shell script to update llhttp in the source tree to specific version 5 6BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) 7DEPS_DIR="${BASE_DIR}/deps" 8 9[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" 10[ -x "$NODE" ] || NODE=$(command -v node) 11 12# shellcheck disable=SC1091 13. "$BASE_DIR/tools/dep_updaters/utils.sh" 14 15NEW_VERSION="$("$NODE" --input-type=module <<'EOF' 16const res = await fetch('https://api.github.com/repos/nodejs/llhttp/releases/latest'); 17if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); 18const { tag_name } = await res.json(); 19console.log(tag_name.replace('release/v', '')); 20EOF 21)" 22 23CURRENT_MAJOR_VERSION=$(grep "#define LLHTTP_VERSION_MAJOR" ./deps/llhttp/include/llhttp.h | sed -n "s/^.*MAJOR \(.*\)/\1/p") 24CURRENT_MINOR_VERSION=$(grep "#define LLHTTP_VERSION_MINOR" ./deps/llhttp/include/llhttp.h | sed -n "s/^.*MINOR \(.*\)/\1/p") 25CURRENT_PATCH_VERSION=$(grep "#define LLHTTP_VERSION_PATCH" ./deps/llhttp/include/llhttp.h | sed -n "s/^.*PATCH \(.*\)/\1/p") 26CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION" 27 28echo "Comparing $NEW_VERSION with $CURRENT_VERSION" 29 30if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then 31 echo "Skipped because llhttp is on the latest version." 32 exit 0 33fi 34 35cleanup () { 36 EXIT_CODE=$? 37 [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" 38 exit $EXIT_CODE 39} 40 41echo "Making temporary workspace ..." 42WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') 43trap cleanup INT TERM EXIT 44 45cd "$WORKSPACE" 46 47if echo "$NEW_VERSION" | grep -qs "/" ; then # Download a release 48 REPO="git@github.com:$NEW_VERSION.git" 49 BRANCH=$2 50 [ -z "$BRANCH" ] && BRANCH=main 51 52 echo "Cloning llhttp source archive $REPO ..." 53 git clone "$REPO" llhttp 54 cd llhttp 55 echo "Checking out branch $BRANCH ..." 56 git checkout "$BRANCH" 57 58 echo "Building llhttp ..." 59 npm install 60 make release 61 62 echo "Copying llhttp release ..." 63 rm -rf "$DEPS_DIR/llhttp" 64 cp -a release "$DEPS_DIR/llhttp" 65else 66 echo "Download llhttp release $NEW_VERSION ..." 67 LLHTTP_TARBALL="llhttp-v$NEW_VERSION.tar.gz" 68 curl -sL -o "$LLHTTP_TARBALL" "https://github.com/nodejs/llhttp/archive/refs/tags/release/v$NEW_VERSION.tar.gz" 69 gzip -dc "$LLHTTP_TARBALL" | tar xf - 70 71 echo "Copying llhttp release ..." 72 rm -rf "$DEPS_DIR/llhttp" 73 cp -a "llhttp-release-v$NEW_VERSION" "$DEPS_DIR/llhttp" 74fi 75 76echo "" 77echo "All done!" 78echo "" 79echo "Please git add llhttp, commit the new version:" 80echo "" 81echo "$ git add -A deps/llhttp" 82echo "$ git commit -m \"deps: update llhttp to $NEW_VERSION\"" 83echo "" 84 85# The last line of the script should always print the new version, 86# as we need to add it to $GITHUB_ENV variable. 87echo "NEW_VERSION=$NEW_VERSION" 88