Repository: nodejs/node
Pull request: tools: add temporal updater

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: .github/workflows/tools.yml
patch: @@ -38,6 +38,7 @@ on:
           - root-certificates
           - simdjson
           - sqlite
+          - temporal
           - undici
           - uvwasi
           - zlib
@@ -255,6 +256,14 @@ jobs:
               cat temp-output
               tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
               rm temp-output
+          - id: temporal
+            subsystem: deps
+            label: dependencies
+            run: |
+              ./tools/dep_updaters/update-temporal.sh > temp-output
+              cat temp-output
+              tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
+              rm temp-output
           - id: undici
             subsystem: deps
             label: dependencies

filename: tools/dep_updaters/update-temporal.sh
patch: @@ -0,0 +1,70 @@
+#!/bin/sh
+set -e
+# Shell script to update temporal in the source tree to specific version
+
+BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
+
+[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
+[ -x "$NODE" ] || NODE=$(command -v node)
+
+# shellcheck disable=SC1091
+. "$BASE_DIR/tools/dep_updaters/utils.sh"
+
+NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
+const res = await fetch('https://api.github.com/repos/boa-dev/temporal/releases/latest');
+if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
+const { tag_name } = await res.json();
+console.log(tag_name.replace('v', ''));
+EOF
+)"
+
+CURRENT_VERSION=$(grep -m 1 version ./deps/temporal/Cargo.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
+
+# This function exit with 0 if new version and current version are the same
+compare_dependency_version "temporal" "$NEW_VERSION" "$CURRENT_VERSION"
+
+echo "Making temporary workspace"
+
+WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
+
+cleanup () {
+  EXIT_CODE=$?
+  [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
+  exit $EXIT_CODE
+}
+
+trap cleanup INT TERM EXIT
+
+TEMPORAL_TARBALL="$NEW_VERSION.tar.gz"
+
+cd "$WORKSPACE"
+
+curl -sL -o "$TEMPORAL_TARBALL"  "https://github.com/boa-dev/temporal/archive/refs/tags/v$NEW_VERSION.tar.gz"
+log_and_verify_sha256sum "temporal" "$TEMPORAL_TARBALL"
+
+gzip -dc "$TEMPORAL_TARBALL" | tar xf -
+
+rm "$TEMPORAL_TARBALL"
+
+mv "temporal-$NEW_VERSION" temporal
+
+rm -rf "$WORKSPACE/temporal/.github"
+
+echo "Copying existing gyp files"
+cp "$BASE_DIR/deps/temporal/temporal_capi/temporal_capi.gyp" "$WORKSPACE/temporal/temporal_capi"
+
+echo "Applying dependency update"
+rm -rf "$BASE_DIR/deps/temporal"
+mv "$WORKSPACE/temporal" "$BASE_DIR/deps/temporal"
+
+echo "All done!"
+echo ""
+echo "Please git add temporal and commit the new version:"
+echo ""
+echo "$ git add -A deps/temporal"
+echo "$ git commit -m \"deps: update temporal to $NEW_VERSION\""
+echo ""
+
+# The last line of the script should always print the new version,
+# as we need to add it to $GITHUB_ENV variable.
+echo "NEW_VERSION=$NEW_VERSION"