-
Notifications
You must be signed in to change notification settings - Fork 18
110 lines (87 loc) · 2.72 KB
/
test.yml
File metadata and controls
110 lines (87 loc) · 2.72 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
name: Test
permissions:
contents: read
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.21', '1.22', '1.23']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Run go vet
run: go vet ./...
- name: Run go fmt
run: |
# Auto-format all Go files
gofmt -s -w .
# Check if any files were formatted (would indicate pre-existing formatting issues)
if [ -n "$(git status --porcelain 2>/dev/null)" ]; then
echo "Some files were auto-formatted. Consider running 'gofmt -s -w .' locally before committing."
git diff --name-only
fi
# Final check to ensure all files are properly formatted
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "The following files are still not formatted after auto-format:"
gofmt -s -l .
exit 1
fi
- name: Run tests
run: go test -v -race -coverprofile=coverage.out ./...
- name: Run tests with short mode
run: go test -v -short ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Generate coverage report
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report-go${{ matrix.go-version }}
path: coverage.html
test-build:
name: Test Build
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Download dependencies
run: go mod download
- name: Build
run: go build -v -o commit ./cmd/commit-msg
- name: Verify binary
run: ./commit --help || true