Skip to content

update-chart

update-chart #5

Workflow file for this run

name: update-chart
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to update'
required: true
type: string
key:
description: 'Helm chart name (e.g., webapp, wire-server)'
required: true
type: string
value:
description: 'New value to set (JSON)'
required: true
type: string
jobs:
update:
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Update chart
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: ${{ inputs.branch }}
KEY: ${{ inputs.key }}
VALUE: ${{ inputs.value }}
shell: bash
run: |
set -xeo pipefail
git config --global --add safe.directory "$PWD"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Checkout the specified branch
git fetch origin "$BRANCH"
git checkout "$BRANCH"
# Validate that VALUE contains required fields
REPO=$(echo "$VALUE" | jq -r '.repo // empty')
VERSION=$(echo "$VALUE" | jq -r '.version // empty')
if [[ -z "$REPO" || -z "$VERSION" ]]; then
echo "Error: VALUE must contain both 'repo' and 'version' fields"
exit 1
fi
# Retry loop for updating and pushing
MAX_RETRIES=5
for attempt in $(seq 1 $MAX_RETRIES); do
# Pull latest changes
git pull origin "$BRANCH"
# Update the helm chart to the provided value using jq
jq --arg chart "$KEY" --argjson value "$VALUE" '.helmCharts[$chart] = $value' build.json > build.json.tmp
mv build.json.tmp build.json
# Commit the change
git add build.json
git commit -m "Update $KEY to version $VERSION"
# Try to push
if git push origin "$BRANCH"; then
echo "Successfully pushed on attempt $attempt"
break
else
if [[ $attempt -eq $MAX_RETRIES ]]; then
echo "Failed to push after $MAX_RETRIES attempts"
exit 1
fi
echo "Push failed on attempt $attempt, retrying..."
# Reset to clean state before retry
git fetch origin "$BRANCH"
git reset --hard "origin/$BRANCH"
# Wait random time between 1-5 seconds
sleep_time=$((1 + RANDOM % 5))
echo "Waiting $sleep_time seconds..."
sleep $sleep_time
fi
done