Skip to content

chore(ci): skip prepack during npm publish to avoid double build #45

chore(ci): skip prepack during npm publish to avoid double build

chore(ci): skip prepack during npm publish to avoid double build #45

Workflow file for this run

name: CI
on:
push:
branches: ['main']
pull_request:
branches: ['main']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
id-token: write
jobs:
check:
name: Lint, Format & Test
runs-on: ubuntu-latest
# Skip release commits pushed by the release workflow
if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --no-fund
- name: Run format check
run: npm run format:check
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
build:
name: Build
runs-on: ubuntu-latest
needs: [check]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --no-fund
- name: Build
run: npm run build:only
release:
name: Release
runs-on: ubuntu-latest
needs: [build]
# Only release on push to main, not on PRs
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install git-cliff
uses: kenji-miyake/setup-git-cliff@v2
- name: Determine next version
id: version
run: |
NEXT=$(git-cliff --bumped-version 2>/dev/null)
CURRENT=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ "$NEXT" = "$CURRENT" ]; then
echo "No version bump needed"
echo "bump=false" >> "$GITHUB_OUTPUT"
else
echo "Next version: $NEXT"
echo "bump=true" >> "$GITHUB_OUTPUT"
echo "version=$NEXT" >> "$GITHUB_OUTPUT"
fi
- name: Setup Node.js
if: steps.version.outputs.bump == 'true'
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: package-lock.json
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
if: steps.version.outputs.bump == 'true'
run: npm ci --prefer-offline --no-audit --no-fund
- name: Build
if: steps.version.outputs.bump == 'true'
run: npm run build:only
- name: Bump package.json version
if: steps.version.outputs.bump == 'true'
run: npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
- name: Generate changelog
if: steps.version.outputs.bump == 'true'
run: git-cliff --tag "${{ steps.version.outputs.version }}" -o CHANGELOG.md
- name: Commit and tag
if: steps.version.outputs.bump == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json CHANGELOG.md
git commit -m "chore(release): ${{ steps.version.outputs.version }}"
git tag -a "${{ steps.version.outputs.version }}" -m "${{ steps.version.outputs.version }}"
git push origin main --follow-tags
- name: Publish to npm
if: steps.version.outputs.bump == 'true'
run: npm publish --provenance --access public --ignore-scripts
- name: Generate release notes
if: steps.version.outputs.bump == 'true'
run: git-cliff --latest --strip header > RELEASE_NOTES.md
- name: Create GitHub Release
if: steps.version.outputs.bump == 'true'
run: gh release create "${{ steps.version.outputs.version }}" --title "${{ steps.version.outputs.version }}" --notes-file RELEASE_NOTES.md
env:
GH_TOKEN: ${{ github.token }}