mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-03-03 17:40:38 +00:00
78 lines
2.8 KiB
YAML
78 lines
2.8 KiB
YAML
name: "Conventional Commits"
|
|
|
|
on:
|
|
pull_request:
|
|
types:
|
|
- opened
|
|
- edited
|
|
- reopened
|
|
- synchronize
|
|
jobs:
|
|
main:
|
|
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=$(.github/scripts/commit_check.sh "${base_sha}" "${head_sha}" 2>&1)
|
|
exit_code=$?
|
|
|
|
echo "${output}" | sed '$d'
|
|
echo "exit_code=${exit_code}" >> $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: |
|
|
Commits must follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/)
|
|
Please fix these commit messages:
|
|
```
|
|
${{ env.error_message }}
|
|
```
|
|
|
|
# Delete a previous comment when the issue has been resolved
|
|
- name: "Delete previous comment"
|
|
if: ${{ steps.check_commit_message.outputs.exit_code == 0 }}
|
|
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")
|