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