Skip to content

Commit

Permalink
Node rc fixes + unpublish on failure mechanism (#2737)
Browse files Browse the repository at this point in the history
* Update Node.js Docker image and enhance npm publish workflow with unpublish feature

Signed-off-by: avifenesh <[email protected]>

* unpublishing a package owned by more than one cant be unpublised, hence the usage is deprecating

Signed-off-by: avifenesh <[email protected]>

---------

Signed-off-by: avifenesh <[email protected]>
  • Loading branch information
avifenesh authored and prateek-kumar-improving committed Nov 26, 2024
1 parent cb9ce08 commit 7d84045
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/json_matrices/build-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down
76 changes: 63 additions & 13 deletions .github/workflows/npm-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -375,10 +379,56 @@ jobs:
npm install --no-save @valkey/valkey-glide@${{ env.NPM_TAG }}
npm run test
- name: Deprecating packages on failure
if: ${{ failure() }}
shell: bash
env:
GH_EVENT_NAME: ${{ github.event_name }}
GH_EVENT_INPUT_VERSION: ${{ github.event.inputs.version }}
GH_REF: ${{ github.ref }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
PLATFORM_MATRIX: ${{ needs.load-platform-matrix.outputs.PLATFORM_MATRIX }}
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
# Set RELEASE_VERSION correctly using environment variables
if [[ "${GH_EVENT_NAME}" == "workflow_dispatch" ]]; then
RELEASE_VERSION="${GH_EVENT_INPUT_VERSION}"
else
RELEASE_VERSION="${GH_REF#refs/tags/v}"
fi
# Validate RELEASE_VERSION
if [[ ! "${RELEASE_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "Invalid release version format: ${RELEASE_VERSION}"
exit 1
fi
echo "Release version for Deprecating: ${RELEASE_VERSION}"
# Deprecating base package
npm deprecate "@valkey/valkey-glide@${RELEASE_VERSION}" "This version has been deprecated" --force || true
# Process platform matrix
echo "${PLATFORM_MATRIX}" > platform_matrix.json
while read -r pkg; do
package_name="@valkey/valkey-glide-${pkg}"
echo "Deprecating ${package_name}@${RELEASE_VERSION}"
npm deprecate "${package_name}@${RELEASE_VERSION}" "This version has been deprecated" --force || true
done < <(jq -r '.[] | "\(.NAMED_OS)\(.TARGET | test("musl") | if . then "-musl" else "" end)-\(.ARCH)"' platform_matrix.json)
# 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
Expand Down
4 changes: 2 additions & 2 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7d84045

Please sign in to comment.