-
Notifications
You must be signed in to change notification settings - Fork 158
240 lines (240 loc) · 7.26 KB
/
main.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
name: main
on:
push:
branches:
- master
tags:
- "*"
pull_request:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
set-safe-directory: true
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
test:
name: test
runs-on: ubuntu-latest
container: golang:1.23-alpine3.20
steps:
- name: Install git
run: apk add --update --no-cache git
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 0
set-safe-directory: true
- name: Test
run: |
scripts/alpine-setup.sh
make test
build:
name: build
runs-on: ubuntu-latest
container: golang:1.23-alpine3.20
strategy:
matrix:
os: [linux, darwin, windows]
arch: [arm64, amd64]
exclude:
- os: windows
arch: arm64
steps:
- name: Install git
run: apk add --update --no-cache git
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
set-safe-directory: true
- name: Build
run: |
git config --global --add safe.directory /__w/kube-no-trouble/kube-no-trouble
scripts/alpine-setup.sh
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} make all
shell: sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Archive release artifacts
uses: actions/upload-artifact@v4
with:
name: release-artifacts-${{ matrix.os }}-${{ matrix.arch }}
path: release-artifacts
build-docker:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
set-safe-directory: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: false
platforms: |
linux/arm64
linux/amd64
build-args: |
GITHUB_REF
GITHUB_SHA
cache-from: type=gha
cache-to: type=gha
integration-test:
name: integration test
needs:
[pre-commit, build, build-docker, test]
runs-on: ubuntu-latest
strategy:
matrix:
k8s_version: [
"kindest/node:v1.19.16",
"kindest/node:v1.20.15",
"kindest/node:v1.21.14",
"kindest/node:v1.22.17",
"kindest/node:v1.23.17",
"kindest/node:v1.24.17",
"kindest/node:v1.25.16",
"kindest/node:v1.26.14",
"kindest/node:v1.27.11",
"kindest/node:v1.28.7",
"kindest/node:v1.29.2"
]
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
set-safe-directory: true
- uses: actions/download-artifact@v4
with:
name: release-artifacts-linux-amd64
path: release-artifacts
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
node_image: ${{ matrix.k8s_version }}
cluster_name: kubent-test-cluster
- name: run integration test
run: |
tar xvzf release-artifacts/kubent-*-linux-amd64.tar.gz
kubectl version
kubectl cluster-info --context kind-kubent-test-cluster
./kubent
create-release:
name: Create Release
needs:
[integration-test]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
tag_name: ${{ steps.get_tag.outputs.git_tag }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
set-safe-directory: true
- name: Generate a changelog
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: cliff.toml
args: --verbose --latest
env:
OUTPUT: changelog.md
- uses: actions/download-artifact@v4
with:
name: release-artifacts-linux-amd64
path: release-artifacts
- name: Get the tag
id: get_tag
run: echo ::set-output name=git_tag::${GITHUB_REF/refs\/tags\//}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_tag.outputs.git_tag }}
release_name: ${{ steps.get_tag.outputs.git_tag }}
body_path: ${{ steps.git-cliff.outputs.changelog }}
draft: ${{ startsWith(steps.get_tag.outputs.git_tag, 'nightly') != true }}
prerelease: ${{ startsWith(steps.get_tag.outputs.git_tag, 'nightly') }}
push-image:
name: Push Image
needs:
[create-release]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: |
linux/arm64
linux/amd64
tags: |
${{ format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, needs.create-release.outputs.tag_name) }}
${{ ( !startsWith(github.ref, 'refs/tags/nightly') && format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, 'latest') ) || '' }}
build-args: |
GITHUB_REF
GITHUB_SHA
cache-from: type=gha
cache-to: type=gha
release-artifacts:
name: Release Artifacts
needs:
[create-release]
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
arch: [arm64, amd64]
exclude:
- os: windows
arch: arm64
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/download-artifact@v4
with:
name: release-artifacts-${{ matrix.os }}-${{ matrix.arch }}
path: release-artifacts
- name: Upload Release Asset - ${{ matrix.os }}-${{ matrix.arch }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./release-artifacts/kubent-${{ needs.create-release.outputs.tag_name }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
asset_name: kubent-${{ needs.create-release.outputs.tag_name }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
asset_content_type: application/tar+gzip