-
-
Notifications
You must be signed in to change notification settings - Fork 14
95 lines (84 loc) · 3.31 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
name: Flux HelmRepository Sync
on:
workflow_dispatch:
inputs:
helmRepoNamespace:
description: Helm Repository Namespace
default: flux-system
required: true
helmRepoName:
description: Helm Repository Name
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: Generate Token
uses: actions/create-github-app-token@2986852ad836768dfea7781f31828eb3e17990fa # v1.6.2
id: app-token
with:
app-id: "${{ secrets.BOT_APP_ID }}"
private-key: "${{ secrets.BOT_APP_PRIVATE_KEY }}"
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
token: "${{ steps.app-token.outputs.token }}"
fetch-depth: 0
- name: Setup Tools
shell: bash
run: sudo apt-get -qq update && sudo apt-get -qq install --no-install-recommends -y curl git
- name: Setup Kube Tools
uses: yokawasa/action-setup-kube-tools@af4ebb1af1efd30c5bd84a2e9773355ad6362a33 # v0.9.3
with:
setup-tools: yq
- name: Setup Flux
uses: fluxcd/flux2/action@9b3958825a314eb79495c6993ef397ddbf87f32f # v2.2.1
- name: Write kubeconfig
id: kubeconfig
uses: timheuer/base64-to-file@784a1a4a994315802b7d8e2084e116e783d157be # v1.2.4
with:
encodedString: "${{ secrets.KUBECONFIG }}"
fileName: kubeconfig
- if: ${{ github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
name: Get changed files
id: changed-files
uses: tj-actions/changed-files@56284d80811fb5963a972b438f2870f175e5b7c8 # v40.2.3
with:
files: kubernetes/**/helmrelease.yaml
- if: ${{ github.event.inputs.helmRepoNamespace == '' && github.event.inputs.helmRepoName == '' }}
name: Sync HelmRepository
env:
KUBECONFIG: "${{ steps.kubeconfig.outputs.filePath }}"
shell: bash
run: |
declare -a repos=()
for f in ${{ steps.changed-files.outputs.all_changed_and_modified_files }}; do
repo_namespace="$(yq -r '.spec.chart.spec.sourceRef.namespace' "${f}")"
repo_name="$(yq -r '.spec.chart.spec.sourceRef.name' "${f}")"
repos+=("${repo_namespace}:${repo_name}")
done
mapfile -t repos < <(printf "%s\n" "${repos[@]}" | sort -u)
for r in "${repos[@]}"; do
IFS=':' read -r repo_namespace repo_name <<< "${r}"
flux \
--namespace ${repo_namespace} \
reconcile source helm ${repo_name}
done
- if: ${{ github.event.inputs.helmRepoNamespace != '' && github.event.inputs.helmRepoName != '' }}
name: Sync HelmRepository
env:
KUBECONFIG: ${{ steps.kubeconfig.outputs.filePath }}
shell: bash
run: |
flux \
--namespace ${{ github.event.inputs.helmRepoNamespace }} \
reconcile source helm ${{ github.event.inputs.helmRepoName }}