-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (127 loc) · 4.15 KB
/
ci.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
name: CI
on:
pull_request:
push:
branches: [main]
release:
types: [published]
jobs:
lint:
name: Lint
if: ${{ github.event.head_commit.message != 'Initial commit' }}
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: "1.18"
- name: Checkout
uses: actions/checkout@v3
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46
test:
name: Test
if: ${{ github.event.head_commit.message != 'Initial commit' }}
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14.4-alpine
env:
POSTGRES_USER: ${{ github.event.repository.name }}
POSTGRES_PASSWORD: ${{ github.event.repository.name }}
POSTGRES_DB: ${{ github.event.repository.name }}
ports:
- 5432/tcp
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: "1.18"
- name: Checkout
uses: actions/checkout@v3
- name: Restore Cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
env:
GO_TG_BOT_POSTGRES_DSN: postgres://${{ github.event.repository.name }}:${{ github.event.repository.name }}@localhost:${{ job.services.postgres.ports[5432] }}/${{ github.event.repository.name }}?sslmode=disable
run: go test -v -race -covermode=atomic -coverprofile=coverage.txt ./...
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
build_and_push:
name: Build and Push
runs-on: ubuntu-latest
needs: [test, lint]
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
permissions:
packages: write
contents: read
deployments: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate build args
id: build_info
run: |
echo ::set-output name=ref::$(git rev-parse --short "$GITHUB_SHA")
echo ::set-output name=version::${GITHUB_REF##*/}
echo ::set-output name=time::$(date --utc +%FT%TZ)
- name: Build and Push
id: build_and_push
uses: docker/build-push-action@v3
with:
push: true
tags: |
ghcr.io/${{ github.repository }}:dev
build-args: |
BUILD_VERSION=${{ steps.build_info.outputs.version }}
BUILD_REF=${{ steps.build_info.outputs.ref }}
BUILD_TIME=${{ steps.build_info.outputs.time }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix @todo
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.build_and_push.outputs.digest }}