116 lines
4.5 KiB
YAML
116 lines
4.5 KiB
YAML
name: "Conventional Commits"
|
|
|
|
on:
|
|
pull_request_target:
|
|
types:
|
|
- opened
|
|
- reopened
|
|
- synchronize
|
|
- labeled
|
|
- unlabeled
|
|
jobs:
|
|
main:
|
|
name: Validate format
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
|
fetch-tags: true
|
|
|
|
- name: Fetch tags
|
|
run: |
|
|
git fetch --tags --quiet
|
|
git checkout ${{ github.event.pull_request.head.ref }}
|
|
|
|
- name: Check commit message
|
|
id: check_commit_message
|
|
run: |
|
|
set +e
|
|
|
|
output=$(./_assets/scripts/commit_check.sh 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' }} |