jason810496 commented on code in PR #71843:
URL: https://github.com/apache/airflow/pull/71843#discussion_r3860251372


##########
.github/workflows/ts-sdk-release.yml:
##########
@@ -0,0 +1,199 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+---
+name: Release TypeScript SDK
+
+on:  # yamllint disable-line rule:truthy
+  workflow_dispatch:
+    inputs:
+      release_type:
+        description: "Stage the package for review or publish it directly"
+        required: true
+        type: choice
+        options:
+          - staged
+          - formal
+      tag:
+        description: "TypeScript SDK release tag (ts-sdk/<version>)"
+        required: true
+        type: string
+      npm_tag:
+        description: "npm dist-tag (for example: beta or latest)"
+        required: true
+        type: string
+
+permissions:
+  contents: read
+
+concurrency:
+  group: ts-sdk-npm-release
+  cancel-in-progress: false
+
+jobs:
+  build:
+    name: Verify and package release
+    runs-on: ubuntu-latest
+    outputs:
+      artifact_name: ${{ steps.package.outputs.artifact_name }}
+      package_file: ${{ steps.release.outputs.package_file }}
+      sha256: ${{ steps.package.outputs.sha256 }}
+      version: ${{ steps.release.outputs.version }}
+    steps:
+      - name: Checkout dispatched release tag
+        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+      - name: Set up Node.js
+        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020  # 
v7.0.0
+        with:
+          node-version: "24.19.0"
+          registry-url: "https://registry.npmjs.org";
+          package-manager-cache: false
+      - name: Enable the pinned pnpm version
+        run: corepack enable
+      - name: Validate release inputs
+        id: release
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: node scripts/validate-release-inputs.mjs
+      - name: Confirm dispatch and checkout use the release tag
+        env:
+          DISPATCH_REF: ${{ github.ref }}
+          DISPATCH_SHA: ${{ github.sha }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          test "${DISPATCH_REF}" = "refs/tags/${RELEASE_TAG}"
+          test "${DISPATCH_SHA}" = "$(git rev-parse HEAD)"
+          test "$(git rev-parse "refs/tags/${RELEASE_TAG}^{commit}")" = "$(git 
rev-parse HEAD)"
+          git merge-base --is-ancestor HEAD "$(git rev-parse 
refs/remotes/origin/main)"
+      - name: Confirm release advances the npm dist-tag
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          error_file="${RUNNER_TEMP}/npm-view-error.log"
+          set +e
+          current_version="$(npm view apache-airflow-ts-sdk 
"dist-tags.${NPM_TAG}" 2>"${error_file}")"

Review Comment:
   Addressed in f50a748b.



##########
ts-sdk/README.md:
##########


Review Comment:
   Addressed in 955acd09.



