forked from delta-io/delta-kernel-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
61 lines (54 loc) · 2.73 KB
/
Copy pathcomment-on-title-failure.yml
File metadata and controls
61 lines (54 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Comment on PR Title Failure
on:
workflow_run:
workflows: ["Validate PR Title"]
types: [completed]
jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
# Step taken from: https://github.com/orgs/community/discussions/25220#discussioncomment-11316244
- name: Find PR info
id: pr-context
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
# If the PR is from a fork, prefix it with `<owner-login>:`, otherwise only the PR branch name is relevant:
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
# Query the PR number by repo + branch, then assign to step output:
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number,title' --jq '"number=\(.number)\ntitle=\(.title)"' \
>> "${GITHUB_OUTPUT}"
- name: Find existing comment
id: find
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
with:
issue-number: ${{ steps.pr-context.outputs.number }}
comment-author: 'github-actions[bot]'
body-includes: PR title does not match the required pattern
- name: Post or update failure comment
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
env:
PR_TITLE: ${{ steps.pr-context.outputs.title }}
with:
comment-id: ${{ steps.find.outputs.comment-id }}
issue-number: ${{ steps.pr-context.outputs.number }}
body: |
PR title does not match the required pattern. Please ensure you follow the [conventional commits](https://www.conventionalcommits.org/) spec.
Your title should start with `feat:`, `fix:`, `chore:`, `docs:`, `perf:`, `refactor:`, `test:`, or `ci:`, and if it's a breaking change that should be suffixed with a `!` (like `feat!:`), and then a 1-72 character brief description of your change.
**Title:** `${{ env.PR_TITLE }}`
- name: Delete comment on success
if: ${{ github.event.workflow_run.conclusion == 'success' && steps.find.outputs.comment-id != '' }}
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/issues/comments/${{ steps.find.outputs.comment-id }} -X DELETE