|
1 | | -name: PR Verifier |
| 1 | +name: "PR Title Verifier" |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | pull_request: |
5 | | - types: [opened, edited, synchronize,reopened] |
6 | | - |
7 | | -permissions: |
8 | | - contents: read # Read-only access to repository contents |
9 | | - pull-requests: read # Read-only access to pull request details |
| 5 | + types: [opened, edited, synchronize, reopened] |
10 | 6 |
|
11 | 7 | jobs: |
12 | | - |
13 | 8 | verify: |
14 | | - name: Verify PR contents |
15 | 9 | runs-on: ubuntu-latest |
| 10 | + |
16 | 11 | steps: |
17 | | - - name: Verifier action |
18 | | - id: verifier |
19 | | - uses: kubernetes-sigs/[email protected] |
20 | | - with: |
21 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Get PR title |
| 16 | + id: get_title |
| 17 | + run: echo "title=${{ github.event.pull_request.title }}" >> $GITHUB_ENV |
| 18 | + |
| 19 | + - name: Run PR Title Checker |
| 20 | + id: check_title |
| 21 | + run: | |
| 22 | + if ! ./hack/ci/pr_title_checker.sh "${{ env.title }}" 2>error_message.txt; then |
| 23 | + echo "failed=true" >> $GITHUB_ENV |
| 24 | + fi |
| 25 | +
|
| 26 | + - name: Set failure status and save error message |
| 27 | + if: always() |
| 28 | + run: | |
| 29 | + if [ -f error_message.txt ]; then |
| 30 | + echo "failed=true" >> $GITHUB_ENV |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Create PR comment if title is invalid |
| 34 | + if: always() && env.failed == 'true' |
| 35 | + uses: actions/github-script@v6 |
| 36 | + with: |
| 37 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + script: | |
| 39 | + const fs = require('fs'); |
| 40 | + const errorMessage = fs.readFileSync('error_message.txt', 'utf8'); |
| 41 | + const prNumber = context.payload.pull_request.number; |
| 42 | + github.issues.createComment({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + issue_number: prNumber, |
| 46 | + body: `### :x: PR Title Check Failed\n${errorMessage}` |
| 47 | + }); |
| 48 | +
|
| 49 | + - name: Fail the job |
| 50 | + if: env.failed == 'true' |
| 51 | + run: exit 1 |
0 commit comments