• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2set -e
3# Shell script to update uvwasi 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/nodejs/uvwasi/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_MAJOR_VERSION=$(grep "#define UVWASI_VERSION_MAJOR" "$DEPS_DIR/uvwasi/include/uvwasi.h" | sed -n "s/^.*MAJOR \(.*\)/\1/p")
23CURRENT_MINOR_VERSION=$(grep "#define UVWASI_VERSION_MINOR" "$DEPS_DIR/uvwasi/include/uvwasi.h" | sed -n "s/^.*MINOR \(.*\)/\1/p")
24CURRENT_PATCH_VERSION=$(grep "#define UVWASI_VERSION_PATCH" "$DEPS_DIR/uvwasi/include/uvwasi.h" | sed -n "s/^.*PATCH \(.*\)/\1/p")
25CURRENT_VERSION="$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION.$CURRENT_PATCH_VERSION"
26
27echo "Comparing $NEW_VERSION with $CURRENT_VERSION"
28
29if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
30  echo "Skipped because uvwasi is on the latest version."
31  exit 0
32fi
33
34echo "Making temporary workspace"
35
36WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
37echo "$WORKSPACE"
38cleanup () {
39  EXIT_CODE=$?
40  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
41  exit $EXIT_CODE
42}
43
44trap cleanup INT TERM EXIT
45
46UVWASI_ZIP="uvwasi-$NEW_VERSION"
47cd "$WORKSPACE"
48
49echo "Fetching UVWASI source archive..."
50curl -sL -o "$UVWASI_ZIP.zip" "https://github.com/nodejs/uvwasi/archive/refs/tags/v$NEW_VERSION.zip"
51
52log_and_verify_sha256sum "uvwasi" "$UVWASI_ZIP.zip"
53
54echo "Moving existing GYP build file"
55mv "$DEPS_DIR/uvwasi/"*.gyp "$WORKSPACE/"
56rm -rf "$DEPS_DIR/uvwasi/"
57
58echo "Unzipping..."
59unzip "$UVWASI_ZIP.zip" -d "$DEPS_DIR/uvwasi/"
60rm "$UVWASI_ZIP.zip"
61
62mv "$WORKSPACE/"*.gyp "$DEPS_DIR/uvwasi/"
63cd "$DEPS_DIR/uvwasi/"
64
65echo "Copying new files to deps folder"
66cp -r "$UVWASI_ZIP/include" "$DEPS_DIR/uvwasi/"
67cp -r "$UVWASI_ZIP/src" "$DEPS_DIR/uvwasi/"
68cp "$UVWASI_ZIP/LICENSE" "$DEPS_DIR/uvwasi/"
69rm -rf "$UVWASI_ZIP"
70
71echo "All done!"
72echo ""
73echo "Please git add uvwasi, commit the new version:"
74echo ""
75echo "$ git add -A deps/uvwasi"
76echo "$ git commit -m \"deps: update uvwasi to $NEW_VERSION\""
77echo ""
78echo "Make sure to update the deps/uvwasi/uvwasi.gyp if any significant changes have occurred upstream"
79echo ""
80
81# The last line of the script should always print the new version,
82# as we need to add it to $GITHUB_ENV variable.
83echo "NEW_VERSION=$NEW_VERSION"
84