69 lines
2.1 KiB
YAML
69 lines
2.1 KiB
YAML
name: bump-stacks
|
||
description: |
|
||
Push the new short sha for a stack into libretech/gitops-sandbox/stacks.yml.
|
||
Idempotent: a no-op when the sha is already pinned. Retries up to 3× on
|
||
non-fast-forward to absorb concurrent bumps from sibling stack repos.
|
||
|
||
inputs:
|
||
stack:
|
||
description: stack name (key under `stacks:` in stacks.yml)
|
||
required: true
|
||
sha:
|
||
description: short git sha (7 chars) of the image tag just pushed
|
||
required: true
|
||
bot_token:
|
||
description: PAT with write:repository on libretech/gitops-sandbox
|
||
required: true
|
||
sandbox_repo:
|
||
description: orchestrator repo slug
|
||
required: false
|
||
default: libretech/gitops-sandbox
|
||
|
||
runs:
|
||
using: composite
|
||
steps:
|
||
- shell: bash
|
||
env:
|
||
STACK: ${{ inputs.stack }}
|
||
SHA: ${{ inputs.sha }}
|
||
BOT_TOKEN: ${{ inputs.bot_token }}
|
||
SANDBOX_REPO: ${{ inputs.sandbox_repo }}
|
||
ACTION_PATH: ${{ github.action_path }}
|
||
run: |
|
||
set -euo pipefail
|
||
WORK=$(mktemp -d)
|
||
cd "$WORK"
|
||
git config --global user.name "gitops-bot"
|
||
git config --global user.email "gitops-bot@librete.ch"
|
||
|
||
REPO_URL="https://oauth2:${BOT_TOKEN}@git.librete.ch/${SANDBOX_REPO}.git"
|
||
for attempt in 1 2 3; do
|
||
rm -rf clone
|
||
git clone --depth=2 "$REPO_URL" clone
|
||
cd clone
|
||
[ -f package.json ] || echo '{"type":"module","dependencies":{"yaml":"^2.6.1"}}' > package.json
|
||
bun install --silent
|
||
|
||
set +e
|
||
bun "$ACTION_PATH/bump.js" "$STACK" "$SHA"
|
||
rc=$?
|
||
set -e
|
||
if [ "$rc" = "10" ]; then
|
||
echo "::notice::stacks.yml already at sha=$SHA, no commit"
|
||
exit 0
|
||
fi
|
||
[ "$rc" = "0" ] || exit "$rc"
|
||
|
||
git add stacks.yml
|
||
git commit -m "bump(${STACK}): sha=${SHA}"
|
||
if git push origin main; then
|
||
echo "::notice::pushed bump for ${STACK} to ${SANDBOX_REPO}"
|
||
exit 0
|
||
fi
|
||
echo "push rejected, attempt ${attempt}/3"
|
||
cd ..
|
||
sleep $((attempt * 3))
|
||
done
|
||
echo "::error::could not push bump after 3 attempts"
|
||
exit 1
|