-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (99 loc) · 2.82 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
name: Test
permissions:
contents: write
packages: write
on: [push]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.3-alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: secret
POSTGRES_USER: krab
POSTGRES_DB: krab
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: 1.21.4
- uses: actions/cache@v3
if: ${{ !env.ACT }}
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run tests
env:
DATABASE_URL: "postgres://krab:secret@localhost:5432/krab?sslmode=disable&prefer_simple_protocol=true"
run: |
mkdir -p bin/
make install
make gen
go test -v ./...
release:
runs-on: ubuntu-latest
needs: test
if: ${{ startsWith(github.ref, 'refs/tags/') }}
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set tag
run: echo "IMAGE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v4
with:
# relative path to the place where source code with Dockerfile is located
context: .
push: true
tags: |
ghcr.io/ohkrab/krab:${{ env.IMAGE_TAG }}
qbart/krab:${{ env.IMAGE_TAG }}
build-args: |
BUILD_VERSION=${{ env.IMAGE_TAG }}
BUILD_COMMIT=${{ github.sha }}
BUILD_DATE=${{ github.event.repository.updated_at }}
-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.21.4
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}