diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 10da471..4c4f575 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,7 +4,7 @@ on: branches: - main pull_request: - workflow_dispatch: null + workflow_dispatch: jobs: build: runs-on: ubuntu-latest @@ -23,7 +23,20 @@ jobs: registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm run prepublishOnly - - run: npm publish --access public + - name: Check if version is already published + id: version-check if: github.event_name != 'pull_request' + run: | + PKG_NAME=$(node -p "require('./package.json').name") + PKG_VERSION=$(node -p "require('./package.json').version") + if npm view "$PKG_NAME@$PKG_VERSION" version > /dev/null 2>&1; then + echo "Version $PKG_VERSION of $PKG_NAME is already published, skipping publish." + echo "should-publish=false" >> "$GITHUB_OUTPUT" + else + echo "Version $PKG_VERSION of $PKG_NAME is new, will publish." + echo "should-publish=true" >> "$GITHUB_OUTPUT" + fi + - run: npm publish --access public + if: github.event_name != 'pull_request' && steps.version-check.outputs.should-publish == 'true' env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}