update linting workflows
All checks were successful
renovate / renovate (push) Successful in 50s

This commit is contained in:
2025-12-03 19:49:32 -06:00
parent 58c418a05e
commit f6017099fc
2 changed files with 175 additions and 65 deletions

View File

@@ -5,11 +5,16 @@ on:
branches: branches:
- main - main
paths: paths:
- 'clusters/**' - 'clusters/*/helm/**'
env:
CLUSTER: cl01tl
BASE_BRANCH: "origin/${{ gitea.base_ref }}"
jobs: jobs:
helm-lint: lint-pull-request:
runs-on: ubuntu-js runs-on: ubuntu-js
if: github.event_name == 'pull_request'
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
@@ -18,64 +23,116 @@ jobs:
- name: Check Branch Exists - name: Check Branch Exists
id: check-branch-exists id: check-branch-exists
if: github.event_name == 'pull_request'
uses: GuillaumeFalourd/branch-exists@v1.1 uses: GuillaumeFalourd/branch-exists@v1.1
with: with:
branch: ${{ github.base_ref }} branch: ${{ gitea.base_ref }}
- name: Branch Does Not Exist - name: Branch Exists
if: steps.check-branch-exists.outputs.exists == 'false' id: branch-exists
run: echo "Branch ${{ github.base_ref }} was not found, likely already merged" if: github.event_name == 'push' || steps.check-branch-exists.outputs.exists == 'true' && github.event_name == 'pull_request'
run: |
echo ">> Branch ${{ gitea.base_ref }} is exists, will continue with linting"
echo "----"
echo "exists=true" >> $GITEA_OUTPUT
- name: Set up Helm - name: Set up Helm
if: steps.check-branch-exists.outputs.exists == 'true' if: steps.branch-exists.outputs.exists == 'true'
uses: azure/setup-helm@v4 uses: azure/setup-helm@v4
with: with:
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
version: v3.19.2 version: v3.19.2
- name: Lint Helm Chart - name: Lint Helm Chart
if: steps.check-branch-exists.outputs.exists == 'true' if: steps.branch-exists.outputs.exists == 'true'
run: | run: |
set -e # Exit immediately if a command exits with a non-zero status. CHANGED_CHARTS=()
TARGET_BRANCH="origin/${{ github.base_ref }}" echo ">> Target branch for diff is: ${BASE_BRANCH}"
echo ">> Target branch for diff is: $TARGET_BRANCH" echo ""
echo ">> Checking for changes ..."
GIT_DIFF=$(git diff --name-only "${BASE_BRANCH}" -- | xargs -I {} dirname {} | sort -u | grep 'clusters/*/helm/')
CHANGED_FILES=$(git diff --name-only "$TARGET_BRANCH" -- 'clusters/**') if [ -n "${GIT_DIFF}" ]; then
echo ""
echo ">> Changes detected:"
echo "$GIT_DIFF"
echo ">> Found changed files:" for path in $GIT_DIFF; do
echo "$CHANGED_FILES" CHANGED_CHARTS+=$(echo "$path" | awk -F '/' '{print $4}')
# For each changed file, find its parent chart directory (the one with Chart.yaml).
# Then, create a unique list of those directories.
CHANGED_CHARTS=$(echo "$CHANGED_FILES" | while read -r file; do
dir=$(dirname "$file")
while [[ "$dir" != "." && ! -f "$dir/Chart.yaml" ]]; do
dir=$(dirname "$dir")
done done
if [[ "$dir" != "." ]]; then
echo "$dir"
fi
done | sort -u)
if [[ -z "$CHANGED_CHARTS" ]]; then else
echo ">> Could not determine changed charts. This could happen if only files outside a chart were changed." echo ""
exit 0 echo ">> No changes detected"
fi fi
echo ">> Running helm lint on changed charts:" if [ -n "${CHANGED_CHARTS}" ]; then
echo "$CHANGED_CHARTS" echo ""
echo ">> Chart to Lint:"
echo "$(echo "${CHANGED_CHARTS[@]}" | sort -u)"
echo "$CHANGED_CHARTS" | while read -r chart; do echo "----"
helm dependency list --max-col-width 120 $chart 2> /dev/null \
echo "changes-detected=true" >> $GITEA_OUTPUT
echo "chart-dir<<EOF" >> $GITEA_OUTPUT
echo "$(echo "${CHANGED_CHARTS[@]}" | sort -u)" >> $GITEA_OUTPUT
echo "EOF" >> $GITEA_OUTPUT
else
echo "changes-detected=false" >> $GITEA_OUTPUT
fi
- name: Add Repositories
if: steps.branch-exists.outputs.exists == 'true'
env:
CHANGED_CHARTS: ${{ steps.check-dir-changes.outputs.chart-dir }}
run: |
echo ">> Adding repositories for chart dependencies ..."
for dir in ${CHANGED_CHARTS}; do
helm dependency list --max-col-width 120 clusters/${CLUSTER}/helm/$dir 2> /dev/null \
| tail +2 | head -n -1 \ | tail +2 | head -n -1 \
| awk '{ print "helm repo add " $1 " " $3 }' \ | awk '{ print "helm repo add " $1 " " $3 }' \
| while read cmd; do echo "$cmd" | sh; done || true | while read cmd; do echo "$cmd" | sh; done || true
done
echo ">> Building dependency for "$chart" ..." if helm repo list | tail +2 | read -r; then
helm dependency build "$chart" echo ""
echo ">> Linting $chart..." echo ">> Update repository cache ..."
helm lint "$chart" helm repo update
fi
echo "----"
- name: Lint Helm Chart
if: steps.branch-exists.outputs.exists == 'true'
env:
CHANGED_CHARTS: ${{ steps.check-dir-changes.outputs.chart-dir }}
run: |
echo ">> Running linting on changed charts ..."
for dir in ${CHANGED_CHARTS}; do
chart_path=clusters/${CLUSTER}/helm/$dir
chart_name=$(basename "$chart_path")
if [ -f "$chart_path/Chart.yaml" ]; then
cd $chart_path
echo ""
echo ">> Building helm dependency ..."
helm dependency build --skip-refresh
echo ""
echo ">> Linting helm ..."
helm lint --namespace "$chart_name"
else
echo ""
echo ">> Directory $chart_path does not contain a Chart.yaml. Skipping ..."
echo ""
fi
done done
- name: ntfy Failed - name: ntfy Failed

