1#!/bin/sh 2set -e 3# Shell script to update base64 in the source tree to a specific version 4 5BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) 6DEPS_DIR="$BASE_DIR/deps" 7 8[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" 9[ -x "$NODE" ] || NODE=$(command -v node) 10 11# shellcheck disable=SC1091 12. "$BASE_DIR/tools/dep_updaters/utils.sh" 13 14NEW_VERSION="$("$NODE" --input-type=module <<'EOF' 15const res = await fetch('https://api.github.com/repos/aklomp/base64/releases/latest'); 16if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); 17const { tag_name } = await res.json(); 18console.log(tag_name.replace('v', '')); 19EOF 20)" 21 22CURRENT_VERSION=$(grep "base64 LANGUAGES C VERSION" ./deps/base64/base64/CMakeLists.txt | sed -n "s/^.*VERSION \(.*\))/\1/p") 23 24echo "Comparing $NEW_VERSION with $CURRENT_VERSION" 25 26if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then 27 echo "Skipped because base64 is on the latest version." 28 exit 0 29fi 30 31echo "Making temporary workspace" 32 33WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') 34 35cleanup () { 36 EXIT_CODE=$? 37 [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" 38 exit $EXIT_CODE 39} 40 41trap cleanup INT TERM EXIT 42 43cd "$WORKSPACE" 44 45BASE64_TARBALL="base64-v$NEW_VERSION.tar.gz" 46 47echo "Fetching base64 source archive" 48curl -sL -o "$BASE64_TARBALL" "https://api.github.com/repos/aklomp/base64/tarball/v$NEW_VERSION" 49log_and_verify_sha256sum "base64" "$BASE64_TARBALL" 50gzip -dc "$BASE64_TARBALL" | tar xf - 51rm "$BASE64_TARBALL" 52mv aklomp-base64-* base64 53 54echo "Replacing existing base64" 55rm -rf "$DEPS_DIR/base64/base64" 56mv "$WORKSPACE/base64" "$DEPS_DIR/base64/" 57 58# Build configuration is handled by `deps/base64/base64.gyp`, but since `config.h` has to be present for the build 59# to work, we create it and leave it empty. 60echo "// Intentionally empty" > "$DEPS_DIR/base64/base64/lib/config.h" 61 62# Clear out .gitignore, otherwise config.h is ignored. That's dangerous when 63# people check in our tarballs into source control and run `git clean`. 64echo "# Intentionally empty" > "$DEPS_DIR/base64/base64/.gitignore" 65 66echo "All done!" 67echo "" 68echo "Please git add base64/base64, commit the new version:" 69echo "" 70echo "$ git add -A deps/base64/base64 src/base64_version.h" 71echo "$ git commit -m \"deps: update base64 to $NEW_VERSION\"" 72echo "" 73 74# update the base64_version.h 75cat > "$BASE_DIR/src/base64_version.h" << EOL 76// This is an auto generated file, please do not edit. 77// Refer to tools/dep_updaters/update-base64.sh 78#ifndef SRC_BASE64_VERSION_H_ 79#define SRC_BASE64_VERSION_H_ 80#define BASE64_VERSION "$NEW_VERSION" 81#endif // SRC_BASE64_VERSION_H_ 82EOL 83 84# The last line of the script should always print the new version, 85# as we need to add it to $GITHUB_ENV variable. 86echo "NEW_VERSION=$NEW_VERSION" 87