2024-08-27 21:42:06 +00:00
name : "Conventional Commits"
on :
2024-09-20 17:11:51 +00:00
pull_request_target :
2024-08-27 21:42:06 +00:00
types :
- opened
2024-09-20 17:11:51 +00:00
- reopened
2024-08-27 21:42:06 +00:00
- synchronize
2024-09-20 17:11:51 +00:00
- labeled
- unlabeled
2024-08-27 21:42:06 +00:00
jobs :
2024-09-26 08:10:59 +00:00
lint_pr_commits :
name : Validate commit messages
2024-08-27 21:42:06 +00:00
runs-on : ubuntu-latest
permissions :
pull-requests : write
steps :
- uses : actions/checkout@v4
with :
2024-09-24 09:51:59 +00:00
fetch-depth : 0
ref : ${{github.event.pull_request.head.ref}}
repository : ${{github.event.pull_request.head.repo.full_name}}
2024-08-27 21:42:06 +00:00
- name : Check commit message
id : check_commit_message
2024-09-26 08:10:59 +00:00
if : always()
2024-08-27 21:42:06 +00:00
run : |
set +e
2024-09-24 09:51:59 +00:00
base_sha=${{ github.event.pull_request.base.sha }}
head_sha=${{ github.event.pull_request.head.sha }}
2024-08-27 21:42:06 +00:00
2024-09-24 09:51:59 +00:00
output=$(./_assets/scripts/commit_check.sh "${base_sha}" "${head_sha}" 2>&1)
2024-08-27 21:42:06 +00:00
exit_code=$?
2024-09-18 22:33:48 +00:00
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
2024-08-27 21:42:06 +00:00
if [[ $exit_code -ne 0 ]]; then
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "error_message<<$EOF" >> "$GITHUB_ENV"
2024-09-18 22:33:48 +00:00
echo "${invalid_commit_messages}" >> "$GITHUB_ENV"
2024-08-27 21:42:06 +00:00
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.
2024-09-18 22:33:48 +00:00
Please fix these commit messages :
2024-08-27 21:42:06 +00:00
```
${{ 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.
2024-09-18 22:33:48 +00:00
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)
2024-08-27 21:42:06 +00:00
# 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
2024-09-18 22:33:48 +00:00
- 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' }}