From 98f64ee7248f6e705a78e5155748b7d0f1fec341 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Wed, 29 Mar 2023 10:27:33 +0200 Subject: [PATCH] tools: standardize base64 update PR-URL: https://github.com/nodejs/node/pull/47201 Refs: https://github.com/nodejs/security-wg/issues/828 Reviewed-By: Rafael Gonzaga --- .github/workflows/tools.yml | 11 ++--- tools/dep_updaters/update-base64.sh | 64 +++++++++++++++++++++++++++++ tools/update-base64.sh | 47 --------------------- 3 files changed, 68 insertions(+), 54 deletions(-) create mode 100755 tools/dep_updaters/update-base64.sh delete mode 100755 tools/update-base64.sh diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index 0b4e8c9f79ec86..e980654ae867d3 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -87,13 +87,10 @@ jobs: subsystem: deps label: dependencies run: | - NEW_VERSION=$(gh api repos/aklomp/base64/releases/latest -q '.tag_name|ltrimstr("v")') - CURRENT_VERSION=$(grep "base64 LANGUAGES C VERSION" ./deps/base64/base64/CMakeLists.txt | \ - sed -n "s/^.*VERSION \(.*\))/\1/p") - if [ "$NEW_VERSION" != "$CURRENT_VERSION" ]; then - echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV - ./tools/update-base64.sh "$NEW_VERSION" - fi + ./tools/dep_updaters/update-base64.sh > temp-output + cat temp-output + tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true + rm temp-output - id: acorn subsystem: deps label: dependencies diff --git a/tools/dep_updaters/update-base64.sh b/tools/dep_updaters/update-base64.sh new file mode 100755 index 00000000000000..05d1c58402d1d6 --- /dev/null +++ b/tools/dep_updaters/update-base64.sh @@ -0,0 +1,64 @@ +#!/bin/sh +set -e +# Shell script to update base64 in the source tree to a specific version + +BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) +DEPS_DIR="$BASE_DIR/deps" + +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" +[ -x "$NODE" ] || NODE=$(command -v node) + +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' +const res = await fetch('https://api.github.com/repos/aklomp/base64/releases/latest'); +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); +const { tag_name } = await res.json(); +console.log(tag_name.replace('v', '')); +EOF +)" + +CURRENT_VERSION=$(grep "base64 LANGUAGES C VERSION" ./deps/base64/base64/CMakeLists.txt | sed -n "s/^.*VERSION \(.*\))/\1/p") + +echo "Comparing $NEW_VERSION with $CURRENT_VERSION" + +if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then + echo "Skipped because base64 is on the latest version." + exit 0 +fi + +echo "Making temporary workspace" + +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') + +cleanup () { + EXIT_CODE=$? + [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" + exit $EXIT_CODE +} + +trap cleanup INT TERM EXIT + +cd "$WORKSPACE" + +echo "Fetching base64 source archive" +curl -sL "https://api.github.com/repos/aklomp/base64/tarball/v$NEW_VERSION" | tar xzf - +mv aklomp-base64-* base64 + +echo "Replacing existing base64" +rm -rf "$DEPS_DIR/base64/base64" +mv "$WORKSPACE/base64" "$DEPS_DIR/base64/" + +# Build configuration is handled by `deps/base64/base64.gyp`, but since `config.h` has to be present for the build +# to work, we create it and leave it empty. +echo "// Intentionally empty" >> "$DEPS_DIR/base64/base64/lib/config.h" + +echo "All done!" +echo "" +echo "Please git add base64/base64, commit the new version:" +echo "" +echo "$ git add -A deps/base64/base64" +echo "$ git commit -m \"deps: update base64 to $NEW_VERSION\"" +echo "" + +# The last line of the script should always print the new version, +# as we need to add it to $GITHUB_ENV variable. +echo "NEW_VERSION=$NEW_VERSION" diff --git a/tools/update-base64.sh b/tools/update-base64.sh deleted file mode 100755 index 50b8da7adb867c..00000000000000 --- a/tools/update-base64.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -set -e -# Shell script to update base64 in the source tree to a specific version - -BASE_DIR=$(cd "$(dirname "$0")/.." && pwd) -DEPS_DIR="$BASE_DIR/deps" -BASE64_VERSION=$1 - -if [ "$#" -le 0 ]; then - echo "Error: please provide an base64 version to update to" - echo " e.g. $0 0.4.0" - exit 1 -fi - -echo "Making temporary workspace" - -WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') - -cleanup () { - EXIT_CODE=$? - [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" - exit $EXIT_CODE -} - -trap cleanup INT TERM EXIT - -cd "$WORKSPACE" - -echo "Fetching base64 source archive" -curl -sL "https://api.github.com/repos/aklomp/base64/tarball/v$BASE64_VERSION" | tar xzf - -mv aklomp-base64-* base64 - -echo "Replacing existing base64" -rm -rf "$DEPS_DIR/base64/base64" -mv "$WORKSPACE/base64" "$DEPS_DIR/base64/" - -# Build configuration is handled by `deps/base64/base64.gyp`, but since `config.h` has to be present for the build -# to work, we create it and leave it empty. -echo "// Intentionally empty" >> "$DEPS_DIR/base64/base64/lib/config.h" - -echo "All done!" -echo "" -echo "Please git add base64/base64, commit the new version:" -echo "" -echo "$ git add -A deps/base64/base64" -echo "$ git commit -m \"deps: update base64 to $BASE64_VERSION\"" -echo ""