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