-
Notifications
You must be signed in to change notification settings - Fork 2
142 lines (132 loc) · 4.13 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
name: Continuous Integration
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches:
- '*'
- '!dependabot/**'
env:
IMAGE_NAME: ${{ github.repository }}
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: 1.22
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.55.2
args: --verbose
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22
- 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: Build image urls
id: image-urls
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
run: |
IMAGES=ghcr.io/${IMAGE_NAME}
[[ -n "$DOCKER_USERNAME" ]] && IMAGES=${IMAGES},${IMAGE_NAME}
echo "images=${IMAGES}" >> $GITHUB_OUTPUT
- name: Docker manager metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image-urls.outputs.images }}
tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- 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: Build
id: docker_build
uses: docker/build-push-action@v6
env:
VERSION: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
with:
context: .
push: ${{ steps.should-push.outputs.should-push == 'true' }}
build-args: |
BINARY=cloud-provider-cherry
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 }}