Skip to content

Commit e8fe48d

Browse files
authored
feat(commitlint): use step summaries for output and adjust comment format (#144)
1 parent b898590 commit e8fe48d

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

.github/workflows/pr-title-commitlint.yaml

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ on:
99

1010
comment-header:
1111
description: "Header line for the PR comment."
12-
default: ":black_nib: Commitlint PR Title"
12+
default: ":black_nib: PR Title Commitlint"
13+
type: string
14+
15+
comment-success:
16+
description: "Success message for the PR comment."
17+
default: ":heavy_check_mark: Lint success!"
18+
type: string
19+
20+
comment-error:
21+
description: "Error message for the PR comment."
22+
default: ":x: Lint error! Fix title before merging!"
1323
type: string
1424

1525
config:
@@ -50,7 +60,7 @@ jobs:
5060
shell: bash
5161
run: |
5262
set +e
53-
lint=$(echo "$TITLE" | npx commitlint --config="$CONFIG")
63+
lint=$(echo "$TITLE" | npx commitlint --config="$CONFIG" --help-url="$CONFIG")
5464
status=$?
5565
echo "$lint"
5666
printf "lint<<EOF\n%s\nEOF" "${lint}" >> "$GITHUB_OUTPUT"
@@ -59,6 +69,33 @@ jobs:
5969
TITLE: ${{ github.event.pull_request.title }}
6070
CONFIG: ${{ inputs.config }}
6171

72+
- name: create step summary on bad lint
73+
if: always() && steps.commitlint.outcome != 'success'
74+
shell: bash
75+
run: |
76+
printf "%s" "${SUMMARY}" >> "$GITHUB_STEP_SUMMARY"
77+
printf "COMMENT_BODY<<EOF\n%s\nEOF" "${SUMMARY}" >> "$GITHUB_ENV"
78+
env:
79+
# Note the intentional double spaces at the end of some lines. This is markdown.
80+
SUMMARY: |
81+
#### ${{ inputs.comment-header }} - ${{ inputs.comment-error }}
82+
Expected PR title to be conventional commit format: ie. `type(scope): summary`
83+
```
84+
${{ steps.commitlint.outputs.lint }}
85+
```
86+
Conventional Commits :open_book: [Docs](https://www.conventionalcommits.org/en/v1.0.0)
87+
Commitlint :file_cabinet: [Config](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/${{ inputs.config }}) :open_book: [Docs](https://commitlint.js.org/reference/rules)
88+
89+
- name: create step summary on good lint
90+
if: always() && steps.commitlint.outcome == 'success'
91+
shell: bash
92+
run: |
93+
printf "%s" "${SUMMARY}" >> "$GITHUB_STEP_SUMMARY"
94+
printf "COMMENT_BODY<<EOF\n%s\nEOF" "${SUMMARY}" >> "$GITHUB_ENV"
95+
env:
96+
SUMMARY: |
97+
#### ${{ inputs.comment-header }} - ${{ inputs.comment-success }}
98+
6299
- name: find pr comment
63100
uses: peter-evans/find-comment@v3
64101
if: always()
@@ -68,28 +105,15 @@ jobs:
68105
body-includes: ${{ inputs.comment-header }}
69106
comment-author: "github-actions[bot]"
70107

71-
- name: create or update pr comment on bad lint
72-
uses: peter-evans/create-or-update-comment@v4
73-
if: always() && steps.commitlint.outcome == 'failure'
74-
with:
75-
comment-id: ${{ steps.find-pr-comment.outputs.comment-id }}
76-
issue-number: ${{ github.event.pull_request.number }}
77-
edit-mode: replace
78-
body: |
79-
#### :x: ${{ inputs.comment-header }} - Fix title before merge!
80-
```
81-
${{ steps.commitlint.outputs.lint }}
82-
```
83-
84-
- name: create or update pr comment on successful lint
108+
- name: create or update pr comment
85109
uses: peter-evans/create-or-update-comment@v4
86-
if: always() && steps.commitlint.outcome == 'success'
110+
if: always() && (steps.commitlint.outcome == 'success' || steps.commitlint.outcome == 'failure')
87111
with:
88112
comment-id: ${{ steps.find-pr-comment.outputs.comment-id }}
89113
issue-number: ${{ github.event.pull_request.number }}
90114
edit-mode: replace
91115
body: |
92-
#### :heavy_check_mark: ${{ inputs.comment-header }} - Good Title
116+
${{ env.COMMENT_BODY }}
93117
94118
- name: add error label on bad lint
95119
uses: actions/github-script@v7.0.1

0 commit comments

Comments
 (0)