Skip to content

Commit 1509312

Browse files
marco-ippolitotargos
authored andcommitted
tools: automate zlib update
PR-URL: #47417 Refs: nodejs/security-wg#828 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 55f70f6 commit 1509312

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

.github/workflows/tools.yml

+8
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ jobs:
198198
cat temp-output
199199
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
200200
rm temp-output
201+
- id: zlib
202+
subsystem: deps
203+
label: dependencies
204+
run: |
205+
./tools/dep_updaters/update-zlib.sh > temp-output
206+
cat temp-output
207+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
208+
rm temp-output
201209
steps:
202210
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
203211
with:

tools/dep_updaters/update-zlib.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update zlib in the source tree to a specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
8+
CURRENT_VERSION=$(grep "#define ZLIB_VERSION" "$DEPS_DIR/zlib/zlib.h" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
9+
10+
NEW_VERSION_ZLIB_H=$(curl -s "https://chromium.googlesource.com/chromium/src/+/refs/heads/main/third_party/zlib/zlib.h?format=TEXT" | base64 --decode)
11+
12+
NEW_VERSION=$(printf '%s' "$NEW_VERSION_ZLIB_H" | grep "#define ZLIB_VERSION" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
13+
14+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
15+
16+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
17+
echo "Skipped because zlib is on the latest version."
18+
exit 0
19+
fi
20+
21+
echo "Making temporary workspace..."
22+
23+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
24+
25+
cd "$WORKSPACE"
26+
27+
mkdir zlib
28+
29+
ZLIB_TARBALL=zlib.tar.gz
30+
31+
echo "Fetching zlib source archive"
32+
curl -sL -o $ZLIB_TARBALL https://chromium.googlesource.com/chromium/src/+archive/refs/heads/main/third_party/$ZLIB_TARBALL
33+
34+
gzip -dc "$ZLIB_TARBALL" | tar xf - -C zlib/
35+
36+
rm "$ZLIB_TARBALL"
37+
38+
cp "$DEPS_DIR/zlib/zlib.gyp" "$DEPS_DIR/zlib/GN-scraper.py" "$DEPS_DIR/zlib/win32/zlib.def" "$DEPS_DIR"
39+
40+
rm -rf "$DEPS_DIR/zlib" zlib/.git
41+
42+
mv zlib "$DEPS_DIR/"
43+
44+
mv "$DEPS_DIR/zlib.gyp" "$DEPS_DIR/GN-scraper.py" "$DEPS_DIR/zlib/"
45+
46+
mkdir "$DEPS_DIR/zlib/win32"
47+
48+
mv "$DEPS_DIR/zlib.def" "$DEPS_DIR/zlib/win32"
49+
50+
perl -i -pe 's|^#include "chromeconf.h"|//#include "chromeconf.h"|' deps/zlib/zconf.h
51+
52+
echo "All done!"
53+
echo ""
54+
echo "Make sure to update the deps/zlib/zlib.gyp if any significant changes have occurred upstream"
55+
echo ""
56+
echo "Please git add zlib, commit the new version:"
57+
echo ""
58+
echo "$ git add -A deps/zlib"
59+
echo "$ git commit -m \"deps: update zlib to $NEW_VERSION\""
60+
echo ""
61+
62+
# The last line of the script should always print the new version,
63+
# as we need to add it to $GITHUB_ENV variable.
64+
echo "NEW_VERSION=$NEW_VERSION"

0 commit comments

Comments
 (0)