##########
.github/workflows/ts-sdk-release.yml:
##########
@@ -0,0 +1,199 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+---
+name: Release TypeScript SDK
+
+on:  # yamllint disable-line rule:truthy
+  workflow_dispatch:
+    inputs:
+      release_type:
+        description: "Stage the package for review or publish it directly"
+        required: true
+        type: choice
+        options:
+          - staged
+          - formal
+      tag:
+        description: "TypeScript SDK release tag (ts-sdk/<version>)"
+        required: true
+        type: string
+      npm_tag:
+        description: "npm dist-tag (for example: beta or latest)"
+        required: true
+        type: string
+
+permissions:
+  contents: read
+
+concurrency:
+  group: ts-sdk-npm-release
+  cancel-in-progress: false
+
+jobs:
+  build:
+    name: Verify and package release
+    runs-on: ubuntu-latest
+    outputs:
+      artifact_name: ${{ steps.package.outputs.artifact_name }}
+      package_file: ${{ steps.release.outputs.package_file }}
+      sha256: ${{ steps.package.outputs.sha256 }}
+      version: ${{ steps.release.outputs.version }}
+    steps:
+      - name: Checkout dispatched release tag
+        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+      - name: Set up Node.js
+        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020  # 
v7.0.0
+        with:
+          node-version: "24.19.0"
+          registry-url: "https://registry.npmjs.org";
+          package-manager-cache: false
+      - name: Enable the pinned pnpm version
+        run: corepack enable
+      - name: Validate release inputs
+        id: release
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: node scripts/validate-release-inputs.mjs
+      - name: Confirm dispatch and checkout use the release tag
+        env:
+          DISPATCH_REF: ${{ github.ref }}
+          DISPATCH_SHA: ${{ github.sha }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          test "${DISPATCH_REF}" = "refs/tags/${RELEASE_TAG}"
+          test "${DISPATCH_SHA}" = "$(git rev-parse HEAD)"
+          test "$(git rev-parse "refs/tags/${RELEASE_TAG}^{commit}")" = "$(git 
rev-parse HEAD)"
+          git merge-base --is-ancestor HEAD "$(git rev-parse 
refs/remotes/origin/main)"
+      - name: Confirm release advances the npm dist-tag
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          error_file="${RUNNER_TEMP}/npm-view-error.log"
+          set +e
+          current_version="$(npm view apache-airflow-ts-sdk 
"dist-tags.${NPM_TAG}" 2>"${error_file}")"
+          view_status=$?
+          set -e
+          if [[ ${view_status} -ne 0 ]]; then
+            if grep -q "E404" "${error_file}"; then
+              current_version=""
+            else
+              cat "${error_file}" >&2
+              exit "${view_status}"
+            fi
+          fi
+          CURRENT_DIST_TAG_VERSION="${current_version}" node 
scripts/validate-release-inputs.mjs
+      - name: Verify package identity
+        working-directory: ts-sdk
+        env:
+          EXPECTED_VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          set -euo pipefail
+          test "$(node --print "require('./package.json').name")" = 
"apache-airflow-ts-sdk"
+          test "$(node --print "require('./package.json').version")" = 
"${EXPECTED_VERSION}"
+      - name: Install and test package
+        working-directory: ts-sdk
+        run: |
+          set -euo pipefail
+          pnpm install --frozen-lockfile
+          pnpm run lint
+          pnpm run format:check
+          pnpm run typecheck
+          pnpm test
+      - name: Create package tarball
+        id: package
+        working-directory: ts-sdk
+        env:
+          PACKAGE_FILE: ${{ steps.release.outputs.package_file }}
+          VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          set -euo pipefail
+          artifact_dir="${RUNNER_TEMP}/ts-sdk-package"
+          mkdir -p "${artifact_dir}"
+          test -z "$(find "${artifact_dir}" -mindepth 1 -maxdepth 1 -print 
-quit)"

Review Comment:
   Addressed in ce5e2cec.



