Files
tools/.gitea/workflows/helmcharts.yaml
Gabriel Radureau a1261d6c80
All checks were successful
Helm Charts / Detect changed charts (push) Successful in 50s
Helm Charts / Library charts tool (push) Has been skipped
Helm Charts / Application charts pgcat (push) Has been skipped
workflow dispatch trigger
2025-08-08 12:32:44 +02:00

178 lines
6.5 KiB
YAML

---
# template source: https://github.com/bretfisher/docker-build-workflow/blob/main/templates/call-docker-build.yaml
name: Helm Charts
on: [push,pull_request,workflow_dispatch]
# push: &helmPaths # turns out gitea don't handle well the paths filter
# paths:
# - '*/\.yaml'
# - '*/\.tpl'
# - '*/NOTES.txt'
# - '*/\.helmignore'
# pull_request: *helmPaths
# cancel any previously-started, yet still active runs of this workflow on the same branch
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
.helm_install_dependencies_sh: &helm_install_dependencies_sh |-
helm_install_dependencies() {
chart_file="$1/Chart.yaml"
[[ ! -f "$chart_file" ]] && echo "Chart.yaml not found in $1" && return 1
yq eval '.dependencies[]' "$chart_file" -o=json | jq -c '.' | while IFS= read -r dep; do
name=$(jq -r '.name' <<< "$dep")
version=$(jq -r '.version' <<< "$dep")
repo=$(jq -r '.repository' <<< "$dep")
url=$(curl -s "${repo}/index.yaml" | yq eval ".entries.${name}[] | select(.version == \"${version}\") | .urls[0]" -)
echo "Dependency: $name, Version: $version, URL: $url"
mkdir -p "$1/charts" && curl -sL "$url" -o "$1/charts/${name}-${version}.tgz"
done
}
helm_install_dependencies $chart
jobs:
filter-chart:
name: Detect changed charts
runs-on: ubuntu-latest
outputs:
library_charts: ${{steps.filter-charts.outputs.library_charts}}
application_charts: ${{steps.filter-charts.outputs.application_charts}}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
- name: Filter modified charts
id: filter-charts
run: |
echo "Changed files:"
echo "${{ steps.changed-files.outputs.all_changed_files }}"
# Find unique directories that contain Chart.yaml among the changed files
modified_dirs=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | xargs -n1 dirname | sort -u || true)
# Initialize an array to store directories that contain Chart.yaml
helm_chart_dirs=()
# Function to find the closest directory containing Chart.yaml
find_chart_root() {
dir="$1"
while [[ "$dir" != "/" && "$dir" != "." ]]; do
if [[ -f "$dir/Chart.yaml" ]]; then
echo "$dir"
return
fi
dir=$(dirname "$dir")
done
}
# Iterate over each modified directory and find the root chart directory
for dir in $modified_dirs; do
chart_dir=$(find_chart_root "$dir")
if [[ -n "$chart_dir" && ! " ${helm_chart_dirs[*]} " =~ " ${chart_dir} " ]]; then
helm_chart_dirs+=("$chart_dir")
fi
done
# Initialize arrays for library and application charts
library_dirs=()
application_dirs=()
# Iterate over each modified directory and check the 'type' field in Chart.yaml
for dir in ${helm_chart_dirs[@]}; do
chart_type=$(yq eval '.type' "$dir/Chart.yaml" || echo "undefined")
# Add directories to corresponding arrays based on the 'type'
if [[ "$chart_type" == "library" ]]; then
library_dirs+=("$dir")
elif [[ "$chart_type" == "application" ]]; then
application_dirs+=("$dir")
fi
done
# Convert the arrays to JSON format
library_json=$(printf '%s\n' "${library_dirs[@]}" | jq -R . | jq -cs 'map(select(. != ""))')
application_json=$(printf '%s\n' "${application_dirs[@]}" | jq -R . | jq -cs 'map(select(. != ""))')
# Output the JSON arrays
echo "Modified Helm library charts directories: $library_json"
echo "library_charts=$library_json" >> $GITHUB_OUTPUT
echo "Modified Helm application charts directories: $application_json"
echo "application_charts=$application_json" >> $GITHUB_OUTPUT
library-charts: &charts-matrix-job
name: Library charts ${{ matrix.chart }}
runs-on: ubuntu-latest
needs: filter-chart
strategy:
matrix:
chart: [tool] # turns out gitea doesn't support dynamic matrix
# chart: ${{ fromJson(needs.filter-chart.outputs.library_charts) }}
type: [library]
if: >-
${{
always() && !contains(needs.*.result, 'failure') && needs.filter-chart.result == 'success'
&& (
contains(fromJson(needs.filter-chart.outputs.library_charts), matrix.chart)
|| contains(fromJson(needs.filter-chart.outputs.application_charts), matrix.chart)
)
&& (
contains(fromJSON('["","pull_request"]'), github.event_name)
|| github.ref == 'refs/heads/main'
) }}
env:
chart: ${{ matrix.chart }}
steps:
- uses: actions/checkout@v4
- run: *helm_install_dependencies_sh
- name: Install Helm for test
if: >-
${{
matrix.type != 'library'
&& (
contains(fromJSON('["","pull_request"]'), github.event_name)
|| github.ref != 'refs/heads/main'
)
}}
uses: azure/setup-helm@v4
- name: Helm template
if: >-
${{
matrix.type != 'library'
&& (
contains(fromJSON('["","pull_request"]'), github.event_name)
|| github.ref != 'refs/heads/main'
)
}}
run: helm template $chart --debug
- name: publish ${{ matrix.chart }} helm chart
if: ${{ contains(fromJSON('["","push"]'), github.event_name) && github.ref == 'refs/heads/main' }}
run: |
set -x
chart=${chart:-tool}
chart_version=`yq eval .version ${chart}/Chart.yaml`
chart_package=${chart}-${chart_version}.tgz
# helm package ${chart}
tar -X ${chart}/.helmignore -czf ${chart_package} ${chart}
curl --user ${{ github.actor }}:${{ secrets.PACKAGES_TOKEN }} -X POST --upload-file ./${chart_package} https://gitea.arcodange.duckdns.org/api/packages/${{ github.repository_owner }}/helm/api/charts
application-charts:
<<: *charts-matrix-job
name: Application charts ${{ matrix.chart }}
needs: [filter-chart,library-charts]
strategy:
matrix:
# chart: ${{ fromJson(needs.filter-chart.outputs.application_charts) }}
chart: [pgcat]
type: [application]