# This workflow is responsible for the continuous deployment of the GLIDE project to NPM. name: NPM - Continuous Deployment on: pull_request: paths: - .github/json_matrices/** - .github/workflows/npm-cd.yml push: tags: - "v*.*.*" # e.g. v1.2.3, v1.2.3-rc1 workflow_dispatch: inputs: version: description: "The release version of GLIDE, formatted as *.*.* or *.*.*-rc*" required: true publish: description: "Publish to NPM" required: true type: boolean default: false concurrency: group: node-cd-${{ github.head_ref || github.ref }}-${{ toJson(inputs) }} cancel-in-progress: true permissions: id-token: write contents: read jobs: get-build-parameters: runs-on: ubuntu-24.04 environment: AWS_ACTIONS outputs: release_version: ${{ steps.get-params.outputs.release_version }} npm_tag: ${{ steps.get-params.outputs.npm_tag }} platform_matrix: ${{ steps.load-platform-matrix.outputs.platform_matrix }} should_publish: ${{ steps.get-params.outputs.should_publish }} steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Determine event type id: event-check shell: bash env: GH_EVENT_NAME: ${{ github.event_name }} GH_REF: ${{ github.ref }} run: | echo "Event: $GH_EVENT_NAME Ref: $GH_REF" echo "event_name=$GH_EVENT_NAME" >> $GITHUB_OUTPUT echo "ref=$GH_REF" >> $GITHUB_OUTPUT - name: Handle pull request event id: pull-request-params if: steps.event-check.outputs.event_name == 'pull_request' shell: bash run: | RELEASE="255.255.255" SHOULD_PUB="false" echo "release_version=$RELEASE" >> $GITHUB_OUTPUT echo "should_publish=$SHOULD_PUB" >> $GITHUB_OUTPUT echo "Pull request detected - using development version $RELEASE" - name: Handle workflow dispatch event id: workflow-dispatch-params if: steps.event-check.outputs.event_name == 'workflow_dispatch' shell: bash env: INPUT_VER: ${{ github.event.inputs.version }} INPUT_PUB: ${{ github.event.inputs.publish }} run: | # Validate version exists if [[ -z "$INPUT_VER" ]]; then echo "::error::Version input is required for manual workflow runs"; exit 1 fi # Validate version format (semver) if [[ ! "$INPUT_VER" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then echo "::error::Invalid version format: '$INPUT_VER'. Must be X.Y.Z or X.Y.Z-rcN"; exit 1 fi # All good - set variables RELEASE="$INPUT_VER" SHOULD_PUB="$INPUT_PUB" echo "release_version=$RELEASE" >> $GITHUB_OUTPUT echo "should_publish=$SHOULD_PUB" >> $GITHUB_OUTPUT echo "Manual workflow run - using version $RELEASE (publish=$SHOULD_PUB)" - name: Handle tag push event id: tag-push-params if: steps.event-check.outputs.event_name == 'push' && startsWith(steps.event-check.outputs.ref, 'refs/tags/v') shell: bash run: | if [[ "${{ steps.event-check.outputs.ref }}" =~ ^refs/tags/v([0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?)$ ]]; then RELEASE="${BASH_REMATCH[1]}" SHOULD_PUB="true" echo "release_version=$RELEASE" >> $GITHUB_OUTPUT echo "should_publish=$SHOULD_PUB" >> $GITHUB_OUTPUT echo "Tag push detected - using version $RELEASE from tag" else echo "::error::Invalid tag format. Expected vX.Y.Z or vX.Y.Z-rcN"; exit 1 fi - name: Determine npm tag id: determine-npm-tag shell: bash env: RELEASE: ${{ steps.pull-request-params.outputs.release_version || steps.workflow-dispatch-params.outputs.release_version || steps.tag-push-params.outputs.release_version }} run: | # npm-tag logic - simple latest/next determination if [[ "$RELEASE" == *-rc* ]]; then # Any release candidate version gets "next" tag TAG="next" else # Regular releases get "latest" tag TAG="latest" fi echo "Using npm tag: $TAG" echo "npm_tag=$TAG" >> $GITHUB_OUTPUT - name: Consolidate build parameters id: get-params shell: bash env: RELEASE_VERSION: ${{ steps.pull-request-params.outputs.release_version || steps.workflow-dispatch-params.outputs.release_version || steps.tag-push-params.outputs.release_version }} NPM_TAG: ${{ steps.determine-npm-tag.outputs.npm_tag }} SHOULD_PUBLISH: ${{ steps.pull-request-params.outputs.should_publish || steps.workflow-dispatch-params.outputs.should_publish || steps.tag-push-params.outputs.should_publish }} run: | echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT echo "npm_tag=$NPM_TAG" >> $GITHUB_OUTPUT echo "should_publish=$SHOULD_PUBLISH" >> $GITHUB_OUTPUT echo "Final build parameters:" echo "- Version: $RELEASE_VERSION" echo "- NPM Tag: $NPM_TAG" echo "- Publish: $SHOULD_PUBLISH" - name: Load Platform Matrix id: load-platform-matrix shell: bash run: | # Filter entries with npm in PACKAGE_MANAGERS and use CD_RUNNER if available, replace "ephemeral" with "persistent" in RUNNER. # x86_64-apple-darwin builds on CD_RUNNER (macos-15, arm64) but tests on macos-15-intel: npm resolves the native package by the runner arch, so testing on arm64 would validate the wrong build. export PLATFORM_MATRIX=$(jq 'map( select(.PACKAGE_MANAGERS != null and (.PACKAGE_MANAGERS | contains(["npm"]))) | .RUNNER = ( if (.CD_RUNNER != null) then .CD_RUNNER elif (.RUNNER != null and (.RUNNER | type != "array")) then .RUNNER else "ubuntu-24.04" end ) | .build_type = ( if (.TARGET | contains("musl")) then "musl" elif (.TARGET | contains("gnu")) then "gnu" elif (.TARGET | contains("windows")) then "windows" else "mac" end ) | if .TARGET == "x86_64-apple-darwin" then .["test-runner"] = "macos-15-intel" else . end )' < .github/json_matrices/build-matrix.json | jq -c .) echo "platform_matrix=${PLATFORM_MATRIX}" >> $GITHUB_OUTPUT echo "Platform matrix loaded: ${PLATFORM_MATRIX}" build-native-modules: needs: [get-build-parameters] strategy: matrix: include: ${{ fromJson(needs.get-build-parameters.outputs.platform_matrix) }} fail-fast: false runs-on: ${{ matrix.RUNNER }} name: Build for ${{ matrix.TARGET }} (${{ matrix.build_type }}) steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: latest - name: Cache cargo registry uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: | ~/.cargo ~/.napi-rs ./target key: ${{ matrix.TARGET }}-cargo-cache restore-keys: | ${{ matrix.TARGET }}-cargo-cache cargo-cache # We don't use the common action for installing Rust because of the many targets; # caching is more efficient this way. - name: Install Rust with the required target uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1 with: toolchain: stable targets: ${{ matrix.TARGET }} - name: Install protoc (protobuf) uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3 with: version: "25.1" repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Install platform dependencies if: ${{ contains(matrix.TARGET, 'linux') }} shell: bash run: | if [[ "${{ matrix.TARGET }}" == *"linux"* ]]; then sudo apt update sudo apt install -y gcc pkg-config openssl libssl-dev # Install zig via direct binary download (works on all runners without snap/pip) ZIG_VERSION="0.13.0" ZIG_ARCH="$(uname -m)" curl -sSL "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ZIG_ARCH}-${ZIG_VERSION}.tar.xz" | sudo tar -xJ -C /usr/local sudo ln -sf "/usr/local/zig-linux-${ZIG_ARCH}-${ZIG_VERSION}/zig" /usr/local/bin/zig fi - name: Build Native Module shell: bash working-directory: ./node/rust-client env: RELEASE_VERSION: ${{ needs.get-build-parameters.outputs.release_version }} # Reported as lib-ver in CLIENT SETINFO; overrides the non-forced "unknown" in .cargo/config.toml. GLIDE_VERSION: ${{ needs.get-build-parameters.outputs.release_version }} run: | mkdir -p ../build-ts npm ci # napi build bakes this version into native.js; it must match the published platform packages. npm pkg set version="${RELEASE_VERSION}" if [[ "${{ matrix.OS }}" == "windows" ]]; then # Windows: native build, no cross-compilation needed npx napi build --release --strip --platform --target "${{ matrix.TARGET }}" \ --js ../build-ts/native.js --dts ../build-ts/native.d.ts \ --js-package-name @valkey/valkey-glide elif [[ "${{ matrix.TARGET }}" == *"gnu"* ]]; then # Linux GNU: use cargo-zigbuild for cross-compilation npm run build:release:gnu elif [[ "${{ matrix.TARGET }}" == "aarch64-apple-darwin" ]]; then # macOS ARM: native build on arm64 runner, no --target needed npx napi build --release --strip --platform \ --js ../build-ts/native.js --dts ../build-ts/native.d.ts \ --js-package-name @valkey/valkey-glide $npm_config_build_flags else # macOS x86 or musl: may need zig for cross-compilation additional_param="" if [[ "${{ matrix.build_type }}" == "musl" ]]; then additional_param="--cross-compile" fi npx napi build --platform --release $additional_param --strip \ --target "${{ matrix.TARGET }}" \ --js ../build-ts/native.js --dts ../build-ts/native.d.ts \ --js-package-name @valkey/valkey-glide $npm_config_build_flags fi mkdir -p ../${{ matrix.TARGET }} cp -r *.node ../${{ matrix.TARGET }}/ echo "Built native module for ${{ matrix.TARGET }}:" ls -la ../${{ matrix.TARGET }}/ - name: Smoke test native module if: ${{ matrix.OS != 'windows' }} working-directory: ./node run: file "${{ matrix.TARGET }}"/*.node | grep -qi "shared object\|dynamic\|mach-o" # Upload the native .node modules as artifacts - name: Upload Native Modules uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 with: name: bindings-${{ matrix.TARGET }}-${{ matrix.RUNNER }} path: ./node/${{ matrix.TARGET }} retention-days: 1 if-no-files-found: error # We want to use the native.js and native.d.ts files in the base package, but we don't have the glide dir yet so we upload them as artifacts - name: Upload Module js files uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 if: ${{ matrix.TARGET == 'x86_64-unknown-linux-gnu' }} with: name: js-files-${{ github.run_id }} path: | ./node/build-ts/native.js ./node/build-ts/native.d.ts retention-days: 1 if-no-files-found: error prepare-and-publish: environment: AWS_ACTIONS if: github.repository_owner == 'valkey-io' && needs.get-build-parameters.outputs.should_publish == 'true' needs: [get-build-parameters, build-native-modules] runs-on: ubuntu-24.04 outputs: release_package_artifact_name: "release-packages-${{ github.run_id }}" steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Create Build Directory shell: bash run: | # Create a build directory js, and d.ts mkdir -p ./node/build-ts # Put the native.js and native.d.ts files in the src directory - name: Download Module js files uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: js-files-${{ github.run_id }} path: ./node/build-ts # Download all native modules - name: Download all native modules uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: path: ./node/artifacts # Setup Node.js for publishing to NPM and caching - name: Setup Node.js with npm cache uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: latest registry-url: "https://registry.npmjs.org" scope: "@valkey" cache: "npm" cache-dependency-path: node/package.json # Install dependencies for the base package - name: Install dependencies working-directory: ./node shell: bash run: | npm ci # Setup npm package directories using NAPI-RS artifacts command - name: Setup npm package directories working-directory: ./node shell: bash run: | # Ensure npm directory exists with base glide package mkdir -p ./npm/glide # List downloaded native modules (initial structure after download) echo "Downloaded native modules (initial structure):" find ./artifacts -type f -name "*.node" -print | sort # Copy LICENSE and README to base package cp ../LICENSE ./npm/glide/ cp ./README.md ./npm/glide/ # Use NAPI artifacts command to manage native module distribution echo "Running NAPI artifacts command to copy native modules..." npm run artifacts # Add LICENSE and README to each platform package echo "Adding LICENSE and README to platform packages..." for dir in ./npm/*/; do if [[ "$dir" != "./npm/glide/" ]]; then platform_dir=$(basename "$dir") echo "Adding files to $platform_dir package..." cp ../LICENSE "$dir" cp ./README.md "$dir" fi done # Show the final directory structure echo "Final npm directory structure:" find ./npm -type f | sort # Build TypeScript for base package with optimized settings - name: Build TypeScript working-directory: ./node shell: bash run: | # Generate protobuf definitions npm run build-protobuf # Build TypeScript with optimized settings - preserving documentation echo "Building TypeScript with optimizations..." npx tsc --sourceMap false --declarationMap false --stripInternal --pretty --declaration # Check the build output echo "TypeScript build complete. Generated files:" find ./build-ts -type f | wc -l du -sh ./build-ts # Copy necessary files to npm/glide directory - name: Prepare base package working-directory: ./node shell: bash run: | mkdir -p ./npm/glide/build-ts cp -r ./build-ts/* ./npm/glide/build-ts/ cp ../LICENSE ./npm/glide/ cp ./README.md ./npm/glide/ cp ./package.json ./npm/glide/package.json # Set version for base package - name: Set package versions shell: bash working-directory: ./node env: NAPI_RS_VERSION_FROM_TAG: ${{ needs.get-build-parameters.outputs.release_version }} run: | echo "Setting version in base package using sed..." cd ./npm/glide sed -i 's/"version": "0\.0\.0"/"version": "'"${NAPI_RS_VERSION_FROM_TAG}"'"/' package.json echo "Base package version is now: $(jq -r .version package.json)" # Run napi prepublish explicitly from node/ before npm publish. # This must run from the project root (node/) — not from node/npm/glide/ — # because napi v3 enforces a workspace boundary check that requires a # workspace marker (workspaces field in package.json) to be discoverable # by walking up from the package directory. Running from node/npm/glide/ # (the npm lifecycle cwd) pins the discovery root to that directory, # making the walk impossible. See: napi-rs/napi-rs#2571 - name: Run napi prepublish if: ${{ needs.get-build-parameters.outputs.should_publish == 'true' }} shell: bash working-directory: ./node env: NAPI_RS_VERSION_FROM_TAG: ${{ needs.get-build-parameters.outputs.release_version }} # napi prepublish has no --tag flag; set the dist-tag via npm config env instead. npm_config_tag: ${{ needs.get-build-parameters.outputs.npm_tag }} run: | node_modules/.bin/napi prepublish \ --package-json-path npm/glide/package.json \ --npm-dir npm \ -t npm \ --no-gh-release # Publish the base package. napi prepublish has already been run in the # preceding step to inject optionalDependencies and version platform packages. - name: Publish packages if: ${{ needs.get-build-parameters.outputs.should_publish == 'true' }} shell: bash working-directory: ./node/npm/glide env: NPM_TAG: ${{ needs.get-build-parameters.outputs.npm_tag }} NPM_CONFIG_PROVENANCE: true run: | package_name=$(cat package.json | jq -r .name) version=$(cat package.json | jq -r .version) echo "Publishing base package ${package_name}@${version} with tag ${NPM_TAG}" npm publish --tag ${NPM_TAG} --access public --provenance --scope=@valkey # Check if the publish was successful if [ $? -ne 0 ]; then echo "::error::Base package publish failed"; exit 1 fi echo "Packages published successfully" test-published-release: needs: [get-build-parameters, prepare-and-publish] # Only run tests if the publish was successful if: needs.get-build-parameters.outputs.should_publish == 'true' strategy: matrix: include: ${{ fromJson(needs.get-build-parameters.outputs.platform_matrix) }} # One platform's failure (e.g. a registry propagation miss) must not cancel the others' validation. fail-fast: false runs-on: ${{ matrix.test-runner || matrix.RUNNER }} container: image: ${{ matrix.IMAGE || ''}} options: ${{ matrix.CONTAINER_OPTIONS || 'none' }} name: Test & Cleanup on ${{ matrix.TARGET }} steps: - name: Setup musl on Linux if: ${{ matrix.build_type == 'musl' }} shell: sh run: | apk update apk add bash git python3 jq - name: Checkout (via action) if: ${{ !(matrix.TARGET == 'aarch64-unknown-linux-musl') }} uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - name: Checkout-action manually repository for musl on ARM64 if: ${{ matrix.TARGET == 'aarch64-unknown-linux-musl' }} shell: bash run: | # First, clone the repository git clone https://github.com/${{ github.repository }} $GITHUB_WORKSPACE cd $GITHUB_WORKSPACE # Now we can run further git commands git config --global --add safe.directory $GITHUB_WORKSPACE git fetch origin ${{ github.sha }} git checkout ${{ github.sha }} git clean -xdf git reset --hard - name: Setup Node.js if: ${{ !(matrix.build_type == 'musl') }} uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: latest - name: Install Valkey shell: bash run: | # Install Valkey (preferred) or Redis as fallback if [[ "${{ matrix.build_type }}" == "gnu" ]]; then echo "Installing Valkey on GNU/Linux..." sudo apt update sudo apt install -y valkey || { echo "Valkey not found in default repos, trying alternative source..." curl -fsSL https://packages.redis.io/valkey/setup-valkey | sudo bash - sudo apt install -y valkey || { echo "Falling back to Redis..." sudo apt install -y redis-server } } elif [[ "${{ matrix.build_type }}" == "musl" ]]; then echo "Installing Valkey on Alpine Linux..." apk update apk add --no-cache valkey || apk add --no-cache redis apk add --no-cache valkey-cli || apk add --no-cache redis-cli elif [[ "${{ matrix.build_type }}" == "mac" ]]; then echo "Installing Valkey on macOS..." # Homebrew 6 exits non-zero on Intel macOS even when the install succeeds (#6976), and a # `|| brew install redis` fallback then fails on the conflicting redis-* binaries. Ignore the # exit code and rely on the server check below. Skipping auto-update and dependency upgrades # keeps Homebrew from rebuilding outdated formulae from source on Intel. HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_UPGRADE=1 brew install valkey || echo "::warning::brew install valkey exited non-zero; checking for valkey-server" elif [[ "${{ matrix.build_type }}" == "windows" ]]; then echo "Windows target tested via CodeBuild - skipping local Valkey install" exit 0 else echo "::error::Unsupported target: ${{ matrix.TARGET }} (build_type: ${{ matrix.build_type }})"; exit 1 fi # Verify installation - prefer valkey-server over redis-server if command -v valkey-server &> /dev/null; then echo "✓ Valkey server is available" elif command -v redis-server &> /dev/null; then echo "✓ Redis server is available (fallback)" else echo "::error::Neither Valkey nor Redis server found"; exit 1 fi - name: Run utils/node Tests if: ${{ matrix.build_type != 'windows' }} working-directory: utils/release-candidate-testing/node run: | # Install the exact version this workflow just published, NOT the dist-tag # (latest/next). The dist-tag pointer itself propagates across npm edges with lag, # so installing by tag can resolve the previous release and pass without ever # exercising the newly published package. # # The platform-specific optional dependency (e.g. @valkey/valkey-glide-linux-x64-gnu) # can also lag behind the base package on the npm registry for a short window right # after publish. When that happens npm silently skips the optional dependency and the # test fails with "Cannot find module". Retry the install until the native module # resolves, and assert the installed version matches the published version. RELEASE_VERSION="${{ needs.get-build-parameters.outputs.release_version }}" # 20 x 15s = ~5 min: npm propagation has taken longer than the old ~60s window (2.6.0-rc2, rc3). MAX_ATTEMPTS=20 DELAY=15 for attempt in $(seq 1 "$MAX_ATTEMPTS"); do rm -rf node_modules package-lock.json # The install itself is what waits on registry propagation: when the exact # version is not visible on an npm edge yet, `npm install` exits non-zero # (ETARGET/404). Guard it with `if` so that (under the default `set -e` shell) # a transient miss is retried instead of aborting the step on the first attempt. # --prefer-online: otherwise npm answers retries from its local cache (packument # max-age=300) and keeps missing a version published after the first attempt (2.6.0-rc4). if npm install "@valkey/valkey-glide@${RELEASE_VERSION}" --save --prefer-online; then # Read the version from the installed package.json on disk. The package's # "exports" map only exposes ".", so require("@valkey/valkey-glide/package.json") # would throw ERR_PACKAGE_PATH_NOT_EXPORTED; read the file directly instead. INSTALLED_VERSION=$(jq -r .version node_modules/@valkey/valkey-glide/package.json 2>/dev/null || true) if [ "${INSTALLED_VERSION}" = "${RELEASE_VERSION}" ] && node -e "require('@valkey/valkey-glide')"; then echo "Version ${RELEASE_VERSION} installed and native module resolved on attempt ${attempt}." break fi else INSTALLED_VERSION="" fi if [ "${attempt}" -eq "${MAX_ATTEMPTS}" ]; then echo "::error::@valkey/valkey-glide@${RELEASE_VERSION} not fully installable after ${MAX_ATTEMPTS} attempts (installed version: '${INSTALLED_VERSION:-none}')." exit 1 fi echo "Attempt ${attempt}/${MAX_ATTEMPTS}: version '${INSTALLED_VERSION:-none}' / native module not resolvable yet (likely npm registry propagation). Retrying in ${DELAY}s..." sleep "${DELAY}" done # Smoke test NAPI version check NAPI_RS_ENFORCE_VERSION_CHECK=1 node -e "require('@valkey/valkey-glide')" npm run build:utils npm test cleanup-artifacts: needs: [test-published-release, get-build-parameters] if: always() && needs.get-build-parameters.outputs.should_publish == 'true' runs-on: ubuntu-24.04 steps: - name: Delete artifacts uses: geekyeggo/delete-artifact@54ab544f12cdb7b71613a16a2b5a37a9ade990af # v2 with: name: | bindings-* js-files-${{ github.run_id }} failOnError: false deprecate-on-failure: needs: [test-published-release, get-build-parameters] if: failure() && needs.get-build-parameters.outputs.should_publish == 'true' runs-on: ubuntu-24.04 steps: - name: Setup Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: latest registry-url: "https://registry.npmjs.org" scope: "@valkey" - name: Deprecate Published Packages run: | echo "Deprecating packages due to failure…" VERSION="${{ needs.get-build-parameters.outputs.release_version }}" DEPRECATION_MESSAGE="This version (${VERSION}) was part of a failed release process and should not be used. It may be removed in the future." # Function to attempt deprecation with retries attempt_deprecate() { local package_spec="$1" local message="$2" local retries=5 local delay=10 # seconds echo "Attempting to deprecate ${package_spec}..." for i in $(seq 1 $retries); do if npm deprecate "${package_spec}" "${message}"; then echo "Successfully deprecated ${package_spec}." return 0 else echo "Attempt $i of $retries failed for ${package_spec}. Retrying in ${delay} seconds..." sleep $delay fi done echo "Note: Could not deprecate ${package_spec} after $retries attempts (it might not have been published or was already deprecated/unpublished)." return 1 } # Main package attempt_deprecate "@valkey/valkey-glide@${VERSION}" "${DEPRECATION_MESSAGE}" # Platform packages MATRIX_JSON='${{ needs.get-build-parameters.outputs.platform_matrix }}' # Validate JSON before processing if ! echo "$MATRIX_JSON" | jq -e . > /dev/null 2>&1; then echo "Warning: Invalid platform matrix JSON, unable to deprecate platform packages." # Optionally exit 1 here if this should be a hard failure, # or exit 0 to allow other cleanup steps to run. exit 0 fi echo "Processing platform packages for deprecation..." echo "$MATRIX_JSON" | jq -c '.[]' | while read -r target_json_line; do if [[ -z "$target_json_line" ]]; then echo "Warning: Skipping empty line from matrix JSON." continue fi # Derive the napi-rs platform string directly from the Rust target triple. # This mirrors SysToNodePlatform + CpuToNodeArch in napi-rs cli/src/utils/target.ts # and avoids the NAMED_OS mismatch where "windows" != napi-rs's "win32". target=$(echo "$target_json_line" | jq -r '.TARGET // empty') if [[ -z "$target" ]]; then echo "Warning: No TARGET field in matrix object, skipping. Object: $target_json_line" continue fi case "$target" in x86_64-unknown-linux-gnu) platform="linux-x64-gnu" ;; aarch64-unknown-linux-gnu) platform="linux-arm64-gnu" ;; x86_64-unknown-linux-musl) platform="linux-x64-musl" ;; aarch64-unknown-linux-musl) platform="linux-arm64-musl" ;; x86_64-apple-darwin) platform="darwin-x64" ;; aarch64-apple-darwin) platform="darwin-arm64" ;; x86_64-pc-windows-msvc) platform="win32-x64-msvc" ;; *) echo "Warning: Unknown target triple '$target', cannot form package name. Skipping." continue ;; esac package_name="@valkey/valkey-glide-${platform}" attempt_deprecate "${package_name}@${VERSION}" "${DEPRECATION_MESSAGE}" done echo "Finished deprecation attempts for platform packages."