Skip to content

Commit 1061e17

Browse files
marco-ippolitodanielleadams
authored andcommitted
tools: standardize update-llhttp.sh
PR-URL: #47198 Refs: nodejs/security-wg#828 Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Tierney Cyren <[email protected]>
1 parent 9781185 commit 1061e17

File tree

5 files changed

+99
-21
lines changed

5 files changed

+99
-21
lines changed

.github/workflows/tools.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,10 @@ jobs:
142142
subsystem: deps
143143
label: dependencies
144144
run: |
145-
NEW_VERSION=$(gh api repos/nodejs/llhttp/releases/latest -q '.tag_name|ltrimstr("release/v")')
146-
CURRENT_MAJOR_VERSION=$(grep "#define LLHTTP_VERSION_MAJOR" ./deps/llhttp/include/llhttp.h | sed -n "s/^.*MAJOR \(.*\)/\1/p")
147-
CURRENT_MINOR_VERSION=$(grep "#define LLHTTP_VERSION_MINOR" ./deps/llhttp/include/llhttp.h | sed -n "s/^.*MINOR \(.*\)/\1/p")
148-
CURRENT_PATCH_VERSION=$(grep "#define LLHTTP_VERSION_PATCH" ./deps/llhttp/include/llhttp.h | sed -n "s/^.*PATCH \(.*\)/\1/p")
149-
CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION"
150-
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
151-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
152-
./tools/update-llhttp.sh "$NEW_VERSION"
153-
fi
145+
./tools/dep_updaters/update-llhttp.sh > temp-output
146+
cat temp-output
147+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
148+
rm temp-output
154149
- id: c-ares
155150
subsystem: deps
156151
label: dependencies

doc/contributing/maintaining-http.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ repository. Updates are pulled into Node.js under
7979
[deps/llhttp](https://github.com/nodejs/node/tree/HEAD/deps/llhttp).
8080

8181
In order to update Node.js with a new version of llhttp you can use the
82-
`tools/update-llhttp.sh` script.
82+
`tools/dep_updaters/update-llhttp.sh` script.
8383

8484
The contents of the `deps/llhttp` folder should look like the following:
8585

tools/dep_updaters/update-llhttp.sh

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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"

tools/lint-md/package-lock.json

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/lint-md/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@rollup/plugin-commonjs": "^24.0.1",
1818
"@rollup/plugin-node-resolve": "^15.0.1",
19-
"rollup": "^3.19.1",
19+
"rollup": "^3.20.2",
2020
"rollup-plugin-cleanup": "^3.2.1"
2121
}
2222
}

0 commit comments

Comments
 (0)