-
Notifications
You must be signed in to change notification settings - Fork 157
61 lines (53 loc) · 1.74 KB
/
check-pr-commit.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
name: Check PR commit
on:
pull_request:
branches:
- master
- release/*
types:
- opened
- synchronize
- reopened
- ready_for_review
defaults:
run:
shell: bash
jobs:
check-commit-message:
name: Check commit message
runs-on: ubuntu-20.04
# Skip on draft, check on draft -> ready
if: github.repository_owner == 'Samsung' && github.event.pull_request.draft == false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Checkout PR head commit
# Checkout Action use merge commit as default
ref: ${{ github.event.pull_request.head.sha }}
# Fetch all history and branch (default: 1)
fetch-depth: 0
- name: Get commit body
run: |
git log origin/${GITHUB_BASE_REF}..HEAD --format=%b > commit_msg.txt
sed '/^$/d' commit_msg.txt > commit_body.txt
- name: Check signed-off
run: |
# Check string starting from "Signed-off-by:"
count=$(cat commit_body.txt | grep 'Signed-off-by:' | wc -l)
if [[ ! "$count" -ge "1" ]]; then
echo "Your commit message does not contain the expected signoff information."
exit 1
fi
echo "Signed-off-by is OK"
- name: Check body words
# Run if check_signed_off step is failed
if: ${{ always() }}
run: |
count=$(cat commit_body.txt | sed '/Signed-off-by:/d' | wc -w)
echo "Commit body word check: $count words"
if [[ "$count" -lt "5" ]]; then
echo "The body of your commit does not satisfy this repository requirements."
echo "The body needs to contain at least 5 words."
exit 1
fi