|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | +# Shell script to update gyp-next in the source tree to specific version |
| 4 | + |
| 5 | +BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) |
| 6 | + |
| 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/gyp-next/releases/latest'); |
| 15 | +if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); |
| 16 | +const { tag_name } = await res.json(); |
| 17 | +console.log(tag_name.replace('v', '')); |
| 18 | +EOF |
| 19 | +)" |
| 20 | + |
| 21 | +CURRENT_VERSION=$(grep -m 1 version ./tools/gyp/pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3) |
| 22 | + |
| 23 | +# This function exit with 0 if new version and current version are the same |
| 24 | +compare_dependency_version "gyp-next" "$NEW_VERSION" "$CURRENT_VERSION" |
| 25 | + |
| 26 | +echo "Making temporary workspace" |
| 27 | + |
| 28 | +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') |
| 29 | + |
| 30 | +cleanup () { |
| 31 | + EXIT_CODE=$? |
| 32 | + [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" |
| 33 | + exit $EXIT_CODE |
| 34 | +} |
| 35 | + |
| 36 | +trap cleanup INT TERM EXIT |
| 37 | + |
| 38 | +GYP_NEXT_TARBALL="$NEW_VERSION.tar.gz" |
| 39 | + |
| 40 | +cd "$WORKSPACE" |
| 41 | + |
| 42 | +curl -sL -o "$GYP_NEXT_TARBALL" "https://github.com/nodejs/gyp-next/archive/refs/tags/v$NEW_VERSION.tar.gz" |
| 43 | + |
| 44 | +log_and_verify_sha256sum "gyp-next" "$GYP_NEXT_TARBALL" |
| 45 | + |
| 46 | +gzip -dc "$GYP_NEXT_TARBALL" | tar xf - |
| 47 | + |
| 48 | +rm "$GYP_NEXT_TARBALL" |
| 49 | + |
| 50 | +mv "gyp-next-$NEW_VERSION" gyp |
| 51 | + |
| 52 | +rm -rf "$BASE_DIR/tools/gyp" |
| 53 | + |
| 54 | +mv "$WORKSPACE/gyp" "$BASE_DIR/tools/" |
| 55 | + |
| 56 | +echo "All done!" |
| 57 | +echo "" |
| 58 | +echo "Please git add gyp-next and commit the new version:" |
| 59 | +echo "" |
| 60 | +echo "$ git add -A tools/gyp" |
| 61 | +echo "$ git commit -m \"tools: update gyp-next to $NEW_VERSION\"" |
| 62 | +echo "" |
| 63 | + |
| 64 | +# The last line of the script should always print the new version, |
| 65 | +# as we need to add it to $GITHUB_ENV variable. |
| 66 | +echo "NEW_VERSION=$NEW_VERSION" |
0 commit comments