-
Notifications
You must be signed in to change notification settings - Fork 27
148 lines (138 loc) · 4.44 KB
/
ci.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
name: Continuous Integration
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- '*'
- '!dependabot/**'
env:
IMAGE_NAME: cloud-provider-equinix-metal
GHCR_REGISTRY: ghcr.io/${{ github.repository_owner }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_ORG }}
QUAY_REGISTRY: quay.io/${{ secrets.QUAY_ORG }}
REGISTRY: ghcr.io/${{ github.repository_owner }}
metadata_flavor: latest=false
metadata_tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
jobs:
report:
name: Report
runs-on: ubuntu-latest
steps:
- name: ref
run: echo ${{ github.ref }}
- name: event_name
run: echo ${{ github.event_name }}
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.59
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
- id: go-cache-paths
shell: bash
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Go Mod Cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-mod-
- name: Go Build Cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-build-
- name: test
run: make race
image:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: Set up QEMU for cross-building
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Generate metadata
id: meta
uses: ./.github/actions/metadata
with:
docker_username: ${{ secrets.DOCKER_USERNAME }}
quay_username: ${{ secrets.QUAY_USERNAME }}
metadata_flavor: ${{ env.metadata_flavor }}
metadata_tags: ${{ env.metadata_tags }}
- name: Determine if workflow should push image
id: should-push
run: |
SHOULD_PUSH=true
# Skip pushing if initiated by dependabot
[[ "$GITHUB_ACTOR" == "dependabot[bot]" ]] && SHOULD_PUSH=false
# Skip pushing if a PR
[[ "$GITHUB_EVENT_NAME" == "pull_request" ]] && SHOULD_PUSH=false
# Skip pushing if a pull request and branch is not main
[[ "$GITHUB_EVENT_NAME" == "push" && "$GITHUB_REF_NAME" != "main" ]] && SHOULD_PUSH=false
echo "should-push=${SHOULD_PUSH}" >> $GITHUB_OUTPUT
- name: Log in to ghcr.io
uses: docker/login-action@v3
if: ${{ steps.should-push.outputs.should-push == 'true' }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log into DockerHub
uses: docker/login-action@v3
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
if: ${{ env.DOCKER_USERNAME != '' && steps.should-push.outputs.should-push == 'true' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log into quay.io
uses: docker/login-action@v3
env:
QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
if: ${{ env.QUAY_USERNAME != '' && steps.should-push.outputs.should-push == 'true' }}
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
push: ${{ steps.should-push.outputs.should-push == 'true' }}
build-args: |
BINARY=cloud-provider-equinix-metal
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, mode=max, scope=${{ github.workflow }}