diff --git a/.github/json_matrices/build-matrix.json b/.github/json_matrices/build-matrix.json index 5e10c38a37..0d0e7c10bb 100644 --- a/.github/json_matrices/build-matrix.json +++ b/.github/json_matrices/build-matrix.json @@ -33,7 +33,7 @@ "ARCH": "arm64", "TARGET": "aarch64-unknown-linux-musl", "RUNNER": ["self-hosted", "Linux", "ARM64"], - "IMAGE": "node:lts-alpine3.19", + "IMAGE": "node:lts-alpine", "CONTAINER_OPTIONS": "--user root --privileged --rm", "PACKAGE_MANAGERS": ["npm"], "languages": ["node"] @@ -44,7 +44,7 @@ "ARCH": "x64", "TARGET": "x86_64-unknown-linux-musl", "RUNNER": "ubuntu-latest", - "IMAGE": "node:lts-alpine3.19", + "IMAGE": "node:lts-alpine", "CONTAINER_OPTIONS": "--user root --privileged", "PACKAGE_MANAGERS": ["npm"], "languages": ["node"] diff --git a/.github/workflows/npm-cd.yml b/.github/workflows/npm-cd.yml index 8ff2936fbc..fdf5e71143 100644 --- a/.github/workflows/npm-cd.yml +++ b/.github/workflows/npm-cd.yml @@ -181,18 +181,22 @@ jobs: working-directory: ./node run: | npm pkg fix - set +e - # 2>&1 1>&3- redirects stderr to stdout and then redirects the original stdout to another file descriptor, - # effectively separating stderr and stdout. The 3>&1 at the end redirects the original stdout back to the console. - # https://github.com/npm/npm/issues/118#issuecomment-325440 - ignoring notice messages since currentlly they are directed to stderr - { npm_publish_err=$(npm publish --tag ${{ env.NPM_TAG }} --access public 2>&1 1>&3- | grep -Ev "notice|ExperimentalWarning") ;} 3>&1 - if [[ "$npm_publish_err" == *"You cannot publish over the previously published versions"* ]] - then - echo "Skipping publishing, package already published" - elif [[ ! -z "$npm_publish_err" ]] - then - echo "Failed to publish with error: ${npm_publish_err}" - exit 1 + set +e # Disable immediate exit on non-zero exit codes + + # Redirect stderr to stdout, filter out notices and warnings + { npm_publish_err=$(npm publish --tag "${NPM_TAG}" --access public --loglevel=error 2>&1 1>&3- | grep -Ev "notice|ExperimentalWarning|WARN") ;} 3>&1 + publish_exit_code=$? + + # Re-enable immediate exit + set -e + + if [[ $publish_exit_code -eq 0 ]]; then + echo "Package published successfully." + elif echo "$npm_publish_err" | grep -q "You cannot publish over the previously published versions"; then + echo "Skipping publishing, package already published." + elif [[ ! -z "$npm_publish_err" ]]; then + echo "Failed to publish with error: $npm_publish_err" + exit 1 fi env: NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} @@ -350,6 +354,9 @@ jobs: shell: bash working-directory: ./utils run: | + # Error on purpose to test the unpublishing + echo "Error on purpose to test the unpublishing" + exit 1 npm install npm install -g typescript npx tsc -p ./tsconfig.json @@ -375,10 +382,51 @@ jobs: npm install --no-save @valkey/valkey-glide@${{ env.NPM_TAG }} npm run test + - name: Unpublish packages on failure + if: ${{ always() }} && ${{ failure() }} + shell: bash + run: | + # Detect OS and install jq + if [[ "$OSTYPE" == "darwin"* ]]; then + brew install jq || true + elif command -v apk > /dev/null; then + apk add --no-cache jq + else + sudo apt-get update && sudo apt-get install -y jq + fi + if ${{ env.EVENT_NAME == 'workflow_dispatch' }}; then + echo "${{env.EVENT_NAME}}" + RELEASE_VERSION="${{ env.INPUT_VERSION }}" + else + RELEASE_VERSION=${GITHUB_REF:11} + fi + + echo "Tests failed, unpublishing packages..." + + # Unpublish the base package + npm unpublish @valkey/valkey-glide@${RELEASE_VERSION} --force || true + + # Save PLATFORM_MATRIX to a file + echo '${{ needs.load-platform-matrix.outputs.PLATFORM_MATRIX }}' > platform_matrix.json + + # Extract package names from platform matrix + jq -r '.[] | "\(.NAMED_OS)\(.TARGET | test("musl") | if . then "-musl" else "" end)-\(.ARCH)"' platform_matrix.json > package_names.txt + + # Loop over each package name and unpublish + while read -r pkg; do + package_name="@valkey/valkey-glide-${pkg}" + echo "Unpublishing $package_name@$${RELEASE_VERSION}" + npm unpublish ${package_name}@${RELEASE_VERSION} --force || true + done < package_names.txt + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + EVENT_NAME: ${{ github.event_name }} + INPUT_VERSION: ${{ github.event.inputs.version }} + # Reset the repository to make sure we get the clean checkout of the action later in other actions. # It is not required since in other actions we are cleaning before the action, but it is a good practice to do it here as well. - name: Reset repository - if: ${{ contains(matrix.build.RUNNER, 'self-hosted') }} + if: ${{ always() }} && ${{ contains(matrix.build.RUNNER, 'self-hosted') }} shell: bash run: | git reset --hard diff --git a/node/package.json b/node/package.json index cda3849de7..62f177898b 100644 --- a/node/package.json +++ b/node/package.json @@ -60,8 +60,8 @@ "semver": "^7.6.3", "ts-jest": "^29.2.5", "ts-node": "^10.9.2", - "typescript": "^5.5.4", - "uuid": "^11.0" + "typescript": "^5.6.3", + "uuid": "^11.0.3" }, "author": "Valkey GLIDE Maintainers", "license": "Apache-2.0",