Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
63 lines (57 loc) · 2.27 KB
/
Copy pathaction.yml
File metadata and controls
63 lines (57 loc) · 2.27 KB
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
62
63
name: "Conventional commit"
description: "Valida o título do PR e as mensagens dos commits com o mesmo script do hook commit-msg."
inputs:
title:
description: "Valida o título do PR (vira a mensagem no squash merge)."
default: "true"
commits:
description: "Valida a mensagem de cada commit do PR (merges ficam de fora)."
default: "true"
release-branch:
description: "Branch dos PRs de release (ex.: dev → main): o título deles não é validado, só os commits. Vazio valida todos os títulos."
default: "dev"
runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
filter: "blob:none"
sparse-checkout: ".commit-scopes"
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Check commit messages
shell: sh
env:
CHECK: ${{ github.action_path }}/.lefthook/commit-msg/conventional-commit.sh
CHECK_TITLE: ${{ inputs.title }}
CHECK_COMMITS: ${{ inputs.commits }}
RELEASE_BRANCH: ${{ inputs.release-branch }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
failed=0
message=$(mktemp)
if [ "$CHECK_TITLE" = "true" ] && [ -n "$RELEASE_BRANCH" ] && [ "$HEAD_REF" = "$RELEASE_BRANCH" ]; then
echo "Release PR ($HEAD_REF): title not checked."
elif [ "$CHECK_TITLE" = "true" ]; then
printf '%s\n' "$PR_TITLE" > "$message"
if ! sh "$CHECK" "$message"; then
echo "::error title=Invalid PR title::$PR_TITLE"
failed=1
fi
fi
if [ "$CHECK_COMMITS" = "true" ]; then
for sha in $(git rev-list --no-merges --reverse "$(git merge-base "$BASE_SHA" "$HEAD_SHA")..$HEAD_SHA"); do
git log -1 --format=%B "$sha" > "$message"
if ! sh "$CHECK" "$message"; then
echo "::error title=Invalid commit message::$(git log -1 --format='%h %s' "$sha")"
failed=1
fi
done
fi
exit "$failed"