-
Notifications
You must be signed in to change notification settings - Fork 6
170 lines (160 loc) · 5.12 KB
/
ci.yml
File metadata and controls
170 lines (160 loc) · 5.12 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
name: ci
on:
push:
branches:
- "**"
pull_request:
workflow_dispatch:
inputs:
run_integration:
description: "Run integration tests with GitLab Testcontainers"
required: false
default: false
type: boolean
permissions:
contents: write
pull-requests: write
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Install golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Run golangci-lint
run: golangci-lint run --timeout=10m
test-fast:
name: test (fast)
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Download dependencies
run: go mod download
- name: Run fast tests
run: go test -v ./...
coverage:
name: coverage
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Download dependencies
run: go mod download
- name: Generate coverage
id: coverage-output
run: |
go test ./... -coverprofile=coverage.out
go tool cover -func=coverage.out | tee coverage.txt
{
echo 'coverage_text<<EOF_TEXT'
cat coverage.txt
echo EOF_TEXT
} >> "$GITHUB_OUTPUT"
echo "## Coverage" >> "$GITHUB_STEP_SUMMARY"
echo '```text' >> "$GITHUB_STEP_SUMMARY"
cat coverage.txt >> "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: go-coverage
path: |
coverage.out
coverage.txt
- name: Comment coverage on PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: coverage
message: |
## Coverage
```text
${{ steps.coverage-output.outputs.coverage_text }}
```
test-integration:
name: test (integration)
runs-on: ubuntu-latest
timeout-minutes: 90
if: >-
github.ref == 'refs/heads/main' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.run_integration == 'true')
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up Go from go.mod
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Download dependencies
run: go mod download
- name: Pre-pull GitLab test image (retry)
run: |
image="gitlab/gitlab-ce:17.6.1-ce.0"
max_attempts=4
for attempt in $(seq 1 "$max_attempts"); do
echo "Pulling $image (attempt $attempt/$max_attempts)"
if docker pull "$image"; then
echo "Successfully pulled $image"
exit 0
fi
if [ "$attempt" -lt "$max_attempts" ]; then
backoff=$((attempt * 10))
echo "Pull failed; retrying in ${backoff}s"
sleep "$backoff"
fi
done
echo "::warning::Could not pre-pull $image after $max_attempts attempts; integration tests will continue and may skip on transient registry/network failures."
- name: Run integration tests
env:
GLABS_RUN_GITLAB_TC: "1"
run: |
go test -tags=integration ./gitlab/... -count=1 -v -run '^TestIntegration_'
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs:
- golangci
- test-fast
- coverage
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- uses: go-semantic-release/action@v1
id: semrel
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
changelog-file: CHANGELOG.md
prepend: true
changelog-generator-opt: "emojis=true"
allow-initial-development-versions: true
hooks: goreleaser
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push CHANGELOG.md
if: steps.semrel.outputs.version != ''
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git diff --cached --quiet || git commit -m "update changelog for v${{ steps.semrel.outputs.version }} [skip ci]"
git push