-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (58 loc) · 1.99 KB
/
build.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
name: build
on:
push:
branches:
- main
tags:
- '!*'
pull_request:
branches:
- '*'
jobs:
build:
runs-on: ubuntu-latest
name: build
steps:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Checkout
uses: actions/checkout@v3
- name: Configure cache paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
echo "::set-output name=envtest::internal/testdata/$(go env GOOS)"
- name: Restore Go build cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
- name: Restore Go mod cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
- name: Restore envtest deps cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.envtest }}
key: ${{ runner.os }}-envtest-${{ hashFiles('**/internal/testdata/get-binaries.sh') }}
- name: Download deps
run: go mod download
- name: Download envtest deps
run: (cd internal/testdata && ./get-binaries.sh)
- name: Test controller
run: go test ./internal/...
- name: Build controller
run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o controller ./cmd/main.go
- name: Build Docker image
run: docker build . -t slamdev/cortex-rule-watcher
- name: Login to Dockerhub
if: github.ref == 'refs/heads/main'
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u slamdev --password-stdin
- name: Push Docker image
if: github.ref == 'refs/heads/main'
run: docker push slamdev/cortex-rule-watcher:latest