After a successful Go image build, uh-cli opens a PR against kacerr/home-kubernetes that bumps the fuj-management Deployment (namespace fuj) to the newly published image tag. Supports workflow_run auto-trigger and workflow_dispatch with dry-run option. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
6.1 KiB
Plan: Gitea Action to open a gitops image-update PR for fuj-management
Context
The Go image of this app is built and pushed by the build-go job in
.gitea/workflows/build.yaml, tagged
gitea.home.hrajfrisbee.cz/kacerr/fuj-management:<git-tag>-go (e.g. 0.37-go).
Kubernetes manifests live in a separate repo,
gitea.home.hrajfrisbee.cz/kacerr/home-kubernetes. Today, bumping the image in
the fuj-management Deployment (namespace fuj) is a manual edit there.
We want CI to automate that bump: when a new Go image is built, open a PR against
home-kubernetes that swaps the image to the freshly built tag — using the
uh-cli gitops deployment update command. The user reviews/merges that PR in
Gitea (matching the existing branch-per-change, merge-in-browser workflow).
Decisions confirmed with the user:
- Separate workflow file (not a job inside build.yaml).
- New
GITOPS_TOKENsecret for home-kubernetes write + PR access. - uh-cli version pinned with a default, overridable via env/var/input.
How uh-cli works (from /Users/jan.novak/srv/go/uh-cli/docs/)
uh-cli gitops deployment updateclones--git-repo, walks--git-pathrecursively for akind: Deploymentwhosemetadata.name/namespacematch, edits the first container image surgically, commits on a new branchgitops/update-<name>-<timestamp>, pushes, and opens the PR itself viatea pr create. PR base is alwaysmain; title/body are hardcoded (no flags).- Requires on PATH:
gitandtea(tea only for the PR flow;--forceskips it). - Auth: token embedded in the
--git-repoURL (https://user:TOKEN@host/...);tea login addfor PR creation; git identity viagit config/env vars. --dry-runprints the unified diff and makes no git changes. Global-v(placed before the subcommand) enables debug logging on stderr.- Release binaries are named
uh-cli-<version>-linux-amd64(version includes thev), attached to the Gitea release. Latest tag today isv0.1.0.
Change: new workflow .gitea/workflows/gitops-update.yaml
Triggers:
workflow_runonworkflows: ["Build and Push"],types: [completed], gated toconclusion == 'success'— auto-fires after the image build succeeds.workflow_dispatchwith inputs:tag(git tag without the-gosuffix, e.g.0.37),dry_run(boolean, default false),uh_cli_version(optional override).
Single job gitops-pr, runs-on: ubuntu-latest, in a container: ubuntu:latest
for a hermetic install (matches the uh-cli CI doc pattern). Steps:
- Install git, curl, ca-certificates, tea — apt-get + download tea
0.9.2fromgitea.com/gitea/tea/releases/...to/usr/local/bin/tea. - Install uh-cli — download
https://gitea.home.hrajfrisbee.cz/kacerr/uh-cli/releases/download/${UH_CLI_VERSION}/uh-cli-${UH_CLI_VERSION}-linux-amd64to/usr/local/bin/uh-cli.UH_CLI_VERSION: ${{ inputs.uh_cli_version || vars.UH_CLI_VERSION || 'v0.1.0' }}. - Resolve image tag — if
workflow_dispatch, useinputs.tag; else usegithub.event.workflow_run.head_branch(the pushed tag name). Outputgitea.home.hrajfrisbee.cz/${{ github.repository }}:<tag>-go. - Configure git identity —
git config --global user.name/emailfor the bot. - Authenticate tea —
tea login add --name ci --url https://gitea.home.hrajfrisbee.cz --token "$GITEA_TOKEN". - Open image-update PR — run, with
--dry-runappended only when the dispatchdry_runinput is true:uh-cli -v gitops deployment update \ --deployment-name fuj-management \ --deployment-namespace fuj \ --set-image "<resolved image>" \ --git-repo "https://fuj-gitops-bot:${GITEA_TOKEN}@gitea.home.hrajfrisbee.cz/kacerr/home-kubernetes" \ --git-path gitops/home-kubernetes
GITEA_TOKEN is sourced from secrets.GITOPS_TOKEN at job level.
Job-level guard: if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}.
Prerequisites (user must set up in Gitea — call out in handoff)
- Create
GITOPS_TOKENsecret in thefuj-managementrepo: a Gitea token for a user (fuj-gitops-botorkacerr) that has write + pull-request access tokacerr/home-kubernetes. The username in the--git-repoURL must match that token's owner (adjustfuj-gitops-botif usingkacerr). - uh-cli
v0.1.0release assets must exist (theuh-cli-v0.1.0-linux-amd64binary attached to the release). If not yet published, cut that release in the uh-cli repo first, or setUH_CLI_VERSIONto a published tag. - Confirm the manifest path:
--git-path gitops/home-kubernetesmust contain thefuj-managementDeployment;--deployment-namespace fujdisambiguates. Cannot verify from this repo — verify against home-kubernetes (narrow the path if uh-cli reports an ambiguity error).
Files
- New:
.gitea/workflows/gitops-update.yaml(the workflow above). - After it works: prepend a
CHANGELOG.mdentry; save this plan todocs/plans/<ts>-gitops-pr-action.mdper CLAUDE.md convention.
Branching
Feature work → branch feat/gitops-pr-action off main, commit with the
Co-Authored-By trailer, push with -u, open the MR with
tea pr create --base main --head feat/gitops-pr-action. Do not merge from CLI.
Verification
- Dry run (manual): trigger
gitops-update.yamlvia workflow_dispatch withtag=0.37,dry_run=true. Confirm logs show the unified diff (image line…:0.37-go) and-vdebug milestones; no PR is created. - Real run (manual): re-trigger with
dry_run=false. Confirm a PR appears inhome-kubernetesagainstmainwith the image bump, and the PR URL is printed. - Auto-trigger: push a new git tag to fuj-management →
Build and Pushcompletes →gitops-updatefires viaworkflow_runand opens the PR. (Note:workflow_run/head_branchbehavior depends on this Gitea/act_runner version; if it doesn't fire, manualworkflow_dispatchis the fallback and the plan still delivers the core capability.)