-
Notifications
You must be signed in to change notification settings - Fork 56
163 lines (143 loc) · 4.58 KB
/
ci-core.yaml
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
name: ci / core
on:
pull_request:
paths:
- go.mod
- go.sum
- '**/*.go'
- 'test/**'
- '.github/workflows/ci-core.yaml'
- '.golangci.yml'
push:
branches:
- main
paths:
- go.mod
- go.sum
- '**/*.go'
- 'test/**'
- '.github/workflows/*-core.yaml'
- '.golangci.yml'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.19"
cache: true
- name: run lint
# disable auto-fix, and enable verbose
run: LINT_ARGS=-v make lint
go-test:
runs-on: ubuntu-latest
name: "go-test (postgres ${{matrix.version}})"
strategy:
matrix:
version: [12, 14]
services:
postgres:
image: postgres:${{ matrix.version }}-alpine
env:
POSTGRES_PASSWORD: password123
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 5
ports: ["127.0.0.1:5432:5432"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.19"
cache: true
- run: go mod download -x
- run: go install gotest.tools/[email protected]
- name: Conditionally enable -race
if: ${{ github.ref_name == 'main' || contains(github.event.pull_request.labels.*.name, 'action/race') }}
run: echo "GO_TEST_RACE=-race" >> $GITHUB_ENV
- name: go test
run: ~/go/bin/gotestsum -ftestname -- ${GO_TEST_RACE:-} ./...
env:
POSTGRESQL_CONNECTION: "host=localhost port=5432 user=postgres dbname=postgres password=password123"
- name: go test querylinter
working-directory: ./internal/tools/querylinter
run: ~/go/bin/gotestsum -ftestname ./...
- name: Check that tests leave a clean git checkout
run: |
# show and check changes to committed files
git diff --exit-code
# show and check for uncommitted files
git status --short; [[ "$(git status --short)" == "" ]]
test:
runs-on: ubuntu-latest
needs: [go-test]
if: ${{ always() }}
steps:
- run: |
RESULT="${{ needs.go-test.result }}"
[ "$RESULT" = 'success' ] || [ "$RESULT" = 'skipped' ] || exit 1
check-generated:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.19"
cache: true
- run: go mod download -x
- run: go build -debug-actiongraph=compile.json .
- uses: actions/upload-artifact@v3
with:
name: build-log
path: compile.json
- name: Check go mod is tidy
run: |
go mod tidy
git diff --exit-code go.mod go.sum
- name: Check generated code is updated
run: |
go generate ./...
git diff --exit-code
test-acceptance:
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' || contains(github.event.pull_request.labels.*.name, 'action/test-acceptance') }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.19"
cache: true
- run: sudo apt-get update && sudo apt-get install -y checkpolicy semodule-utils
- run: go install gotest.tools/[email protected]
- name: Filter goreleaser config to linux only
run: go run ./test/bin/goreleaser-filter.go > .goreleaser.linux.yml
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: release --rm-dist --snapshot --skip-publish --config .goreleaser.linux.yml
env:
RELEASE_NAME: 0.0.0
# the ./test module uses the main module, this is an easy way to use the
# dependencies from the main module
- name: Setup workspace
run: go work init . ./test
- name: Start containers
run: |
head -c 32 < /dev/urandom > test/root.key
docker compose -f test/docker-compose.yaml up -d --wait
- name: Setup destinations
run: ./test/setup.sh
- name: Run tests
working-directory: test
run: ~/go/bin/gotestsum -ftestname -- ./...
- name: Container output
if: always()
run: |
set +e
docker compose --ansi always -f test/docker-compose.yaml logs
echo "systemd logs from ubuntu"
docker exec test-destination_ubuntu-1 journalctl -t infra -t sshd -t infra-ssh