Repository navigation
117 lines (98 loc) · 3.73 KB
/
Copy pathci.yml
File metadata and controls
117 lines (98 loc) · 3.73 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: CI
on:
pull_request:
branches: [main, dev]
push:
branches: [main, dev]
workflow_call:
permissions:
contents: read
pull-requests: write
jobs:
commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Validate commit messages
run: |
# Clean Commit convention pattern (supports optional ! for breaking changes)
# Format: <emoji> <type>[!][(<scope>)]: <description>
PATTERN='^(📦|🔧|🗑️|🔒|⚙️|☕|🧪|📖|🚀) (new|update|remove|security|setup|chore|test|docs|release)!?( \([a-z0-9][a-z0-9-]*\))?: .{1,72}$'
if [ "${{ github.event_name }}" = "pull_request" ]; then
COMMITS=$(git log --format="%s" "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}")
else
GITHUB_EVENT_BEFORE="${{ github.event.before }}"
GITHUB_EVENT_AFTER="${{ github.event.after }}"
if [ "$GITHUB_EVENT_BEFORE" = "0000000000000000000000000000000000000000" ]; then
# Initial push has no valid "before" SHA, so capture all reachable commits
COMMITS=$(git log --format="%s" "$GITHUB_EVENT_AFTER")
elif ! git cat-file -e "${GITHUB_EVENT_BEFORE}^{commit}" 2>/dev/null; then
# Force-push: before SHA no longer exists, validate only the latest commit
echo "⚠ Force-push detected — before SHA not found, validating HEAD commit only"
COMMITS=$(git log --format="%s" -1 "$GITHUB_EVENT_AFTER")
else
COMMITS=$(git log --format="%s" "${GITHUB_EVENT_BEFORE}..${GITHUB_EVENT_AFTER}")
fi
fi
FAILED=0
while IFS= read -r msg; do
[ -z "$msg" ] && continue
# Allow merge commits
if echo "$msg" | grep -qE "^Merge "; then
continue
fi
# Allow Copilot agent initial plan commits (auto-generated before repo conventions are read)
if echo "$msg" | grep -qE "^Initial plan$"; then
echo "⚠ Skipping bot commit: $msg"
continue
fi
if ! echo "$msg" | grep -qP "$PATTERN"; then
echo "✖ Invalid commit message: $msg"
FAILED=1
else
echo "✔ Valid commit message: $msg"
fi
done <<< "$COMMITS"
if [ "$FAILED" -eq 1 ]; then
echo ""
echo "One or more commit messages do not follow the Clean Commit convention."
echo "Format: <emoji> <type>[(<scope>)]: <description>"
echo "Reference: https://github.com/wgtechlabs/clean-commit"
exit 1
fi
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Generate
run: go generate ./...
- uses: golangci/golangci-lint-action@v8
with:
version: v2.11.3
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Generate
run: go generate ./...
- name: Build
run: go build ./...
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Generate
run: go generate ./...
- name: Run tests
run: go test ./...