fix: commitlint force push behaviour #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: ci | |
| on: | |
| workflow_dispatch: | |
| push: | |
| pull_request: | |
| jobs: | |
| commitlint: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "lts/*" | |
| # Local node_modules so "@..." in .commitlintrc.json resolves (global install does not). | |
| - name: Install commitlint | |
| run: npm install --no-package-lock @commitlint/cli@17 @commitlint/config-conventional@17 | |
| - if: github.event_name == 'pull_request' | |
| name: commitlint (pr) | |
| run: npx commitlint -V --from HEAD~${{ github.event.pull_request.commits }} | |
| - if: github.event_name == 'push' && !startsWith(github.ref, 'refs/tags') | |
| name: commitlint (push) | |
| # Prefer github.event.before so multi-commit pushes are all checked; if that ref is gone | |
| # (force push, or all-zero before on new branch), fall back to HEAD~1. | |
| run: | | |
| set -euo pipefail | |
| BEFORE="${{ github.event.before }}" | |
| if [[ "$BEFORE" =~ ^0+$ ]]; then | |
| npx commitlint -V --from HEAD~1 | |
| elif git rev-parse --verify "${BEFORE}^{commit}" >/dev/null 2>&1; then | |
| npx commitlint -V --from "$BEFORE" | |
| else | |
| npx commitlint -V --from HEAD~1 | |
| fi | |
| release: | |
| if: github.ref == 'refs/heads/main' | |
| needs: commitlint | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: write # for creating the gh release | |
| issues: write # for commenting on related issues | |
| pull-requests: write # for commenting on related pull-requests | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # semantic release needs all the history | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: "22" | |
| - run: sudo npm install --global conventional-changelog-conventionalcommits@9 semantic-release@25 | |
| - name: Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: semantic-release | |