|
| 1 | +#!/bin/sh |
| 2 | +set -ex |
| 3 | +# Shell script to update ncrypto in the source tree to a specific version |
| 4 | + |
| 5 | +BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) |
| 6 | +DEPS_DIR="$BASE_DIR/deps" |
| 7 | +[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node" |
| 8 | +[ -x "$NODE" ] || NODE=$(command -v node) |
| 9 | + |
| 10 | +# shellcheck disable=SC1091 |
| 11 | +. "$BASE_DIR/tools/dep_updaters/utils.sh" |
| 12 | + |
| 13 | +NEW_VERSION="$("$NODE" --input-type=module <<'EOF' |
| 14 | +const res = await fetch('https://api.github.com/repos/nodejs/ncrypto/releases/latest', |
| 15 | + process.env.GITHUB_TOKEN && { |
| 16 | + headers: { |
| 17 | + "Authorization": `Bearer ${process.env.GITHUB_TOKEN}` |
| 18 | + }, |
| 19 | + }); |
| 20 | +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); |
| 21 | +const { tag_name } = await res.json(); |
| 22 | +console.log(tag_name.replace('v', '')); |
| 23 | +EOF |
| 24 | +)" |
| 25 | + |
| 26 | +CURRENT_VERSION=$(awk -F'"' '/^#define NCRYPTO_VERSION /{ print $2 }' "$DEPS_DIR/ncrypto/ncrypto/version.h" || true) |
| 27 | + |
| 28 | +# This function exit with 0 if new version and current version are the same |
| 29 | +compare_dependency_version "ncrypto" "$NEW_VERSION" "$CURRENT_VERSION" |
| 30 | + |
| 31 | +echo "Making temporary workspace..." |
| 32 | + |
| 33 | +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') |
| 34 | + |
| 35 | +cleanup () { |
| 36 | + EXIT_CODE=$? |
| 37 | + [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" |
| 38 | + exit $EXIT_CODE |
| 39 | +} |
| 40 | + |
| 41 | +trap cleanup INT TERM EXIT |
| 42 | + |
| 43 | +echo "Fetching ncrypto source archive..." |
| 44 | +NCRYPTO_TARBALL="ncrypto-v$NEW_VERSION.tar.gz" |
| 45 | +curl -sL "https://api.github.com/repos/nodejs/ncrypto/tarball/v$NEW_VERSION" \ |
| 46 | +| tar xz --strip-components=1 -C "$WORKSPACE" --wildcards \ |
| 47 | + '*/README.md' \ |
| 48 | + '*/src/engine.cpp' \ |
| 49 | + '*/src/ncrypto.cpp' \ |
| 50 | + '*/include/ncrypto.h' \ |
| 51 | + '*/include/ncrypto/version.h' |
| 52 | + |
| 53 | +mv "$WORKSPACE/README.md" "$DEPS_DIR/ncrypto/." |
| 54 | +mv "$WORKSPACE/src/engine.cpp" "$DEPS_DIR/ncrypto/engine.cc" |
| 55 | +mv "$WORKSPACE/src/ncrypto.cpp" "$DEPS_DIR/ncrypto/ncrypto.cc" |
| 56 | +mv "$WORKSPACE/include/"* "$DEPS_DIR/ncrypto/." |
| 57 | + |
| 58 | +cleanup |
| 59 | + |
| 60 | +# Update the version number on maintaining-dependencies.md |
| 61 | +# and print the new version as the last line of the script as we need |
| 62 | +# to add it to $GITHUB_ENV variable |
| 63 | +finalize_version_update "ncrypto" "$NEW_VERSION" |
0 commit comments