-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (116 loc) · 3.93 KB
/
ci.yml
File metadata and controls
137 lines (116 loc) · 3.93 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# ==============================================================================
# .github/workflows/ci.yml — cpp-gen
# ==============================================================================
# Continuous integration pipeline. Runs on every push to main/master
# and on pull requests, ensuring the project compiles and passes tests.
# ==============================================================================
name: CI
on:
push:
branches:
- main
- master
# Ignores tag pushes (covered by the release.yml workflow)
tags-ignore:
- "**"
pull_request:
branches:
- main
- master
# Cancels previous runs of the same PR/branch to save minutes
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
# ── Build & Test ─────────────────────────────────────────────────────────────
build:
name: Build & Test (Go ${{ matrix.go-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go-version:
- "1.22"
- "1.23"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Verify dependencies
run: |
go mod verify
go mod tidy
git diff --exit-code go.mod go.sum
- name: go vet
run: go vet ./...
- name: Build
run: |
go build -trimpath -ldflags "-s -w \
-X cpp-gen/cmd.AppVersion=ci \
-X cpp-gen/cmd.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
-X cpp-gen/cmd.GitCommit=${GITHUB_SHA::7}" \
-o /dev/null .
- name: Test
run: go test -v -race -coverprofile=coverage.out ./...
- name: Upload coverage
if: matrix.go-version == '1.22'
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
retention-days: 7
# ── Cross-compilation check ───────────────────────────────────────────────────
# Ensures the binary compiles for all targets that goreleaser will generate.
cross-build:
name: Cross-compile (${{ matrix.goos }}/${{ matrix.goarch }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: "386"
- goos: darwin
goarch: amd64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: true
- name: Cross-compile ${{ matrix.goos }}/${{ matrix.goarch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
run: |
go build -trimpath -ldflags "-s -w \
-X cpp-gen/cmd.AppVersion=ci \
-X cpp-gen/cmd.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
-X cpp-gen/cmd.GitCommit=${GITHUB_SHA::7}" \
-o /dev/null .
# ── Lint ──────────────────────────────────────────────────────────────────────
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m