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.
94 lines
3.8 KiB
94 lines
3.8 KiB
kind: pipeline
|
|
type: kubernetes
|
|
name: update-helm-charts
|
|
|
|
steps:
|
|
# Step 1: Lint all Helm charts
|
|
- name: lint-charts
|
|
image: alpine/helm:latest
|
|
commands:
|
|
- find charts -maxdepth 2 -type d -regex ".*/v[0-9]+\.[0-9]+\.[0-9]+" -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 versioned chart directories (e.g., charts/my-chart/v1.0.0)
|
|
- CHANGED_CHARTS=$(git diff --name-only $DRONE_PREV_COMMIT $DRONE_COMMIT | grep '^charts/.*v[0-9]\+\.[0-9]\+\.[0-9]\+' | 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
|
|
- mkdir -p charts/dist
|
|
depends_on:
|
|
- lint-charts
|
|
|
|
|
|
# Step 3: Fetch the existing index.yaml from Gitea (if it exists)
|
|
- name: fetch-existing-index
|
|
image: alpine:latest
|
|
commands:
|
|
- apk add --no-cache curl 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:
|
|
# Debug: Verify API key presence
|
|
- test -n "$GITEA_API_KEY" || { echo "GITEA_API_KEY is not set"; exit 1; }
|
|
# Debug: Confirm key presence without exposing it
|
|
- "echo API key length: ${GITEA_API_KEY}"
|
|
# Check if gh-pages exists remotely, fetch it if it does, otherwise create it
|
|
- git ls-remote --heads origin gh-pages | grep -q gh-pages && git fetch origin gh-pages && git checkout gh-pages || git checkout -b gh-pages
|
|
# Stage the charts/dist directory (already in the working directory)
|
|
- git add charts/dist/*
|
|
# Commit changes
|
|
- git commit -m "Update Helm charts from commit ${DRONE_COMMIT}" || echo "No changes to commit"
|
|
# Push with API key, ensuring proper variable expansion
|
|
- PUSH_URL="https://x:${GITEA_API_KEY}@git.interlegis.leg.br/SEIT/rancher-charts.git"
|
|
- git push "$PUSH_URL" 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
|