Skip to content

Commit 5d46c59

Browse files
marco-ippolitodanielleadams
authored andcommitted
tools: automate brotli update
PR-URL: #47205 Refs: nodejs/security-wg#828 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com>
1 parent d324c15 commit 5d46c59

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.github/workflows/tools.yml

+8
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ jobs:
161161
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
162162
./tools/dep_updaters/update-ada.sh "$NEW_VERSION"
163163
fi
164+
- id: brotli
165+
subsystem: deps
166+
label: dependencies
167+
run: |
168+
./tools/dep_updaters/update-brotli.sh > temp-output
169+
cat temp-output
170+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
171+
rm temp-output
164172
steps:
165173
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
166174
with:

tools/dep_updaters/update-brotli.sh

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update brotli in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
8+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
9+
[ -x "$NODE" ] || NODE=$(command -v node)
10+
11+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
12+
const res = await fetch('https://api.github.com/repos/google/brotli/releases/latest');
13+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
14+
const { tag_name } = await res.json();
15+
console.log(tag_name.replace('v', ''));
16+
EOF
17+
)"
18+
19+
VERSION_HEX=$(grep "#define BROTLI_VERSION" ./deps/brotli/c/common/version.h | sed 's/.* //')
20+
21+
major=$(( ($VERSION_HEX >> 24) & 0xff ))
22+
minor=$(( ($VERSION_HEX >> 12) & 0xfff ))
23+
patch=$(( $VERSION_HEX & 0xfff ))
24+
CURRENT_VERSION="${major}.${minor}.${patch}"
25+
26+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
27+
28+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
29+
echo "Skipped because brotli is on the latest version."
30+
exit 0
31+
fi
32+
33+
echo "Making temporary workspace"
34+
35+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
36+
37+
cleanup () {
38+
EXIT_CODE=$?
39+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
40+
exit $EXIT_CODE
41+
}
42+
43+
trap cleanup INT TERM EXIT
44+
45+
cd "$WORKSPACE"
46+
47+
BROTLI_TARBALL="v$NEW_VERSION.tar.gz"
48+
49+
echo "Fetching brotli source archive"
50+
curl -sL -o "$BROTLI_TARBALL" "https://github.com/google/brotli/archive/$BROTLI_TARBALL"
51+
gzip -dc "$BROTLI_TARBALL" | tar xf -
52+
rm "$BROTLI_TARBALL"
53+
mv "brotli-$NEW_VERSION" "brotli"
54+
55+
echo "Copying existing gyp file"
56+
cp "$DEPS_DIR/brotli/brotli.gyp" "$WORKSPACE/brotli"
57+
58+
echo "Deleting existing brotli"
59+
rm -rf "$DEPS_DIR/brotli"
60+
mkdir "$DEPS_DIR/brotli"
61+
62+
echo "Update c and LICENSE"
63+
mv "$WORKSPACE/brotli/c" "$WORKSPACE/brotli/LICENSE" "$WORKSPACE/brotli/brotli.gyp" "$DEPS_DIR/brotli"
64+
65+
echo "All done!"
66+
echo ""
67+
echo "Please git add brotli, commit the new version:"
68+
echo ""
69+
echo "$ git add -A deps/brotli"
70+
echo "$ git commit -m \"deps: update brotli to $NEW_VERSION\""
71+
echo ""
72+
73+
# The last line of the script should always print the new version,
74+
# as we need to add it to $GITHUB_ENV variable.
75+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)