|
| 1 | +# SPDX-FileCopyrightText: Copyright DB InfraGO AG |
| 2 | +# SPDX-License-Identifier: CC0-1.0 |
| 3 | + |
| 4 | +name: Commits |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +jobs: |
| 11 | + conventional-commits: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + concurrency: |
| 14 | + group: commit-check-pr-${{ github.event.pull_request.number }} |
| 15 | + cancel-in-progress: true |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + - name: Install commitlint |
| 21 | + run: npm install @commitlint/cli @commitlint/config-conventional |
| 22 | + - name: Validate commit messages |
| 23 | + id: conventional-commits |
| 24 | + env: |
| 25 | + SHA_FROM: ${{ github.event.pull_request.base.sha }} |
| 26 | + SHA_TO: ${{ github.event.pull_request.head.sha }} |
| 27 | + run: | |
| 28 | + delim="_EOF_$(uuidgen)" |
| 29 | + echo "validation-result<<$delim" >> "$GITHUB_OUTPUT" |
| 30 | + r=0 |
| 31 | + npx commitlint --from "$SHA_FROM" --to "$SHA_TO" >> "$GITHUB_OUTPUT" 2>&1 || r=$? |
| 32 | + echo "$delim" >> "$GITHUB_OUTPUT" |
| 33 | + exit $r |
| 34 | + - name: Find conventional commit comment on PR |
| 35 | + uses: peter-evans/find-comment@v3 |
| 36 | + if: always() && steps.conventional-commits.outcome == 'failure' |
| 37 | + id: fc |
| 38 | + with: |
| 39 | + issue-number: ${{ github.event.pull_request.number }} |
| 40 | + comment-author: 'github-actions[bot]' |
| 41 | + body-includes: conventional commit |
| 42 | + - name: Post comment if validation failed |
| 43 | + uses: peter-evans/create-or-update-comment@v4 |
| 44 | + if: always() && steps.conventional-commits.outcome == 'failure' |
| 45 | + with: |
| 46 | + comment-id: ${{ steps.fc.outputs.comment-id }} |
| 47 | + issue-number: ${{ github.event.pull_request.number }} |
| 48 | + edit-mode: replace |
| 49 | + body: | |
| 50 | + The pull request does not conform to the conventional commit specification. Please ensure that your commit messages follow the spec: <https://www.conventionalcommits.org/>. |
| 51 | + We also strongly recommend that you set up your development environment with pre-commit. |
| 52 | +
|
| 53 | + This is the commit validation log: |
| 54 | + ``` |
| 55 | + ${{ steps.conventional-commits.outputs.validation-result }} |
| 56 | + ``` |
| 57 | +
|
| 58 | + Here are some examples of valid commit messages: |
| 59 | + ``` |
| 60 | + feat(model): Add realized_states to State and Mode |
| 61 | + fix(aird): Prevent creating circles with r=0 |
| 62 | + docs(readme): Update project description |
| 63 | + ``` |
0 commit comments