|
58 | 58 |
|
59 | 59 | - name: Check PR Title |
60 | 60 | id: check_title |
| 61 | + env: |
| 62 | + PR_TITLE: ${{ github.event.pull_request.title }} |
61 | 63 | run: | |
62 | | - PR_TITLE="${{ github.event.pull_request.title }}" |
63 | 64 | echo "Checking PR title: $PR_TITLE" |
64 | 65 | if echo "$PR_TITLE" | npx commitlint; then |
65 | 66 | echo "title_valid=true" >> "$GITHUB_OUTPUT" |
@@ -100,40 +101,48 @@ jobs: |
100 | 101 |
|
101 | 102 | - name: Update PR comment |
102 | 103 | if: always() |
| 104 | + env: |
| 105 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + # Pass values via env (data, not code) so special chars like |
| 107 | + # backticks in commit messages are never evaluated by the shell. |
| 108 | + TITLE_VALID: ${{ steps.check_title.outputs.title_valid }} |
| 109 | + COMMITS_VALID: ${{ steps.check_commits.outputs.commits_valid }} |
| 110 | + COMMIT_COUNT: ${{ steps.check_commits.outputs.commit_count }} |
| 111 | + INVALID_COMMITS: ${{ steps.check_commits.outputs.invalid_commits }} |
| 112 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 113 | + REPO: ${{ github.repository }} |
103 | 114 | run: | |
104 | 115 | BODY="## Conventional Commits Validation\n\n" |
105 | 116 |
|
106 | | - if [ "${{ steps.check_title.outputs.title_valid }}" = "true" ]; then |
| 117 | + if [ "$TITLE_VALID" = "true" ]; then |
107 | 118 | BODY="${BODY}**PR Title**: valid\n" |
108 | 119 | else |
109 | 120 | BODY="${BODY}**PR Title**: invalid — please use \`type(scope): description\`\n" |
110 | 121 | fi |
111 | 122 |
|
112 | | - if [ "${{ steps.check_commits.outputs.commits_valid }}" = "true" ]; then |
113 | | - BODY="${BODY}**Commits**: all ${{ steps.check_commits.outputs.commit_count }} follow conventional format\n" |
| 123 | + if [ "$COMMITS_VALID" = "true" ]; then |
| 124 | + BODY="${BODY}**Commits**: all ${COMMIT_COUNT} follow conventional format\n" |
114 | 125 | else |
115 | 126 | BODY="${BODY}**Commits**: some do not follow conventional format\n" |
116 | | - BODY="${BODY}${{ steps.check_commits.outputs.invalid_commits }}\n" |
| 127 | + BODY="${BODY}${INVALID_COMMITS}\n" |
117 | 128 | fi |
118 | 129 |
|
119 | | - if [ "${{ steps.check_title.outputs.title_valid }}" != "true" ] || \ |
120 | | - [ "${{ steps.check_commits.outputs.commits_valid }}" != "true" ]; then |
| 130 | + if [ "$TITLE_VALID" != "true" ] || \ |
| 131 | + [ "$COMMITS_VALID" != "true" ]; then |
121 | 132 | BODY="${BODY}\n### Format\n\n\`type(scope): description\`\n\n" |
122 | 133 | BODY="${BODY}**Types**: \`feat\`, \`fix\`, \`docs\`, \`style\`, \`refactor\`, \`test\`, \`chore\`, \`ci\`, \`build\`, \`perf\`, \`revert\`\n" |
123 | 134 | fi |
124 | 135 |
|
125 | | - COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --json comments \ |
| 136 | + COMMENT_ID=$(gh pr view "$PR_NUMBER" --json comments \ |
126 | 137 | --jq '.comments[] | select(.author.login == "github-actions[bot]" and (.body | test("Conventional Commits Validation"))) | .id' \ |
127 | 138 | | head -n 1) |
128 | 139 |
|
129 | 140 | if [ -n "$COMMENT_ID" ]; then |
130 | | - gh api -X PATCH "repos/${{ github.repository }}/issues/comments/$COMMENT_ID" \ |
| 141 | + gh api -X PATCH "repos/${REPO}/issues/comments/$COMMENT_ID" \ |
131 | 142 | -f body="$(echo -e "$BODY")" |
132 | 143 | else |
133 | | - gh pr comment ${{ github.event.pull_request.number }} --body "$(echo -e "$BODY")" |
| 144 | + gh pr comment "$PR_NUMBER" --body "$(echo -e "$BODY")" |
134 | 145 | fi |
135 | | - env: |
136 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
137 | 146 |
|
138 | 147 | - name: Set commit status |
139 | 148 | if: always() |
|
0 commit comments