Skip to content

Commit

Permalink
Update Node.js Docker image and enhance npm publish workflow with unp…
Browse files Browse the repository at this point in the history
…ublish feature

Signed-off-by: avifenesh <[email protected]>
  • Loading branch information
avifenesh committed Nov 22, 2024
1 parent 0d5bc9f commit 09473f7
Show file tree
Hide file tree
Showing 3 changed files with 61 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
70 changes: 57 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 @@ -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
Expand All @@ -375,10 +382,47 @@ 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
# Set RELEASE_VERSION correctly
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
RELEASE_VERSION="${{ github.event.inputs.version }}"
else
RELEASE_VERSION="${GITHUB_REF#refs/tags/v}"
fi
echo "Release version for unpublishing: ${RELEASE_VERSION}"
# Unpublish base package
npm unpublish "@valkey/valkey-glide@${RELEASE_VERSION}" --force || true
# Process platform matrix
echo '${{ needs.load-platform-matrix.outputs.PLATFORM_MATRIX }}' > platform_matrix.json
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 < <(jq -r '.[] | "\(.NAMED_OS)\(.TARGET | test("musl") | if . then "-musl" else "" end)-\(.ARCH)"' platform_matrix.json)
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
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 09473f7

Please sign in to comment.