1#!/bin/sh 2set -e 3# Shell script to update simdutf in the source tree to a specific version 4 5BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd) 6DEPS_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 13NEW_VERSION="$("$NODE" --input-type=module <<'EOF' 14const res = await fetch('https://api.github.com/repos/simdutf/simdutf/releases/latest'); 15if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res }); 16const { tag_name } = await res.json(); 17console.log(tag_name.replace('v', '')); 18EOF 19)" 20CURRENT_VERSION=$(grep "#define SIMDUTF_VERSION" "$DEPS_DIR/simdutf/simdutf.h" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p") 21 22echo "Comparing $NEW_VERSION with $CURRENT_VERSION" 23 24if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then 25 echo "Skipped because simdutf is on the latest version." 26 exit 0 27fi 28 29echo "Making temporary workspace..." 30 31WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') 32 33cleanup () { 34 EXIT_CODE=$? 35 [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" 36 exit $EXIT_CODE 37} 38 39trap cleanup INT TERM EXIT 40 41SIMDUTF_REF="v$NEW_VERSION" 42SIMDUTF_ZIP="simdutf-$SIMDUTF_REF.zip" 43SIMDUTF_LICENSE="LICENSE-MIT" 44 45cd "$WORKSPACE" 46 47echo "Fetching simdutf source archive..." 48curl -sL -o "$SIMDUTF_ZIP" "https://github.com/simdutf/simdutf/releases/download/$SIMDUTF_REF/singleheader.zip" 49log_and_verify_sha256sum "simdutf" "$SIMDUTF_ZIP" 50unzip "$SIMDUTF_ZIP" 51rm "$SIMDUTF_ZIP" 52rm ./*_demo.cpp 53 54curl -sL -o "$SIMDUTF_LICENSE" "https://raw.githubusercontent.com/simdutf/simdutf/HEAD/LICENSE-MIT" 55 56echo "Replacing existing simdutf (except GYP build files)" 57mv "$DEPS_DIR/simdutf/"*.gyp "$DEPS_DIR/simdutf/README.md" "$WORKSPACE/" 58rm -rf "$DEPS_DIR/simdutf" 59mv "$WORKSPACE" "$DEPS_DIR/simdutf" 60 61echo "All done!" 62echo "" 63echo "Please git add simdutf, commit the new version:" 64echo "" 65echo "$ git add -A deps/simdutf" 66echo "$ git commit -m \"deps: update simdutf to $NEW_VERSION\"" 67echo "" 68 69# The last line of the script should always print the new version, 70# as we need to add it to $GITHUB_ENV variable. 71echo "NEW_VERSION=$NEW_VERSION" 72