##########
.github/workflows/ts-sdk-release.yml:
##########
@@ -0,0 +1,199 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+---
+name: Release TypeScript SDK
+
+on:  # yamllint disable-line rule:truthy
+  workflow_dispatch:
+    inputs:
+      release_type:
+        description: "Stage the package for review or publish it directly"
+        required: true
+        type: choice
+        options:
+          - staged
+          - formal
+      tag:
+        description: "TypeScript SDK release tag (ts-sdk/<version>)"
+        required: true
+        type: string
+      npm_tag:
+        description: "npm dist-tag (for example: beta or latest)"
+        required: true
+        type: string
+
+permissions:
+  contents: read
+
+concurrency:
+  group: ts-sdk-npm-release
+  cancel-in-progress: false
+
+jobs:
+  build:
+    name: Verify and package release
+    runs-on: ubuntu-latest
+    outputs:
+      artifact_name: ${{ steps.package.outputs.artifact_name }}
+      package_file: ${{ steps.release.outputs.package_file }}
+      sha256: ${{ steps.package.outputs.sha256 }}
+      version: ${{ steps.release.outputs.version }}
+    steps:
+      - name: Checkout dispatched release tag
+        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+      - name: Set up Node.js
+        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020  # 
v7.0.0
+        with:
+          node-version: "24.19.0"
+          registry-url: "https://registry.npmjs.org";
+          package-manager-cache: false
+      - name: Enable the pinned pnpm version
+        run: corepack enable
+      - name: Validate release inputs
+        id: release
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: node scripts/validate-release-inputs.mjs
+      - name: Confirm dispatch and checkout use the release tag
+        env:
+          DISPATCH_REF: ${{ github.ref }}
+          DISPATCH_SHA: ${{ github.sha }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          test "${DISPATCH_REF}" = "refs/tags/${RELEASE_TAG}"
+          test "${DISPATCH_SHA}" = "$(git rev-parse HEAD)"
+          test "$(git rev-parse "refs/tags/${RELEASE_TAG}^{commit}")" = "$(git 
rev-parse HEAD)"
+          git merge-base --is-ancestor HEAD "$(git rev-parse 
refs/remotes/origin/main)"
+      - name: Confirm release advances the npm dist-tag
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          error_file="${RUNNER_TEMP}/npm-view-error.log"
+          set +e
+          current_version="$(npm view apache-airflow-ts-sdk 
"dist-tags.${NPM_TAG}" 2>"${error_file}")"
+          view_status=$?
+          set -e
+          if [[ ${view_status} -ne 0 ]]; then
+            if grep -q "E404" "${error_file}"; then
+              current_version=""
+            else
+              cat "${error_file}" >&2
+              exit "${view_status}"
+            fi
+          fi
+          CURRENT_DIST_TAG_VERSION="${current_version}" node 
scripts/validate-release-inputs.mjs
+      - name: Verify package identity
+        working-directory: ts-sdk
+        env:
+          EXPECTED_VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          set -euo pipefail
+          test "$(node --print "require('./package.json').name")" = 
"apache-airflow-ts-sdk"
+          test "$(node --print "require('./package.json').version")" = 
"${EXPECTED_VERSION}"
+      - name: Install and test package
+        working-directory: ts-sdk
+        run: |
+          set -euo pipefail
+          pnpm install --frozen-lockfile
+          pnpm run lint
+          pnpm run format:check
+          pnpm run typecheck
+          pnpm test
+      - name: Create package tarball
+        id: package
+        working-directory: ts-sdk
+        env:
+          PACKAGE_FILE: ${{ steps.release.outputs.package_file }}
+          VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          set -euo pipefail
+          artifact_dir="${RUNNER_TEMP}/ts-sdk-package"
+          mkdir -p "${artifact_dir}"
+          test -z "$(find "${artifact_dir}" -mindepth 1 -maxdepth 1 -print 
-quit)"
+          npm pack --pack-destination "${artifact_dir}"
+          artifact_path="${artifact_dir}/${PACKAGE_FILE}"
+          test -f "${artifact_path}"
+          test "$(find "${artifact_dir}" -maxdepth 1 -type f -name '*.tgz' | 
wc -l)" -eq 1
+          echo "artifact_name=ts-sdk-package-${VERSION}" >> "${GITHUB_OUTPUT}"
+          echo "sha256=$(sha256sum "${artifact_path}" | awk '{print $1}')" >> 
"${GITHUB_OUTPUT}"
+      - name: Upload package tarball
+        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a 
 # v7.0.1
+        with:
+          name: ${{ steps.package.outputs.artifact_name }}
+          path: ${{ runner.temp }}/ts-sdk-package/${{ 
steps.release.outputs.package_file }}
+          if-no-files-found: error
+          retention-days: 1

Review Comment:
   Addressed in 00b08b1d.



