-
Notifications
You must be signed in to change notification settings - Fork 249
115 lines (99 loc) · 4.66 KB
/
commit-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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: "Conventional Commits"
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
jobs:
lint_pr_commits:
name: Validate commit messages
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Check commit message
id: check_commit_message
if: always()
run: |
set +e
base_sha=${{ github.event.pull_request.base.sha }}
head_sha=${{ github.event.pull_request.head.sha }}
output=$(./_assets/scripts/commit_check.sh "${base_sha}" "${head_sha}" 2>&1)
exit_code=$?
echo "${output}" | sed '$d'
echo "has_breaking_changes=${has_breaking_changes}"
echo "exit_code=${exit_code}" >> $GITHUB_OUTPUT
has_breaking_changes=$(echo "${output}" | tail -n 1)
echo "has_breaking_changes=${has_breaking_changes}" >> $GITHUB_OUTPUT
invalid_commit_messages=$(echo "${output}" | sed '1d;$d')
invalid_commit_messages=$(echo "${output}" | sed '1d;$d')
invalid_commit_messages=$(echo "${invalid_commit_messages}" | sed 's/\x1b\[[0-9;]*m//g') # Remove color codes
invalid_commit_messages=$(echo "${invalid_commit_messages}" | sed 's/^Commit message is ill-formed: //') # Remove prefix
if [[ $exit_code -ne 0 ]]; then
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "error_message<<$EOF" >> "$GITHUB_ENV"
echo "${invalid_commit_messages}" >> "$GITHUB_ENV"
echo "$EOF" >> "$GITHUB_ENV"
fi
- name: "Publish failed commit messages"
uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.check_commit_message.outputs.exit_code != 0)
with:
header: commit-message-lint-error
message: |
We require commits to follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), but with `_` for non-breaking changes.
Please fix these commit messages:
```
${{ env.error_message }}
```
- name: "Publish breaking changes message"
uses: marocchino/sticky-pull-request-comment@v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.check_commit_message.outputs.exit_code == 0 && steps.check_commit_message.outputs.has_breaking_changes == 'true')
with:
header: commit-message-lint-error
message: |
Looks like you have BREAKING CHANGES in your PR.
Please make sure to follow [💔How to introduce breaking changes](https://www.notion.so/How-to-introduce-breaking-changes-ded9ec2d91464a46a2593c0d8de62fbe?pvs=4) guide:
### Check-list
- [ ] Tried to avoid this breaking change
- [ ] Updated [status-desktop](https://github.com/status-im/status-desktop)
- [ ] Updated [status-mobile](https://github.com/status-im/status-mobile)
# Delete a previous comment when the issue has been resolved
- name: "Delete previous comment"
if: ${{ steps.check_commit_message.outputs.exit_code == 0 && steps.check_commit_message.outputs.has_breaking_changes == 'false' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: commit-message-lint-error
delete: true
- name: "Mark as failed"
if: steps.check_commit_message.outputs.exit_code != 0
uses: actions/github-script@v7
with:
script: |
core.setFailed("Some commit messages are ill-formed")
- name: "Update breaking changes label"
if: always()
run: |
if [[ $ADD_LABEL == 'true' ]]; then
command="--add-label"
else
command="--remove-label"
fi
gh issue edit "$NUMBER" $command "breaking change"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.pull_request.number }}
ADD_LABEL: ${{ steps.check_commit_message.outputs.has_breaking_changes == 'true' }}