11cb0ef41Sopenharmony_ci#!/bin/sh
21cb0ef41Sopenharmony_ciset -e
31cb0ef41Sopenharmony_ci# Shell script to update simdutf in the source tree to a specific version
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciBASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
61cb0ef41Sopenharmony_ciDEPS_DIR="$BASE_DIR/deps"
71cb0ef41Sopenharmony_ci[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
81cb0ef41Sopenharmony_ci[ -x "$NODE" ] || NODE=$(command -v node)
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci# shellcheck disable=SC1091
111cb0ef41Sopenharmony_ci. "$BASE_DIR/tools/dep_updaters/utils.sh"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciNEW_VERSION="$("$NODE" --input-type=module <<'EOF'
141cb0ef41Sopenharmony_ciconst res = await fetch('https://api.github.com/repos/simdutf/simdutf/releases/latest');
151cb0ef41Sopenharmony_ciif (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
161cb0ef41Sopenharmony_ciconst { tag_name } = await res.json();
171cb0ef41Sopenharmony_ciconsole.log(tag_name.replace('v', ''));
181cb0ef41Sopenharmony_ciEOF
191cb0ef41Sopenharmony_ci)"
201cb0ef41Sopenharmony_ciCURRENT_VERSION=$(grep "#define SIMDUTF_VERSION" "$DEPS_DIR/simdutf/simdutf.h" | sed -n "s/^.*VERSION \"\(.*\)\"/\1/p")
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciecho "Comparing $NEW_VERSION with $CURRENT_VERSION"
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciif [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
251cb0ef41Sopenharmony_ci  echo "Skipped because simdutf is on the latest version."
261cb0ef41Sopenharmony_ci  exit 0
271cb0ef41Sopenharmony_cifi
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciecho "Making temporary workspace..."
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciWORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cicleanup () {
341cb0ef41Sopenharmony_ci  EXIT_CODE=$?
351cb0ef41Sopenharmony_ci  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
361cb0ef41Sopenharmony_ci  exit $EXIT_CODE
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_citrap cleanup INT TERM EXIT
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciSIMDUTF_REF="v$NEW_VERSION"
421cb0ef41Sopenharmony_ciSIMDUTF_ZIP="simdutf-$SIMDUTF_REF.zip"
431cb0ef41Sopenharmony_ciSIMDUTF_LICENSE="LICENSE-MIT"
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_cicd "$WORKSPACE"
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciecho "Fetching simdutf source archive..."
481cb0ef41Sopenharmony_cicurl -sL -o "$SIMDUTF_ZIP" "https://github.com/simdutf/simdutf/releases/download/$SIMDUTF_REF/singleheader.zip"
491cb0ef41Sopenharmony_cilog_and_verify_sha256sum "simdutf" "$SIMDUTF_ZIP"
501cb0ef41Sopenharmony_ciunzip "$SIMDUTF_ZIP"
511cb0ef41Sopenharmony_cirm "$SIMDUTF_ZIP"
521cb0ef41Sopenharmony_cirm ./*_demo.cpp
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_cicurl -sL -o "$SIMDUTF_LICENSE" "https://raw.githubusercontent.com/simdutf/simdutf/HEAD/LICENSE-MIT"
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ciecho "Replacing existing simdutf (except GYP build files)"
571cb0ef41Sopenharmony_cimv "$DEPS_DIR/simdutf/"*.gyp "$DEPS_DIR/simdutf/README.md" "$WORKSPACE/"
581cb0ef41Sopenharmony_cirm -rf "$DEPS_DIR/simdutf"
591cb0ef41Sopenharmony_cimv "$WORKSPACE" "$DEPS_DIR/simdutf"
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ciecho "All done!"
621cb0ef41Sopenharmony_ciecho ""
631cb0ef41Sopenharmony_ciecho "Please git add simdutf, commit the new version:"
641cb0ef41Sopenharmony_ciecho ""
651cb0ef41Sopenharmony_ciecho "$ git add -A deps/simdutf"
661cb0ef41Sopenharmony_ciecho "$ git commit -m \"deps: update simdutf to $NEW_VERSION\""
671cb0ef41Sopenharmony_ciecho ""
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci# The last line of the script should always print the new version,
701cb0ef41Sopenharmony_ci# as we need to add it to $GITHUB_ENV variable.
711cb0ef41Sopenharmony_ciecho "NEW_VERSION=$NEW_VERSION"
72