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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: continuous-integration
on:
push:
branches:
- master
- v[1-9].*
tags:
- v[1-9].*
pull_request:
branches:
- master
- v[1-9].*
env:
BUILDTIME_BASE: "golang:1.16.5-alpine3.14"
RUNTIME_BASE: "alpine:3.14"
GO_VERSION: "~1.16.5"
jobs:
# Runs Golangci-lint on the source code
ci-go-lint:
name: ci-go-lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Lint kube-router code
run: |
make lint
# Executes Unit Tests
ci-unit-tests:
name: ci-unit-tests
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run unit tests for kube-router
run: |
make test
env:
DOCKER_BUILD_IMAGE: ${{ env.BUILDTIME_BASE }}
# Builds Kube-Router binary
ci-build-kube-router:
name: ci-build-kube-router
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build kube-router
run: |
make kube-router
# Builds Container on Push Event, not run if there's a Tag Event
ci-build-container:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract branch from github ref - New Push
if: ${{ startsWith(github.ref, 'refs/tags/v') != true && github.event_name != 'pull_request' }}
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Extract tag from github ref - New Release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
shell: bash
run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/})"
id: extract_tag
- name: Build and push - New Push
uses: docker/build-push-action@v2
if: ${{ startsWith(github.ref, 'refs/tags/v') != true && github.event_name != 'pull_request' }}
with:
context: .
platforms: |
linux/amd64
linux/arm64
linux/arm/v7
push: true
build-args: |
BUILDTIME_BASE=${{ env.BUILDTIME_BASE }}
RUNTIME_BASE=${{ env.RUNTIME_BASE }}
tags: cloudnativelabs/kube-router-git:${{ steps.extract_branch.outputs.branch }}
- name: Build and push - New PR
uses: docker/build-push-action@v2
if: github.event_name == 'pull_request'
with:
context: .
# Don't build multi arch images for PR as they take more than 30 min to build
platforms: linux/amd64
push: true
build-args: |
BUILDTIME_BASE=${{ env.BUILDTIME_BASE }}
RUNTIME_BASE=${{ env.RUNTIME_BASE }}
tags: cloudnativelabs/kube-router-git:PR-${{ github.event.pull_request.number }}
- name: Build and push - New Tag
uses: docker/build-push-action@v2
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
context: .
platforms: |
linux/amd64
linux/arm64
linux/arm/v7
push: true
build-args: |
BUILDTIME_BASE=${{ env.BUILDTIME_BASE }}
RUNTIME_BASE=${{ env.RUNTIME_BASE }}
tags: |
cloudnativelabs/kube-router:${{ steps.extract_tag.outputs.tag }}
cloudnativelabs/kube-router:latest
# Runs Go Releaser on Tag Event
ci-goreleaser-tag:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}