-
Notifications
You must be signed in to change notification settings - Fork 5
238 lines (203 loc) · 6.17 KB
/
Copy pathci.yml
File metadata and controls
238 lines (203 loc) · 6.17 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
name: CI
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
env:
GO_VERSION: '1.25'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpcsclite-dev
- name: Setup dev environment
run: make dev
- name: Check formatting
run: |
UNFORMATTED=$(gofmt -l .)
if [ -n "$UNFORMATTED" ]; then
echo "The following files are not properly formatted:"
echo "$UNFORMATTED"
exit 1
fi
- name: Run staticcheck
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
- name: Run go vet
run: go vet ./...
test:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpcsclite-dev
- name: Run tests
run: |
make dev
go test -v -race ./...
security-scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpcsclite-dev
- name: Setup dev environment
run: make dev
- name: Run gosec
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec -exclude-dir .build -severity high ./...
- name: Run govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
build:
name: Build (${{ matrix.os }}_${{ matrix.arch }})
runs-on: ubuntu-latest
needs: [lint, security-scan, test]
strategy:
matrix:
include:
- os: linux
arch: amd64
goarch: amd64
- os: linux
arch: arm64
goarch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libpcsclite-dev
# Install cross-compilation toolchain for arm64
if [ "${{ matrix.arch }}" = "arm64" ]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
- name: Setup dev environment
run: |
mkdir .build
git clone --branch v0.29.0 --depth 1 https://github.com/smallstep/certificates.git .build/certificates/
rm -rf .build/certificates/server && cp -r ./hack/server .build/certificates/server
mkdir -p db
go mod tidy
- name: Build binary
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: ${{ matrix.arch == 'arm64' && '0' || '1' }}
CC: ${{ matrix.arch == 'arm64' && 'aarch64-linux-gnu-gcc' || '' }}
run: |
BINARY_NAME="step-ca_${{ matrix.os }}_${{ matrix.arch }}"
go build -v -o "${BINARY_NAME}" .
echo "Built ${BINARY_NAME}"
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: step-ca_${{ matrix.os }}_${{ matrix.arch }}
path: step-ca_${{ matrix.os }}_${{ matrix.arch }}
container-build-and-push:
name: Build and Push Container
runs-on: ubuntu-latest
needs: [lint, security-scan, test]
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
name: Release
runs-on: ubuntu-latest
needs: [build]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
path: dist
pattern: step-ca_*
merge-multiple: true
- name: List artifacts
run: ls -la dist/
- name: Get version
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ steps.version.outputs.VERSION }}
generate_release_notes: true
files: |
dist/step-ca_*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}