-
Notifications
You must be signed in to change notification settings - Fork 16
109 lines (94 loc) · 2.68 KB
/
CI&CD.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
name: CI/CD
on:
push:
branches: master
tags: v*
pull_request:
branches: master
env:
GO_VERSION: '^1.16'
GOFLAGS: '-mod=readonly'
jobs:
test:
runs-on: 'ubuntu-latest'
timeout-minutes: 30
services:
mysql:
image: 'mysql:5.6'
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
ports:
- '3306:3306'
env:
EXAMPLE_APIKEY_ADMIN: 'admin'
EXAMPLE_MYSQL_ADDR_HOST: 'localhost'
EXAMPLE_MYSQL_AUTH_LOGIN: 'root'
EXAMPLE_MYSQL_AUTH_PASS: ''
steps:
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/go/bin
~/go/pkg
~/go/src
~/.cache/go-build
~/.cache/golangci-lint
.gobincache
key: v3-test-${{ runner.os }}-${{ hashFiles('go.mod') }}
restore-keys: |
v3-test-${{ runner.os }}-
- run: scripts/test
- name: Ensure API spec match auto-generated code
run: |
go generate ./api/...
git add . && git status --short && git diff-index --quiet HEAD
- name: Report code coverage
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
if: env.COVERALLS_TOKEN
run: |
scripts/cover
.gobincache/goveralls -coverprofile=cover.out -service=GitHub
build-and-release:
needs: test
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event_name == 'push'
steps:
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v2
- name: Turnstyle
uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v2
with:
path: |
~/go/pkg
~/.cache/go-build
key: v1-build-${{ runner.os }}-${{ hashFiles('go.mod') }}
restore-keys: |
v1-build-${{ runner.os }}-
- run: scripts/build
- name: Upload to GitHub Container Registry
run: |
docker login ghcr.io -u '${{ secrets.CR_USER }}' -p '${{ secrets.CR_PAT }}'
if echo "$GITHUB_REF" | grep -q '^refs/tags/v'; then
TAGS="${GITHUB_REF/refs\/tags\/v}"
else
#TAGS="$GITHUB_SHA latest"
TAGS="latest"
fi
for TAG in $TAGS; do
IMAGE_TAG="ghcr.io/${GITHUB_REPOSITORY,,*}:$TAG"
docker tag "$(basename $(go list -m))" "$IMAGE_TAG"
docker push "$IMAGE_TAG"
done