View File

@@ -5,11 +5,16 @@ on:
branches: branches:
- main - main
paths: paths:
- 'clusters/**' - 'clusters/*/helm/**'
env:
CLUSTER: cl01tl
BASE_BRANCH: "origin/${{ gitea.base_ref }}"
jobs: jobs:
helm-lint: lint-push:
runs-on: ubuntu-js runs-on: ubuntu-js
if: github.event_name == 'push'
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v6 uses: actions/checkout@v6
@@ -22,46 +27,94 @@ jobs:
token: ${{ secrets.GITEA_TOKEN }} token: ${{ secrets.GITEA_TOKEN }}
version: v3.19.2 version: v3.19.2
- name: Lint Helm Chart - name: Check which Directories have Changes
id: check-dir-changes
run: | run: |
TARGET_BRANCH="origin/main" CHANGED_CHARTS=()
echo ">> Target branch for diff is: $TARGET_BRANCH"
CHANGED_FILES=$(git diff --name-only "$TARGET_BRANCH" -- 'clusters/**') echo ">> Target branch for diff is: ${BASE_BRANCH}"
echo ""
echo ">> Checking for changes ..."
GIT_DIFF=$(git diff --name-only "${BASE_BRANCH}" -- | xargs -I {} dirname {} | sort -u | grep 'clusters/*/helm/')
echo ">> Found changed files:" if [ -n "${GIT_DIFF}" ]; then
echo "$CHANGED_FILES" echo ""
echo ">> Changes detected:"
echo "$GIT_DIFF"
# For each changed file, find its parent chart directory (the one with Chart.yaml). for path in $GIT_DIFF; do
# Then, create a unique list of those directories. CHANGED_CHARTS+=$(echo "$path" | awk -F '/' '{print $4}')
CHANGED_CHARTS=$(echo "$CHANGED_FILES" | while read -r file; do
dir=$(dirname "$file")
while [[ "$dir" != "." && ! -f "$dir/Chart.yaml" ]]; do
dir=$(dirname "$dir")
done done
if [[ "$dir" != "." ]]; then
echo "$dir"
fi
done | sort -u)
if [[ -z "$CHANGED_CHARTS" ]]; then else
echo ">> Could not determine changed charts. This could happen if only files outside a chart were changed." echo ""
exit 0 echo ">> No changes detected"
fi fi
echo ">> Running helm lint on changed charts:" if [ -n "${CHANGED_CHARTS}" ]; then
echo "$CHANGED_CHARTS" echo ""
echo ">> Chart to Lint:"
echo "$(echo "${CHANGED_CHARTS[@]}" | sort -u)"
echo "$CHANGED_CHARTS" | while read -r chart; do echo "----"
helm dependency list --max-col-width 120 $chart 2> /dev/null \
echo "changes-detected=true" >> $GITEA_OUTPUT
echo "chart-dir<<EOF" >> $GITEA_OUTPUT
echo "$(echo "${CHANGED_CHARTS[@]}" | sort -u)" >> $GITEA_OUTPUT
echo "EOF" >> $GITEA_OUTPUT
else
echo "changes-detected=false" >> $GITEA_OUTPUT
fi
- name: Add Repositories
if: steps.check-dir-changes.outputs.changes-detected == 'true'
env:
CHANGED_CHARTS: ${{ steps.check-dir-changes.outputs.chart-dir }}
run: |
echo ">> Adding repositories for chart dependencies ..."
for dir in ${CHANGED_CHARTS}; do
helm dependency list --max-col-width 120 clusters/${CLUSTER}/helm/$dir 2> /dev/null \
| tail +2 | head -n -1 \ | tail +2 | head -n -1 \
| awk '{ print "helm repo add " $1 " " $3 }' \ | awk '{ print "helm repo add " $1 " " $3 }' \
| while read cmd; do echo "$cmd" | sh; done || true | while read cmd; do echo "$cmd" | sh; done || true
done
echo ">> Building dependency for "$chart" ..." if helm repo list | tail +2 | read -r; then
helm dependency build "$chart" echo ""
echo ">> Linting $chart..." echo ">> Update repository cache ..."
helm lint "$chart" helm repo update
fi
echo "----"
- name: Lint Helm Chart
if: steps.check-dir-changes.outputs.changes-detected == 'true'
env:
CHANGED_CHARTS: ${{ steps.check-dir-changes.outputs.chart-dir }}
run: |
echo ">> Running linting on changed charts ..."
for dir in ${CHANGED_CHARTS}; do
chart_path=clusters/${CLUSTER}/helm/$dir
chart_name=$(basename "$chart_path")
if [ -f "$chart_path/Chart.yaml" ]; then
cd $chart_path
echo ""
echo ">> Building helm dependency ..."
helm dependency build --skip-refresh
echo ""
echo ">> Linting helm ..."
helm lint --namespace "$chart_name"
else
echo ""
echo ">> Directory $chart_path does not contain a Chart.yaml. Skipping ..."
echo ""
fi
done done
- name: ntfy Failed - name: ntfy Failed