Flux HelmRepository Sync #90
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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: | |
AQUA_CONFIG: ./.github/aqua.yaml | |
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: Install System Tools | |
shell: bash | |
run: sudo apt-get -qq update && sudo apt-get -qq install --no-install-recommends -y curl git jo | |
- name: Cache Aqua | |
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 | |
id: cache | |
with: | |
path: ~/.local/share/aquaproj-aqua | |
key: aqua-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('./.github/aqua.yaml') }} | |
restore-keys: aqua-${{ runner.os }}-${{ runner.arch }}- | |
- name: Install Aqua and CLI Tools | |
uses: aquaproj/aqua-installer@928a2ee4243a9ee8312d80dc8cbaca88fb602a91 # v2.2.0 | |
with: | |
aqua_version: v2.16.4 | |
aqua_opts: -a | |
env: | |
GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}" | |
- 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 }} |