Skip to content

Commit

Permalink
ci: skip publish when there is no update to package version
Browse files Browse the repository at this point in the history
  • Loading branch information
danbillson committed Feb 19, 2025
1 parent 194e328 commit 3be6861
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 78 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/publish-latest.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/publish-next.yml

This file was deleted.

55 changes: 55 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish

on:
push:
branches:
- main
- v1.X

jobs:
run-publish:
name: Run publish
runs-on: ubuntu-latest

permissions:
contents: read
actions: write

steps:
- name: Check out git repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'

- name: Install yarn dependencies
run: yarn install

- name: Build
run: yarn build

- name: Test
run: yarn test

- name: Check version and publish
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(node -p "require('./package.json').version")
# Check if version exists in npm registry
if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version &>/dev/null; then
echo "Version $CURRENT_VERSION already published, skipping"
exit 0
fi
if [[ "$CURRENT_VERSION" =~ (next) ]]; then
yarn publish:next
else
yarn publish:latest
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 comments on commit 3be6861

Please # to comment.