workflows/gitops-bump/action.yaml
Noah Holt c1ea61f544 fix(gitops-bump): rebase and retry when another deploy pushed first
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 12:16:41 -06:00

48 lines
1.8 KiB
YAML

name: gitops-bump
description: >
Points the app's kustomize overlay in the gitops repo at the image tag
just pushed (short sha of the triggering commit); ArgoCD picks up the
commit and deploys. Run on the `host` runner label (git + kustomize
installed there).
inputs:
app-name:
description: App name (dir under manifests/ and kustomize image name)
required: true
gitops-repo:
description: owner/name of the gitops repo
required: false
default: nholtware/gitops
gitops-token:
description: Token with write access to the gitops repo (pass secrets.GITOPS_TOKEN)
required: true
registry:
description: Registry host:port (must match build-push)
required: false
default: "192.168.1.230:3000"
runs:
using: composite
steps:
- shell: bash
env:
GITOPS_TOKEN: ${{ inputs.gitops-token }}
run: |
set -euo pipefail
TAG="${GITHUB_SHA:0:8}"
IMAGE="${{ inputs.registry }}/$GITHUB_REPOSITORY_OWNER/${{ inputs.app-name }}"
DIR="$(mktemp -d)"
trap 'rm -rf "$DIR"' EXIT
git clone --depth 1 "http://ci-bot:${GITOPS_TOKEN}@192.168.1.230:3000/${{ inputs.gitops-repo }}.git" "$DIR"
cd "$DIR/manifests/${{ inputs.app-name }}"
kustomize edit set image "${{ inputs.app-name }}=$IMAGE:$TAG"
cd "$DIR"
git -c user.name=ci-bot -c user.email=ci-bot@forgejo.local \
commit -am "${{ inputs.app-name }}: deploy $TAG" || { echo "tag unchanged, nothing to deploy"; exit 0; }
# Another app's deploy may push first: rebase (touches a different dir) and retry.
for i in 1 2 3 4 5; do
git push && exit 0
echo "push rejected (attempt $i), rebasing"
sleep $((i * 2))
git pull --rebase
done
echo "gitops push failed after 5 attempts" >&2
exit 1