-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (171 loc) · 5.61 KB
/
main.yml
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
name: main
on:
push:
branches:
- main
tags:
- 'v*'
pull_request:
branches:
- '*'
jobs:
build:
name: Build
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_DB: auditum_db
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
options: >-
--health-cmd "pg_isready -U user"
--health-interval 1s
--health-timeout 10s
--health-retries 10
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: 'go.mod'
- name: Download dependencies
run: |
go mod download
- name: Run unit tests
run: |
go test -v -race -coverprofile=coverage.txt -covermode=atomic $(go list ./...)
- name: Run linter
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0
with:
version: v1.55.2
args: --verbose
# See: https://github.com/golangci/golangci-lint-action/issues/244
skip-pkg-cache: true
skip-build-cache: true
- name: Build
run: |
go build -v -o ./bin/auditum ./cmd/auditum
- name: Run integration tests
env:
POSTGRES_HOST: 127.0.0.1
POSTGRES_PORT: 5432
POSTGRES_DBNAME: auditum_db
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_SSL_MODE: disable
run: |
go test \
-tags "integration postgres" \
-v \
-p 1 \
-count 1 \
./internal/sql/... \
-run "TestIntegration"
go test \
-tags "integration sqlite" \
-v \
-p 1 \
-count 1 \
./internal/sql/... \
-run "TestIntegration"
docker:
name: Docker
runs-on: ubuntu-latest
needs:
- build
permissions:
contents: read
packages: write
env:
IMAGE_REGISTRY_GITHUB: ghcr.io
IMAGE_NAME_GITHUB: ${{ github.repository }}
IMAGE_NAME_DOCKERHUB_AUDITUMIO: auditumio/auditum
# For PR, we only build for AMD64, just to be sure that Docker build works.
# For main branch and tags we also build for ARM64.
# Note that building for ARM64 is very slow.
IMAGE_PLATFORMS: |
linux/amd64
${{ github.event_name != 'pull_request' && 'linux/arm64' || '' }}
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: 'go.mod'
- name: Download dependencies
run: |
go mod download
go mod vendor
- name: Extract Docker image metadata
id: docker_meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: |
${{ env.IMAGE_NAME_DOCKERHUB_AUDITUMIO }}
${{ env.IMAGE_REGISTRY_GITHUB }}/${{ env.IMAGE_NAME_GITHUB }}
tags: |
type=ref,event=pr
type=ref,event=branch,enable={{ is_default_branch }}
type=semver,pattern={{ version }}
- name: Login to Docker Hub for auditumio
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
username: auditumio
password: ${{ secrets.DOCKERHUB_AUDITUMIO_TOKEN }}
if: github.event_name != 'pull_request'
- name: Login to GitHub Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ${{ env.IMAGE_REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name != 'pull_request'
# Used for arm images.
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
with:
platforms: ${{ env.IMAGE_PLATFORMS }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Build and push Docker image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: .
platforms: ${{ env.IMAGE_PLATFORMS }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
goreleaser:
name: GoReleaser
runs-on: ubuntu-latest
needs:
- build
permissions:
contents: write
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: 'go.mod'
- name: Download dependencies
run: |
go mod download
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_PREVIOUS_TAG: ""