You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.4 KiB
90 lines
3.4 KiB
kind: pipeline
|
|
type: docker
|
|
name: update-helm-charts
|
|
|
|
steps:
|
|
# Step 1: Lint all Helm charts
|
|
- name: lint-charts
|
|
image: alpine/helm:latest
|
|
commands:
|
|
- find charts -maxdepth 1 -type d -not -path charts -exec helm lint {} \;
|
|
|
|
# Step 2: Package only changed Helm charts
|
|
- name: package-changed-charts
|
|
image: alpine/helm:latest
|
|
commands:
|
|
- mkdir -p charts/dist
|
|
# Detect changed chart directories and package them
|
|
- CHANGED_CHARTS=$(git diff --name-only $DRONE_PREV_COMMIT $DRONE_COMMIT | grep '^charts/' | sed 's|/[^/]*$||' | sort -u)
|
|
- if [ -n "$CHANGED_CHARTS" ]; then echo "$CHANGED_CHARTS" | xargs -I {} helm package {} --destination charts/dist; else echo "No charts changed"; fi
|
|
depends_on:
|
|
- lint-charts
|
|
|
|
# Step 3: Fetch the existing index.yaml from Gitea (if it exists)
|
|
- name: fetch-existing-index
|
|
image: curlimages/curl
|
|
commands:
|
|
- apk add jq
|
|
- LATEST_TAG=$(curl -s -H "Authorization: token $GITEA_API_KEY" https://git.interlegis.leg.br/api/v1/repos/seit/rancher-charts/releases?limit=1 | jq -r '.[0].tag_name')
|
|
- if [ -n "$LATEST_TAG" ]; then curl -L -o charts/dist/index.yaml https://git.interlegis.leg.br/seit/rancher-charts/releases/download/$LATEST_TAG/index.yaml || true; fi
|
|
environment:
|
|
GITEA_API_KEY:
|
|
from_secret: gitea_api_key
|
|
depends_on:
|
|
- package-changed-charts
|
|
|
|
# Step 4: Update index.yaml with changed charts (skip if no changes)
|
|
- name: update-index
|
|
image: alpine/helm:latest
|
|
commands:
|
|
- if [ -n "$(ls charts/dist/*.tgz 2>/dev/null)" ]; then helm repo index charts/dist --url https://git.interlegis.leg.br/seit/rancher-charts/raw/branch/gh-pages/ --merge charts/dist/index.yaml; else echo "No new charts to index"; fi
|
|
depends_on:
|
|
- fetch-existing-index
|
|
|
|
# Step 5: Push charts and index to gh-pages branch without credentials file
|
|
- name: push-to-branch
|
|
image: alpine/git
|
|
commands:
|
|
# Set up the gh-pages branch
|
|
- git fetch origin gh-pages || echo "gh-pages not found, will create it"
|
|
- git checkout gh-pages || git checkout -b gh-pages
|
|
# Copy new chart artifacts
|
|
- mkdir -p charts/dist
|
|
- cp -r $DRONE_WORKSPACE/charts/dist/* charts/dist/
|
|
# Commit changes
|
|
- git add charts/dist/*
|
|
- git commit -m "Update Helm charts from commit ${DRONE_COMMIT}" || echo "No changes to commit"
|
|
# Push with API key in URL and check for failure
|
|
- git push https://x:${GITEA_API_KEY}@git.interlegis.leg.br/seit/rancher-charts.git HEAD:gh-pages --force || { echo "Git push failed"; exit 1; }
|
|
environment:
|
|
GITEA_API_KEY:
|
|
from_secret: gitea_api_key
|
|
when:
|
|
condition: ls charts/dist/*.tgz 2>/dev/null # Only run if there are new .tgz files
|
|
depends_on:
|
|
- update-index
|
|
|
|
# Step 6: Create or update Gitea release with changed artifacts
|
|
- name: release-to-gitea
|
|
image: plugins/gitea-release
|
|
settings:
|
|
api_key:
|
|
from_secret: gitea_api_key
|
|
base_url: https://git.interlegis.leg.br
|
|
files:
|
|
- charts/dist/*.tar.gz
|
|
- charts/dist/index.yaml
|
|
title: "Helm Charts Update - ${DRONE_COMMIT}"
|
|
note: "Updated Helm repository from commit ${DRONE_COMMIT}"
|
|
draft: false
|
|
prerelease: true
|
|
when:
|
|
condition: ls charts/dist/*.tgz 2>/dev/null # Only run if there are new .tgz files
|
|
depends_on:
|
|
- push-to-branch
|
|
|
|
trigger:
|
|
branch:
|
|
- master
|
|
event:
|
|
- push
|