##########
.github/workflows/ts-sdk-release.yml:
##########
@@ -0,0 +1,199 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+---
+name: Release TypeScript SDK
+
+on:  # yamllint disable-line rule:truthy
+  workflow_dispatch:
+    inputs:
+      release_type:
+        description: "Stage the package for review or publish it directly"
+        required: true
+        type: choice
+        options:
+          - staged
+          - formal
+      tag:
+        description: "TypeScript SDK release tag (ts-sdk/<version>)"
+        required: true
+        type: string
+      npm_tag:
+        description: "npm dist-tag (for example: beta or latest)"
+        required: true
+        type: string
+
+permissions:
+  contents: read
+
+concurrency:
+  group: ts-sdk-npm-release
+  cancel-in-progress: false
+
+jobs:
+  build:
+    name: Verify and package release
+    runs-on: ubuntu-latest
+    outputs:
+      artifact_name: ${{ steps.package.outputs.artifact_name }}
+      package_file: ${{ steps.release.outputs.package_file }}
+      sha256: ${{ steps.package.outputs.sha256 }}
+      version: ${{ steps.release.outputs.version }}
+    steps:
+      - name: Checkout dispatched release tag
+        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+      - name: Set up Node.js
+        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020  # 
v7.0.0
+        with:
+          node-version: "24.19.0"
+          registry-url: "https://registry.npmjs.org";
+          package-manager-cache: false
+      - name: Enable the pinned pnpm version
+        run: corepack enable
+      - name: Validate release inputs
+        id: release
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: node scripts/validate-release-inputs.mjs
+      - name: Confirm dispatch and checkout use the release tag
+        env:
+          DISPATCH_REF: ${{ github.ref }}
+          DISPATCH_SHA: ${{ github.sha }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          test "${DISPATCH_REF}" = "refs/tags/${RELEASE_TAG}"
+          test "${DISPATCH_SHA}" = "$(git rev-parse HEAD)"
+          test "$(git rev-parse "refs/tags/${RELEASE_TAG}^{commit}")" = "$(git 
rev-parse HEAD)"
+          git merge-base --is-ancestor HEAD "$(git rev-parse 
refs/remotes/origin/main)"
+      - name: Confirm release advances the npm dist-tag
+        working-directory: ts-sdk
+        env:
+          NPM_TAG: ${{ inputs.npm_tag }}
+          RELEASE_TAG: ${{ inputs.tag }}
+        run: |
+          set -euo pipefail
+          error_file="${RUNNER_TEMP}/npm-view-error.log"
+          set +e
+          current_version="$(npm view apache-airflow-ts-sdk 
"dist-tags.${NPM_TAG}" 2>"${error_file}")"
+          view_status=$?
+          set -e
+          if [[ ${view_status} -ne 0 ]]; then
+            if grep -q "E404" "${error_file}"; then
+              current_version=""
+            else
+              cat "${error_file}" >&2
+              exit "${view_status}"
+            fi
+          fi
+          CURRENT_DIST_TAG_VERSION="${current_version}" node 
scripts/validate-release-inputs.mjs
+      - name: Verify package identity
+        working-directory: ts-sdk
+        env:
+          EXPECTED_VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          set -euo pipefail
+          test "$(node --print "require('./package.json').name")" = 
"apache-airflow-ts-sdk"
+          test "$(node --print "require('./package.json').version")" = 
"${EXPECTED_VERSION}"
+      - name: Install and test package
+        working-directory: ts-sdk
+        run: |
+          set -euo pipefail
+          pnpm install --frozen-lockfile
+          pnpm run lint
+          pnpm run format:check
+          pnpm run typecheck
+          pnpm test
+      - name: Create package tarball
+        id: package
+        working-directory: ts-sdk
+        env:
+          PACKAGE_FILE: ${{ steps.release.outputs.package_file }}
+          VERSION: ${{ steps.release.outputs.version }}
+        run: |
+          set -euo pipefail
+          artifact_dir="${RUNNER_TEMP}/ts-sdk-package"
+          mkdir -p "${artifact_dir}"
+          test -z "$(find "${artifact_dir}" -mindepth 1 -maxdepth 1 -print 
-quit)"
+          npm pack --pack-destination "${artifact_dir}"
+          artifact_path="${artifact_dir}/${PACKAGE_FILE}"
+          test -f "${artifact_path}"
+          test "$(find "${artifact_dir}" -maxdepth 1 -type f -name '*.tgz' | 
wc -l)" -eq 1
+          echo "artifact_name=ts-sdk-package-${VERSION}" >> "${GITHUB_OUTPUT}"
+          echo "sha256=$(sha256sum "${artifact_path}" | awk '{print $1}')" >> 
"${GITHUB_OUTPUT}"
+      - name: Upload package tarball
+        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a 
 # v7.0.1
+        with:
+          name: ${{ steps.package.outputs.artifact_name }}
+          path: ${{ runner.temp }}/ts-sdk-package/${{ 
steps.release.outputs.package_file }}
+          if-no-files-found: error
+          retention-days: 1
+
+  publish:
+    name: ${{ inputs.release_type == 'staged' && 'Stage release on npm' || 
'Publish formal release to npm' }}
+    needs: build
+    runs-on: ubuntu-latest
+    environment:
+      name: ${{ inputs.release_type == 'staged' && 'ts-sdk-npm-staged' || 
'ts-sdk-npm-formal' }}
+    permissions:
+      contents: read
+      id-token: write
+    steps:
+      - name: Set up Node.js
+        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020  # 
v7.0.0
+        with:
+          node-version: "24.19.0"
+          registry-url: "https://registry.npmjs.org";
+          package-manager-cache: false
+      - name: Check npm supports staged and trusted publishing
+        run: |
+          node --input-type=module --eval '
+            import { execFileSync } from "node:child_process";
+            const npmVersion = execFileSync("npm", ["--version"], { encoding: 
"utf8" });
+            const [major, minor] = npmVersion.split(".").map(Number);
+            if (major < 11 || (major === 11 && minor < 15)) process.exit(1);

