generated from onedr0p/cluster-template
-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (64 loc) · 2.31 KB
/
helmrepository-sync.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
---
name: "HelmRepository Sync"
on:
workflow_dispatch:
inputs:
repoName:
description: "Flux HelmRepository Name"
required: true
repoNamespace:
description: "Flux HelmRepository Namespace"
default: "flux-system"
required: true
pull_request:
branches: ["main"]
paths: ["kubernetes/**/helmrelease.yaml"]
jobs:
sync:
name: Flux HelmRepository Sync
runs-on: ["self-hosted"]
steps:
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
with:
fetch-depth: 0
- name: Setup Kube Tools
uses: yokawasa/action-setup-kube-tools@5fe385031665158529decddddb51d6224422836e # v0.11.1
with:
setup-tools: |
yq
- name: Setup Flux
uses: fluxcd/flux2/action@896e0fa46d5107a05e953dd0a5261d78a145ec8c # v2.3.0
- name: Write kubeconfig
id: kubeconfig
uses: timheuer/base64-to-file@adaa40c0c581f276132199d4cf60afa07ce60eac # v1.2
with:
encodedString: ${{ secrets.KUBECONFIG }}
fileName: kubeconfig
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c # v44.5.7
with:
files: |
kubernetes/**/helmrelease.yaml
- name: Sync HelmRepository
env:
KUBECONFIG: ${{ steps.kubeconfig.outputs.filePath }}
run: |
declare -a repos=()
for file in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do
repoName="$(yq eval '.spec.chart.spec.sourceRef.name' "${file}")"
repoNamespace="$(yq eval '.spec.chart.spec.sourceRef.namespace' "${file}")"
repos+=("${repoName}:${repoNamespace}")
done
repos=($(for r in ${repos[@]}; do echo $r; done | sort -u))
for repo in ${repos[@]}; do
flux --namespace "${repo##*:}" reconcile source helm "${repo%%:*}"
done
- name: Sync HelmRepository
if: ${{ github.event.inputs.repoName != '' }}
env:
KUBECONFIG: ${{ steps.kubeconfig.outputs.filePath }}
run: |
flux --namespace ${{ github.event.inputs.repoNamespace }} reconcile \
source helm ${{ github.event.inputs.repoName }}