Skip to content

Commit

Permalink
Fix NPM Publish (#33)
Browse files Browse the repository at this point in the history
The NPM publish job was running even if we didn't bump the version. This
PR adds a check to the GHA job that ensures it only runs when the
version is manually bumped.
  • Loading branch information
ProfMoo authored May 10, 2024
1 parent 4d6f1fd commit 1bff45f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
79 changes: 40 additions & 39 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- 'package.json'
- "package.json"

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand All @@ -18,44 +18,45 @@ jobs:
id-token: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Get version from package.json
id: package_version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Check if tag exists
id: check_tag
run: |
git fetch --tags
if git rev-parse "v${{ steps.package_version.outputs.VERSION }}" >/dev/null 2>&1; then
echo "::set-output name=EXISTS::true"
fi
- name: Create Release
if: steps.check_tag.outputs.EXISTS != 'true'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package_version.outputs.VERSION }}
name: Release v${{ steps.package_version.outputs.VERSION }}
draft: false
prerelease: false
generate_release_notes: true
make_latest: true

- name: Setup node
uses: actions/setup-node@v4
with:
- name: Checkout code
uses: actions/checkout@v4

- name: Get version from package.json
id: package_version
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT

- name: Check if tag exists
id: check_tag
run: |
git fetch --tags
if git rev-parse "v${{ steps.package_version.outputs.VERSION }}" >/dev/null 2>&1; then
echo "::set-output name=EXISTS::true"
fi
- name: Create Release
if: steps.check_tag.outputs.EXISTS != 'true'
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package_version.outputs.VERSION }}
name: Release v${{ steps.package_version.outputs.VERSION }}
draft: false
prerelease: false
generate_release_notes: true
make_latest: true

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Publish to NPM
run: |
npm install -g npm@^9.5.0
npm ci
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to NPM
if: steps.check_tag.outputs.EXISTS != 'true'
run: |
npm install -g npm@^9.5.0
npm ci
npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/staking-client-library-ts",
"version": "0.7.1",
"version": "0.8.1",
"description": "Coinbase Staking API Typescript Library",
"repository": "https://github.com/coinbase/staking-client-library-ts.git",
"license": "Apache-2.0",
Expand Down

0 comments on commit 1bff45f

Please sign in to comment.