-
Notifications
You must be signed in to change notification settings - Fork 154
62 lines (53 loc) · 1.84 KB
/
changeset-check.yml
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
62
name: PR Changeset Check
on:
pull_request:
types:
- opened
- synchronize
jobs:
check_changeset:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Check for major changes
run: |
changed_files=$(git diff --name-only "HEAD..HEAD~1")
files=$(echo "$changed_files" | grep "\.changeset")
major_changes=$(grep -c "major" $files)
echo "$major_changes major changes found."
if [ "$major_changes" -gt 0 ]; then
comment="@${{ github.actor }}, 本次 PR 的更改包含 major 变更,请确认是否符合预期。<!-- AUTO_CHANGESET_CHECK_HOOK -->"
echo "$comment" > comment_body.txt
echo "comment=$comment" >> $GITHUB_OUTPUT
else
echo "comment=" >> $GITHUB_OUTPUT
fi
# Save PR id to output
- name: save PR id
id: pr
run: echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
add_comment:
needs: check_changeset
runs-on: ubuntu-latest
if: ${{ needs.check_changeset.outputs.comment != '' }}
steps:
- name: update status comment
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ needs.check_changeset.outputs.comment }}
body-include: '<!-- AUTO_CHANGESET_CHECK_HOOK -->'
number: ${{ steps.pr.outputs.id }}
delete_comment:
needs: check_changeset
runs-on: ubuntu-latest
if: ${{ needs.check_changeset.outputs.comment == '' }}
steps:
- name: Delete comment
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body-include: '<!-- AUTO_CHANGESET_CHECK_HOOK -->'
number: ${{ steps.pr.outputs.id }}
delete: true