-
-
Notifications
You must be signed in to change notification settings - Fork 14
78 lines (69 loc) · 2.6 KB
/
flux-hr-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
73
74
75
76
77
78
---
name: Flux 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: ["master"]
paths: ["kubernetes/**/helmrelease.yaml"]
env:
DEBCONF_NONINTERACTIVE_SEEN: "true"
DEBIAN_FRONTEND: noninteractive
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE: DontWarn
jobs:
sync:
name: Flux HelmRepository Sync
runs-on: ["arc-runner-set-k8s-gitops"]
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Setup Tools
shell: bash
run: brew install fluxcd/tap/flux yq
- name: Write kubeconfig
id: kubeconfig
uses: timheuer/base64-to-file@784a1a4a994315802b7d8e2084e116e783d157be # v1.2.4
with:
encodedString: "${{ secrets.KUBECONFIG }}"
fileName: kubeconfig
- if: ${{ github.event.inputs.repoNamespace == '' && github.event.inputs.repoName == '' }}
name: Get changed files
id: changed-files
uses: tj-actions/changed-files@94549999469dbfa032becf298d95c87a14c34394 # v40.2.2
with:
files: kubernetes/**/helmrelease.yaml
- if: ${{ github.event.inputs.repoNamespace == '' && github.event.inputs.repoName == '' }}
name: Sync HelmRepository
env:
KUBECONFIG: "${{ steps.kubeconfig.outputs.filePath }}"
shell: bash
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
- if: ${{ github.event.inputs.repoNamespace != '' && github.event.inputs.repoName != '' }}
name: Sync HelmRepository
env:
KUBECONFIG: ${{ steps.kubeconfig.outputs.filePath }}
shell: bash
run: |
flux --namespace ${{ github.event.inputs.repoNamespace }} reconcile \
source helm ${{ github.event.inputs.repoName }}