|
6 | 6 | types: |
7 | 7 | - opened |
8 | 8 | - edited |
9 | | - - labeled |
10 | | - - auto_merge_enabled |
11 | 9 | - synchronize |
12 | 10 | - reopened |
13 | | - - ready_for_review |
| 11 | + pull_request_target: |
| 12 | + types: |
| 13 | + - opened |
| 14 | + - edited |
| 15 | + - synchronize |
| 16 | + - reopened |
14 | 17 |
|
15 | 18 | pull_request_review: |
16 | 19 | types: |
17 | 20 | - submitted |
18 | 21 |
|
19 | | -env: |
20 | | - TOKEN: "${{ secrets.GITHUB_TOKEN }}" |
| 22 | +permissions: |
| 23 | + pull-requests: read |
21 | 24 |
|
22 | 25 | # Separate jobs can run concurrently |
23 | 26 | jobs: |
24 | 27 | prTitle: |
25 | 28 | name: Validate conventional commit format for title |
26 | 29 | runs-on: ubuntu-latest |
| 30 | + permissions: |
| 31 | + pull-requests: write |
| 32 | + contents: read |
27 | 33 |
|
28 | 34 | steps: |
29 | | - - uses: actions/checkout@v3 |
| 35 | + - uses: actions/checkout@v4 |
30 | 36 | with: |
31 | 37 | fetch-depth: 0 |
32 | | - |
33 | | - # https://github.com/wagoid/commitlint-github-action/issues/560#issuecomment-1277659864 |
34 | | - - run: rm tsconfig.json |
35 | | - |
36 | | - - uses: wagoid/commitlint-github-action@v5 |
37 | | - id: commitlint |
38 | | - continue-on-error: true |
| 38 | + - uses: actions/setup-node@v4 |
39 | 39 | with: |
40 | | - configFile: .commitlintrc.cjs |
| 40 | + node-version: 20 |
| 41 | + cache: npm |
| 42 | + - run: npm ci --prefer-offline |
| 43 | + - run: npm i @commitlint/load |
41 | 44 |
|
42 | | - - name: Validate conventional commit format for title |
43 | | - id: prTitle |
44 | | - if: ${{ steps.commitlint.outcome == 'failure' }} |
45 | | - |
46 | | - continue-on-error: true |
47 | | - with: |
48 | | - success-state: Title follows the conventional commit format. |
49 | | - failure-state: Please update the title to use conventional commit format. |
50 | | - context-name: conventional-pr-title |
51 | | - preset: '@commitlint/config-conventional@latest' |
52 | | - env: |
53 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + - id: prlint |
| 46 | + uses: kevintyj/prlint@v2 |
54 | 47 |
|
55 | | - - name: Format commitlint messages |
56 | | - id: format |
57 | | - if: ${{ steps.commitlint.outcome == 'failure' }} |
58 | | - uses: actions/github-script@v6 |
59 | | - with: |
60 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
61 | | - script: | |
62 | | - const results = ${{ steps.commitlint.outputs.results }}; |
63 | | - const titleGood = ${{ steps.prTitle.outputs.success }}; |
64 | | - const { format } = await import('${{ github.workspace }}/scripts/format-commitlint-messages.js'); |
65 | | - return format({ core, results, titleGood }); |
66 | | -
|
67 | | - - name: Notify PR |
68 | | - if: ${{ steps.commitlint.outcome == 'failure' && steps.prTitle.outputs.success == 'false' }} |
69 | | - id: comment |
| 48 | + - id: comment |
70 | 49 | uses: marocchino/sticky-pull-request-comment@v2 |
71 | 50 | with: |
72 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
73 | 51 | header: commitlint |
74 | 52 | message: | |
75 | | - ${{ steps.format.outputs.result }} |
| 53 | + ## ${{ steps.prlint.outputs.lint-status }} |
| 54 | +
|
| 55 | + <details><summary>More Info</summary> |
76 | 56 |
|
77 | | - - name: Fail Job on Error |
78 | | - if: ${{ steps.commitlint.outcome == 'failure' && steps.prTitle.outputs.success == 'false' }} |
79 | | - uses: actions/github-script@v6 |
| 57 | + ```json |
| 58 | + ${{ toJSON(fromJSON(steps.prlint.outputs.lint-details)) }} |
| 59 | + ``` |
| 60 | +
|
| 61 | + </details> |
| 62 | +
|
| 63 | + - uses: actions/github-script@v7 |
| 64 | + env: |
| 65 | + PR_TITLE_VALID: ${{ fromJSON(steps.prlint.outputs.lint-details).valid }} |
| 66 | + PR_LINT_STATUS: ${{ steps.prlint.outputs.lint-status }} |
80 | 67 | with: |
81 | 68 | script: | |
82 | | - core.setFailed("There were problems with this PR's commit messages") |
| 69 | + const { PR_LINT_STATUS, PR_TITLE_VALID } = process.env; |
| 70 | +
|
| 71 | + if (PR_TITLE_VALID.toString() !== 'true') |
| 72 | + core.setFailed(PR_LINT_STATUS); |
83 | 73 |
|
0 commit comments