-
Notifications
You must be signed in to change notification settings - Fork 1
132 lines (115 loc) · 3.56 KB
/
Copy pathbuild.yml
File metadata and controls
132 lines (115 loc) · 3.56 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
name: Build and Release
on:
push:
branches: [main, master]
tags:
- 'v*'
pull_request:
branches: [main, master]
workflow_dispatch:
jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Run go vet
run: go vet ./...
- name: Run tests
run: |
echo ">>> Running tests..."
FAILED=""
for pkg in $(go list ./...); do
echo "--- Testing $pkg ---"
set +e
go test "$pkg" 2>&1
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -ne 0 ]; then
echo "::error::TEST FAILED: $pkg (exit code: $EXIT_CODE)"
FAILED="$FAILED $pkg"
fi
done
if [ -n "$FAILED" ]; then
echo "============================================"
echo ">>> FAILED PACKAGES:$FAILED"
echo "============================================"
exit 1
fi
echo "All basic tests passed"
- name: Run tests with coverage
run: |
echo ">>> Running tests with coverage..."
FAILED=""
TMPDIR=$(mktemp -d)
echo "mode: set" > "$TMPDIR/coverage.out"
for pkg in $(go list ./...); do
echo "--- Testing $pkg ---"
set +e
go test -coverprofile="$TMPDIR/coverage.tmp" "$pkg" 2>&1
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -ne 0 ]; then
echo "::error::COVERAGE TEST FAILED: $pkg (exit code: $EXIT_CODE)"
FAILED="$FAILED $pkg"
fi
if [ -f "$TMPDIR/coverage.tmp" ]; then
tail -n +2 "$TMPDIR/coverage.tmp" >> "$TMPDIR/coverage.out"
rm "$TMPDIR/coverage.tmp"
fi
done
cp "$TMPDIR/coverage.out" coverage.out
rm -rf "$TMPDIR"
if [ -n "$FAILED" ]; then
echo "============================================"
echo ">>> FAILED PACKAGES:$FAILED"
echo "============================================"
exit 1
fi
echo "--- coverage summary ---"
go tool cover -func=coverage.out | tail -5
- name: Check for vulnerable dependencies
continue-on-error: true
uses: golang/govulncheck-action@v1
with:
go-version-input: '1.25'
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
build:
needs: quality
strategy:
matrix:
go-version: ['1.25']
platform: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Build
run: |
go build -o cortex-${{ matrix.platform }}-amd64 ./cmd/cortex
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: cortex-${{ matrix.platform }}-amd64
path: cortex-${{ matrix.platform }}-amd64*
release:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4