Skip to content

Commit 98f64ee

Browse files
marco-ippolitoRafaelGSS
authored andcommitted
tools: standardize base64 update
PR-URL: #47201 Refs: nodejs/security-wg#828 Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent c1ef1fd commit 98f64ee

File tree

3 files changed

+68
-54
lines changed

3 files changed

+68
-54
lines changed

.github/workflows/tools.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,10 @@ jobs:
8787
subsystem: deps
8888
label: dependencies
8989
run: |
90-
NEW_VERSION=$(gh api repos/aklomp/base64/releases/latest -q '.tag_name|ltrimstr("v")')
91-
CURRENT_VERSION=$(grep "base64 LANGUAGES C VERSION" ./deps/base64/base64/CMakeLists.txt | \
92-
sed -n "s/^.*VERSION \(.*\))/\1/p")
93-
if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then
94-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
95-
./tools/update-base64.sh "$NEW_VERSION"
96-
fi
90+
./tools/dep_updaters/update-base64.sh > temp-output
91+
cat temp-output
92+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
93+
rm temp-output
9794
- id: acorn
9895
subsystem: deps
9996
label: dependencies

tools/dep_updaters/update-base64.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 base64 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/aklomp/base64/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+
CURRENT_VERSION=$(grep "base64 LANGUAGES C VERSION" ./deps/base64/base64/CMakeLists.txt | sed -n "s/^.*VERSION \(.*\))/\1/p")
20+
21+
echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
22+
23+
if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
24+
echo "Skipped because base64 is on the latest version."
25+
exit 0
26+
fi
27+
28+
echo "Making temporary workspace"
29+
30+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
31+
32+
cleanup () {
33+
EXIT_CODE=$?
34+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
35+
exit $EXIT_CODE
36+
}
37+
38+
trap cleanup INT TERM EXIT
39+
40+
cd "$WORKSPACE"
41+
42+
echo "Fetching base64 source archive"
43+
curl -sL "https://api.github.com/repos/aklomp/base64/tarball/v$NEW_VERSION" | tar xzf -
44+
mv aklomp-base64-* base64
45+
46+
echo "Replacing existing base64"
47+
rm -rf "$DEPS_DIR/base64/base64"
48+
mv "$WORKSPACE/base64" "$DEPS_DIR/base64/"
49+
50+
# Build configuration is handled by `deps/base64/base64.gyp`, but since `config.h` has to be present for the build
51+
# to work, we create it and leave it empty.
52+
echo "// Intentionally empty" >> "$DEPS_DIR/base64/base64/lib/config.h"
53+
54+
echo "All done!"
55+
echo ""
56+
echo "Please git add base64/base64, commit the new version:"
57+
echo ""
58+
echo "$ git add -A deps/base64/base64"
59+
echo "$ git commit -m \"deps: update base64 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"

tools/update-base64.sh

-47
This file was deleted.

0 commit comments

Comments
 (0)