forked from spack/spack
-
Notifications
You must be signed in to change notification settings - Fork 14
50 lines (42 loc) · 1.89 KB
/
validate-commit-message.yaml
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
name: Commit message & PR title validation
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Get diff with base branch
id: changed-files
run: |
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} | jq -sR 'split("\n") | map(select(. != "")) | @json' | sed -r 's/^"|"$//g' | tr -s /)
echo "changed-files=\"${CHANGED_FILES}\"" >> $GITHUB_OUTPUT
- name: Validate commit messages & PR title
id: commit-message-validator
continue-on-error: true
run: |
pip install gitpython
set -x
python ./.github/workflows/validate-commit-message.py --title "${{ github.event.pull_request.title }}" --changed-files "${{ steps.changed-files.outputs.changed-files }}" --commits "${{ github.event.pull_request.commits }}"
- name: Show output
run: |
echo "Faulty commits: ${{ steps.commit-message-validator.outputs.faulty-commits }}"
echo "Script failure: ${{ steps.commit-message-validator.outputs.script-failure }}"
- name: Add comment to PR
if: ${{ steps.commit-message-validator.outputs.faulty-commits == 'true' }}
uses: thollander/actions-comment-pull-request@v2
with:
filePath: message_issues.txt
reactions: eyes, confused, rocket
- name: Fail the action
if: ${{ steps.commit-message-validator.outputs.faulty-commits == 'true' || steps.commit-message-validator.outputs.script-failure == 'true' }}
run: |
echo "Something is not right - failing"
exit 1