Review Comment:
   Addressed in 9699ab65.



##########
ts-sdk/scripts/validate-release-inputs.mjs:
##########
@@ -0,0 +1,152 @@
+#!/usr/bin/env node
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import console from "node:console";
+import { appendFileSync, readFileSync } from "node:fs";
+import process from "node:process";
+import { URL, pathToFileURL } from "node:url";
+
+const PACKAGE_NAME = JSON.parse(
+  readFileSync(new URL("../package.json", import.meta.url), "utf8"),
+).name;
+const SEMVER_PATTERN =
+  
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?$/;
+const NPM_TAG_PATTERN = /^[a-z][a-z0-9._-]*$/;
+
+function parseVersion(version) {
+  const match = SEMVER_PATTERN.exec(version);
+  if (match === null) {
+    throw new Error(`Release version ${JSON.stringify(version)} is not valid 
SemVer`);
+  }
+  return {
+    version,
+    major: BigInt(match[1]),
+    minor: BigInt(match[2]),
+    patch: BigInt(match[3]),
+    prerelease: match[4]?.split(".") ?? [],
+  };
+}
+
+function compareIdentifiers(left, right) {
+  if (left === right) {
+    return 0;
+  }
+  const leftIsNumeric = /^\d+$/.test(left);
+  const rightIsNumeric = /^\d+$/.test(right);
+  if (leftIsNumeric && rightIsNumeric) {
+    return BigInt(left) < BigInt(right) ? -1 : 1;
+  }
+  if (leftIsNumeric) {
+    return -1;
+  }
+  if (rightIsNumeric) {
+    return 1;
+  }
+  return left < right ? -1 : 1;
+}
+
+function compareVersions(left, right) {
+  for (const field of ["major", "minor", "patch"]) {
+    if (left[field] !== right[field]) {
+      return left[field] < right[field] ? -1 : 1;
+    }
+  }
+  if (left.prerelease.length === 0 || right.prerelease.length === 0) {
+    return right.prerelease.length - left.prerelease.length;
+  }
+  const length = Math.max(left.prerelease.length, right.prerelease.length);
+  for (let index = 0; index < length; index += 1) {
+    const leftIdentifier = left.prerelease[index];
+    const rightIdentifier = right.prerelease[index];
+    if (leftIdentifier === undefined) {
+      return -1;
+    }
+    if (rightIdentifier === undefined) {
+      return 1;
+    }
+    const difference = compareIdentifiers(leftIdentifier, rightIdentifier);
+    if (difference !== 0) {
+      return difference;
+    }
+  }
+  return 0;
+}
+
+function getPrereleaseChannel(prerelease) {
+  return prerelease[0]?.match(/^[A-Za-z]+/)?.[0].toLowerCase();
+}
+
+export function validateReleaseInputs({ releaseTag, npmTag, 
currentDistTagVersion = "" }) {
+  if (!releaseTag.startsWith("ts-sdk/")) {
+    throw new Error("Release tag must have the form ts-sdk/<semver>");
+  }
+  const version = releaseTag.slice("ts-sdk/".length);
+  const parsedVersion = parseVersion(version);
+
+  if (!NPM_TAG_PATTERN.test(npmTag)) {
+    throw new Error(`npm tag ${JSON.stringify(npmTag)} is invalid`);
+  }
+  if (parsedVersion.prerelease.length === 0 && npmTag !== "latest") {
+    throw new Error("Stable releases must use the latest npm dist-tag");
+  }
+  if (parsedVersion.prerelease.length > 0) {
+    const channel = getPrereleaseChannel(parsedVersion.prerelease);
+    if (npmTag !== "next" && npmTag !== channel) {
+      const allowedTags = channel === undefined ? "next" : `${channel} or 
next`;

Review Comment:
   Addressed in e73bed82.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to