Skip to content

Commit 12c00a7

Browse files
author
Dan Billson
authored
ci: skip publish if version already exists (#113)
* ci: skip publish if version already exists * ci: add package name to npm view
1 parent 12e2409 commit 12c00a7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

.github/workflows/publish.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/setup-node@v4
2424
with:
2525
node-version: lts/*
26-
cache: "yarn"
26+
cache: 'yarn'
2727
registry-url: 'https://registry.npmjs.org'
2828

2929
- name: Install yarn dependencies
@@ -35,13 +35,21 @@ jobs:
3535
- name: Test
3636
run: yarn test
3737

38-
- name: Publish
38+
- name: Check version and publish
3939
run: |
40-
VERSION=$(node -p "require('./package.json').version" )
41-
if [[ "$VERSION" =~ (rc) ]]; then
40+
PACKAGE_NAME=$(node -p "require('./package.json').name")
41+
CURRENT_VERSION=$(node -p "require('./package.json').version")
42+
43+
# Check if version exists in npm registry
44+
if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version &>/dev/null; then
45+
echo "Version $CURRENT_VERSION already published, skipping"
46+
exit 0
47+
fi
48+
49+
if [[ "$CURRENT_VERSION" =~ (rc) ]]; then
4250
yarn publish:rc
4351
else
4452
yarn publish:latest
4553
fi
4654
env:
47-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
55+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)