Skip to content

Commit 997f28e

Browse files
committed
Add: CI test workflow and build dependencies
- Adds test.yml for multi-Go-version testing, including linting and coverage. - Updates build-and-release.yml to run tests before building.
1 parent 967e042 commit 997f28e

2 files changed

Lines changed: 125 additions & 3 deletions

File tree

.github/workflows/build-and-release.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,38 @@ jobs:
4141
echo "New tag: ${{ steps.tag_version.outputs.new_tag }}"
4242
echo "Tag created: ${{ steps.tag_version.outputs.new_tag != '' }}"
4343
44+
test:
45+
name: Test
46+
permissions:
47+
contents: read
48+
runs-on: ubuntu-latest
49+
needs: auto-tag
50+
# Always run tests, even if auto-tag was skipped
51+
if: always() && (needs.auto-tag.result == 'success' || needs.auto-tag.result == 'skipped')
52+
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v4
56+
57+
- name: Set up Go
58+
uses: actions/setup-go@v5
59+
with:
60+
go-version: '1.23' # Use the appropriate Go version for your project
61+
62+
- name: Get dependencies
63+
run: go mod download
64+
65+
- name: Run tests
66+
run: go test -v ./...
67+
4468
build:
4569
name: Build Go Binary
4670
permissions:
4771
contents: read
4872
runs-on: ${{ matrix.os }}
49-
needs: auto-tag
50-
# Always run build, even if auto-tag was skipped (e.g., for tag pushes)
51-
if: always() && (needs.auto-tag.result == 'success' || needs.auto-tag.result == 'skipped')
73+
needs: [auto-tag, test]
74+
# Only build if tests passed
75+
if: always() && (needs.auto-tag.result == 'success' || needs.auto-tag.result == 'skipped') && needs.test.result == 'success'
5276
strategy:
5377
matrix:
5478
os: [ubuntu-latest, windows-latest, macos-latest]

.github/workflows/test.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
go-version: ['1.21', '1.22', '1.23']
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v5
24+
with:
25+
go-version: ${{ matrix.go-version }}
26+
27+
- name: Cache Go modules
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.cache/go-build
32+
~/go/pkg/mod
33+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
34+
restore-keys: |
35+
${{ runner.os }}-go-${{ matrix.go-version }}-
36+
37+
- name: Download dependencies
38+
run: go mod download
39+
40+
- name: Verify dependencies
41+
run: go mod verify
42+
43+
- name: Run go vet
44+
run: go vet ./...
45+
46+
- name: Run go fmt
47+
run: |
48+
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
49+
echo "The following files are not formatted:"
50+
gofmt -s -l .
51+
exit 1
52+
fi
53+
54+
- name: Run tests
55+
run: go test -v -race -coverprofile=coverage.out ./...
56+
57+
- name: Run tests with short mode
58+
run: go test -v -short ./...
59+
60+
- name: Upload coverage to Codecov
61+
uses: codecov/codecov-action@v4
62+
with:
63+
file: ./coverage.out
64+
flags: unittests
65+
name: codecov-umbrella
66+
fail_ci_if_error: false
67+
68+
- name: Generate coverage report
69+
run: go tool cover -html=coverage.out -o coverage.html
70+
71+
- name: Upload coverage report
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: coverage-report-go${{ matrix.go-version }}
75+
path: coverage.html
76+
77+
test-build:
78+
name: Test Build
79+
runs-on: ubuntu-latest
80+
needs: test
81+
82+
steps:
83+
- name: Checkout code
84+
uses: actions/checkout@v4
85+
86+
- name: Set up Go
87+
uses: actions/setup-go@v5
88+
with:
89+
go-version: '1.23'
90+
91+
- name: Download dependencies
92+
run: go mod download
93+
94+
- name: Build
95+
run: go build -v -o commit ./cmd/commit-msg
96+
97+
- name: Verify binary
98+
run: ./commit --help || true

0 commit comments

Comments
 (0)