-
Notifications
You must be signed in to change notification settings - Fork 117
341 lines (293 loc) · 12.2 KB
/
pipeline.yaml
File metadata and controls
341 lines (293 loc) · 12.2 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
name: Pipeline
on:
push:
branches:
- "**" # Matches all branches
pull_request:
branches:
- "**" # Matches all branches
workflow_dispatch:
inputs:
force_build:
description: "Forces a build even if no changes are detected"
required: true
default: "false"
force_release:
description: "Forces a release even if no changes are detected"
required: true
default: "false"
concurrency:
group: pipeline-${{ github.ref_name }}
cancel-in-progress: true
env:
helm_chart: "reflector"
helm_chart_dir: "src/helm/reflector"
helm_chart_repository: "ghcr.io/emberstack/helm-charts"
helm_chart_repository_protocol: "oci://"
container_image: "kubernetes-reflector"
container_image_build_context: "."
container_image_build_platforms: "linux/amd64,linux/arm/v7,linux/arm64"
container_image_build_dockerfile: "src/ES.Kubernetes.Reflector/Dockerfile"
container_image_repository_dockerhub: "emberstack"
container_image_repository_ghcr: "ghcr.io/emberstack"
jobs:
discovery:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
pathsFilter_src: ${{ steps.pathsFilter.outputs.src }}
gitVersion_SemVer: ${{ steps.gitversion.outputs.GitVersion_SemVer }}
gitVersion_AssemblySemFileVer: ${{ steps.gitversion.outputs.GitVersion_AssemblySemFileVer }}
build: ${{ steps.evaluate_build.outputs.result }}
build_push: ${{ steps.evaluate_build_push.outputs.result }}
build_configuration: ${{ steps.evaluate_build_configuration.outputs.result }}
release: ${{ steps.evaluate_release.outputs.result }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: tools - dotnet - install
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
- name: tools - gitversion - install
uses: gittools/actions/gitversion/setup@v3.2.1
with:
versionSpec: "5.x"
preferLatestVersion: true
- name: gitversion - execute
id: gitversion
uses: gittools/actions/gitversion/execute@v3.2.1
with:
useConfigFile: true
configFilePath: GitVersion.yaml
- name: tools - detect changes
id: pathsFilter
uses: dorny/paths-filter@v3
with:
base: ${{ github.ref }}
filters: |
src:
- '*.sln'
- '*.slnx'
- '*.props'
- 'src/**'
build:
- '*.sln'
- '*.slnx'
- '*.props'
- 'src/**'
- 'tests/**'
- 'playground/**'
- name: evaluate - build
id: evaluate_build
run: |
if [ "${{ steps.pathsFilter.outputs.build }}" = "true" ] || \
[ "${{ github.event.inputs.force_build }}" = "true" ] || \
[ "${{ github.event.inputs.force_release }}" = "true" ]; then
result=true
else
result=false
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: evaluate - build_push
id: evaluate_build_push
run: |
if [ "${{ steps.pathsFilter.outputs.src }}" = "true" ] || \
[ "${{ github.event.inputs.force_build }}" = "true" ]; then
result=true
else
result=false
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: evaluate - build_configuration
id: evaluate_build_configuration
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
result=Release
else
result=Debug
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: evaluate - release
id: evaluate_release
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ] || \
[ "${{ github.event.inputs.force_release }}" = "true" ]; then
result=true
else
result=false
fi
echo "result=$result" >> $GITHUB_OUTPUT
build:
name: build
if: ${{ needs.discovery.outputs.build == 'true' }}
needs: [discovery]
runs-on: ubuntu-latest
env:
build: ${{ needs.discovery.outputs.build }}
build_push: ${{ needs.discovery.outputs.build_push }}
build_configuration: ${{ needs.discovery.outputs.build_configuration }}
gitVersion_SemVer: ${{ needs.discovery.outputs.gitVersion_SemVer }}
gitVersion_AssemblySemFileVer: ${{ needs.discovery.outputs.gitVersion_AssemblySemFileVer }}
steps:
- name: checkout
uses: actions/checkout@v4
- name: artifacts - prepare directories
run: |
mkdir -p .artifacts/helm
mkdir -p .artifacts/kubectl
- name: tools - dotnet - install
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.x"
- name: dotnet - restore
run: dotnet restore
- name: dotnet - build
run: dotnet build --no-restore --configuration ${{ env.build_configuration }} /p:Version=${{ env.gitVersion_SemVer }} /p:AssemblyVersion=${{env.gitVersion_AssemblySemFileVer}} /p:NuGetVersion=${{env.gitVersion_SemVer}}
- name: dotnet - test
run: dotnet test --no-build --configuration ${{ env.build_configuration }} --verbosity normal
- name: tests - report
uses: dorny/test-reporter@v2
if: ${{ github.event.pull_request.head.repo.fork == false }}
with:
name: Test Results
path: .artifacts/TestResults/*.trx
reporter: dotnet-trx
fail-on-empty: "false"
- name: tools - helm - install
uses: azure/setup-helm@v4
- name: tools - helm - login - ghcr.io
if: ${{ env.build_push == 'true' }}
run: echo "${{ secrets.ES_GITHUB_PAT }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
- name: tools - docker - login ghcr.io
if: ${{ env.build_push == 'true' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.ES_GITHUB_PAT }}
- name: tools - docker - login docker.io
if: ${{ env.build_push == 'true' }}
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.ES_DOCKERHUB_USERNAME }}
password: ${{ secrets.ES_DOCKERHUB_PAT }}
- name: tools - docker - register QEMU
run: |
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- name: tools - docker - setup buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container # REQUIRED for multi-platform builds
- name: helm - import README
run: cp README.md ${{ env.helm_chart_dir }}/README.md
- name: helm - package chart
run: helm package --destination .artifacts/helm --version ${{ env.gitVersion_SemVer }} --app-version ${{ env.gitVersion_SemVer }} ${{ env.helm_chart_dir }}
- name: helm - template chart
run: helm template --namespace kube-system ${{ env.helm_chart }} .artifacts/helm/${{ env.helm_chart }}-${{ env.gitVersion_SemVer }}.tgz > .artifacts/kubectl/${{ env.helm_chart }}.yaml
- name: docker - build and push
uses: docker/build-push-action@v6
with:
context: ${{ env.container_image_build_context }}
file: ${{ env.container_image_build_dockerfile }}
build-args: |
BUILD_CONFIGURATION=${{ env.build_configuration }}
push: ${{ env.build_push == 'true' }}
provenance: false
platforms: ${{ env.container_image_build_platforms }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.vendor=https://github.com/${{ github.repository_owner }}
org.opencontainers.image.version=${{ env.gitVersion_SemVer }}
org.opencontainers.image.revision=${{ github.sha }}
tags: |
${{ env.container_image_repository_dockerhub }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }}
${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }}
- name: helm - push
if: ${{ env.build_push == 'true' }}
run: helm push .artifacts/helm/${{ env.helm_chart }}-${{ env.gitVersion_SemVer }}.tgz ${{ env.helm_chart_repository_protocol }}${{ env.helm_chart_repository }}
- name: artifacts - helm - upload
uses: actions/upload-artifact@v4
with:
name: artifacts-helm-${{env.gitVersion_SemVer}}
path: .artifacts/helm
- name: artifacts - kubectl - upload
uses: actions/upload-artifact@v4
with:
name: artifacts-kubectl-${{env.gitVersion_SemVer}}
path: .artifacts/kubectl
release:
name: release
if: ${{ needs.discovery.outputs.release == 'true' && github.ref == 'refs/heads/main' }}
needs: [discovery, build]
runs-on: ubuntu-latest
env:
gitVersion_SemVer: ${{ needs.discovery.outputs.gitVersion_SemVer }}
gitVersion_AssemblySemFileVer: ${{ needs.discovery.outputs.gitVersion_AssemblySemFileVer }}
steps:
- name: artifacts - helm - download
uses: actions/download-artifact@v4
with:
name: artifacts-helm-${{env.gitVersion_SemVer}}
path: .artifacts/helm
- name: artifacts - kubectl - download
uses: actions/download-artifact@v4
with:
name: artifacts-kubectl-${{env.gitVersion_SemVer}}
path: .artifacts/kubectl
- name: tools - helm - install
uses: azure/setup-helm@v4
- name: tools - helm - login - ghcr.io
run: echo "${{ secrets.ES_GITHUB_PAT }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
- name: tools - oras - install
uses: oras-project/setup-oras@v1
- name: tools - oras - login - ghcr.io
run: echo "${{ secrets.ES_GITHUB_PAT }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
- name: tools - docker - login ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.ES_GITHUB_PAT }}
- name: tools - docker - login docker.io
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.ES_DOCKERHUB_USERNAME }}
password: ${{ secrets.ES_DOCKERHUB_PAT }}
- name: tools - docker - setup buildx
uses: docker/setup-buildx-action@v3
- name: docker - tag and push - latest
run: |
docker buildx imagetools create \
--tag ${{ env.container_image_repository_dockerhub }}/${{ env.container_image }}:latest \
--tag ${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:latest \
--tag ${{ env.container_image_repository_dockerhub }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} \
--tag ${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} \
${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }}
- name: helm - push
run: helm push .artifacts/helm/${{ env.helm_chart }}-${{ env.gitVersion_SemVer }}.tgz ${{ env.helm_chart_repository_protocol }}${{ env.helm_chart_repository }}
- name: github - release - create
uses: softprops/action-gh-release@v2
with:
repository: ${{ github.repository }}
name: v${{ env.gitVersion_SemVer }}
tag_name: v${{ env.gitVersion_SemVer }}
body: The release process is automated.
generate_release_notes: true
token: ${{ secrets.ES_GITHUB_PAT }}
files: |
.artifacts/kubectl/${{ env.helm_chart }}.yaml
- name: github - repository-dispatch - release
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.ES_GITHUB_PAT }}
repository: emberstack/helm-charts
event-type: release
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'