-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (163 loc) · 4.92 KB
/
ci.yml
File metadata and controls
197 lines (163 loc) · 4.92 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: CI
on:
push:
pull_request:
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
cache-dependency-path: go.sum
- name: Verify dependencies
run: |
go mod verify
go mod tidy
git diff --exit-code
- name: Run tests
run: go test -v ./...
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
cache-dependency-path: go.sum
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m
security:
name: Security
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
cache-dependency-path: go.sum
- name: Run govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
build:
name: Build
runs-on: ubuntu-latest
needs: [test, lint, security]
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
cache-dependency-path: go.sum
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
# Calculate version information
BASE_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0")
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
BUILD_DATE=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
GIT_TAG=$(git describe --exact-match --tags 2>/dev/null || echo "")
GIT_DIRTY=$(test -z "$(git status --porcelain 2>/dev/null)" || echo "-dirty")
# Determine version string
if [ -n "$GIT_TAG" ] && [ "$GIT_TAG" = "v$BASE_VERSION" ]; then
VERSION="v$BASE_VERSION"
else
VERSION="${BASE_VERSION}+${GIT_COMMIT}${GIT_DIRTY}"
fi
echo "Building version: $VERSION"
# Build with version information
LDFLAGS="-w -s -X 'github.com/orien/stackaroo/internal/version.Version=$VERSION' -X 'github.com/orien/stackaroo/internal/version.GitCommit=$GIT_COMMIT' -X 'github.com/orien/stackaroo/internal/version.BuildDate=$BUILD_DATE'"
if [ "${{ matrix.goos }}" = "windows" ]; then
go build -v -ldflags="$LDFLAGS" -o stackaroo-${{ matrix.goos }}-${{ matrix.goarch }}.exe .
else
go build -v -ldflags="$LDFLAGS" -o stackaroo-${{ matrix.goos }}-${{ matrix.goarch }} .
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: stackaroo-${{ matrix.goos }}-${{ matrix.goarch }}
path: stackaroo-*
retention-days: 30
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
- name: Download Linux build
uses: actions/download-artifact@v5
with:
name: stackaroo-linux-amd64
- name: Make binary executable
run: chmod +x stackaroo-linux-amd64
- name: Test CLI basics
run: |
./stackaroo-linux-amd64 --help
./stackaroo-linux-amd64 --version
./stackaroo-linux-amd64 deploy --help
docker-test:
name: Docker Build Test
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Test Docker build
run: |
# Test that our Go binary can build in a minimal container
docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app golang:1.25-alpine go build -v .
notify:
name: Notify
runs-on: ubuntu-latest
needs: [test, lint, security, build, integration-test]
if: always()
steps:
- name: Workflow Status
run: |
if [ "${{ needs.test.result }}" = "success" ] && \
[ "${{ needs.lint.result }}" = "success" ] && \
[ "${{ needs.security.result }}" = "success" ] && \
[ "${{ needs.build.result }}" = "success" ] && \
[ "${{ needs.integration-test.result }}" = "success" ]; then
echo "✅ All CI checks passed!"
else
echo "❌ Some CI checks failed"
exit 1
fi