|
| 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" |
0 commit comments