Skip to content

feat(go-generated): push the regenerated code on Renovate branches (MK8S-516) - #117

Merged
ezekiel-alexrod merged 9 commits into
mainfrom
improvement/MK8S-516-go-generated-renovate-push
Nov 19, 2026
Merged

ezekiel-alexrod merged 9 commits into
mainfrom
improvement/MK8S-516-go-generated-renovate-push

Conversation

@ezekiel-alexrod

@ezekiel-alexrod ezekiel-alexrod commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This adds a push-to-renovate-branches mode to the go-generated workflow of #115: on a Renovate branch, the workflow pushes the regenerated code itself, so a generator bump no longer needs a human commit.

Stacked on #115: the base of this PR becomes main once #115 is merged.

Problem

When Renovate bumps a code generator (oapi-codegen, mockery, controller-tools), its PR only changes go.mod and go.sum. The generated code is not touched, so the repo's generated-files check fails until someone runs the generator and pushes on the Renovate branch. Renovate then sees a commit it did not make, and stops updating that branch (rebases, new versions). Examples: scality/metalk8s-registry-node-agent#203 (oapi-codegen, regenerated by hand on 2026-10-30), scality/platform-uploads-api#96 (red today for this reason).

Renovate can run go generate itself (postUpdateOptions: ["goGenerate"]), but not safely in our setup: it runs every Go command of that step with GIT_CONFIG_* variables that hold the bot's GitHub token, so a bumped generator could read the token of the Renovate App, which can write to all our repos. That was the plan of scality/platform-renovate#62 and scality/devinfra#807, found by their review. Regenerating in CI instead keeps the generator away from any write token.

What changes

  • New inputs push-to-renovate-branches (default false) and actions-app-id, new optional secret ACTIONS_APP_PRIVATE_KEY. Nothing changes for current callers.
  • On a renovate/* branch of the repo (never a fork), the go-generated job runs the commands on the branch head with a read-only token, and uploads the diff of working-directory as an artifact. The check still fails on that commit.
  • A second job, on a fresh GitHub-hosted runner, applies the diff and pushes it with an App token limited to the repo. It never runs the repo code (git hooks off). An App token, because a push made with GITHUB_TOKEN starts no workflow, so the required checks would never run on the new commit.
  • Guards: nothing is pushed when the commands change files outside working-directory or under .github/ (moves included), when files the App already regenerated on the branch still differ (no loop, also with one call per module), or when Renovate moved the branch meanwhile. The push job checks the paths again, since the first job ran the generators. No force-push.
  • A validate-push-inputs job, with no checkout, checks the App config. It fails only when a push is due, and warns otherwise, so Dependabot and fork PRs, which get no Actions secrets, stay green. The App key never reaches the job that runs the generators.
  • docs/go-generated.md explains the mode, its guards and its limits. tests.yaml runs the existing call with the mode on.

Review guide

The push-to-renovate-branch job is the part to read, then the Save the regenerated code step. Feedback welcome on the guards, and on the security trade-off in Known limits.

Testing

Check Result
actionlint on go-generated.yaml and tests.yaml OK
mkdocs build --strict OK
.github/ guard, local git repo: pkg/gen.go, .github/ö.yml, .github/ci.yml, move of .github/workflows/ci.yaml to x/ first pushed, the other three blocked
Loop guard, local git repo with two modules: run 1 module A, run 2 module B, run 3 both still differ A and B push once, then both are blocked
Outside-module guard, working-directory: svc: change in svc/, in ../go.work.sum, new file at the root; and working-directory: . only the changes inside the module are pushed
scality/workflows reads vars.ACTIONS_APP_ID and the ACTIONS_APP_PRIVATE_KEY org secret OK
not verified a real push on a Renovate branch: needs a consumer repo, planned right after this PR, with the App email to add to gitIgnoredAuthors

Known limits

  • The pushed code is what the generators wrote. A compromised generator could put code there, so a PR with a regeneration commit must stay under human review: to keep out of any automerge rule.
  • On a Renovate branch the commands run on the branch head, not on its merge with the base branch.
  • The App's commit email is only known at run time (printed in the run summary). It has to be added to gitIgnoredAuthors in scality/platform-renovate, or Renovate stops updating the branch after the first push.

Out of scope

  • Adoption in each repo, and the gitIgnoredAuthors entry: separate PRs (MK8S-516).

Refs: MK8S-516

@ezekiel-alexrod
ezekiel-alexrod requested a review from a team as a code owner November 17, 2026 15:51
Comment thread .github/workflows/go-generated.yaml Resolved
Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • Validate inputs fails every PR without Actions secrets (Dependabot, forks), so tests.yaml breaks on Dependabot bumps here and in consumers
    - Run the check only when env.RENOVATE_PUSH == 'true'
    - Or emit a warning instead of failing when the secret is missing
    - The outside-working-directory guard runs in the same job as the generators, which can tamper with later steps ($GITHUB_PATH, $GITHUB_ENV, fake git in GOPATH/bin)
    - Re-check in push-to-renovate-branch that all patch paths are under inputs.working-directory, next to the .github/ check

    Review by Claude Code

@ezekiel-alexrod
ezekiel-alexrod force-pushed the improvement/MK8S-516-go-generated-renovate-push branch from 68d0538 to 99274d4 Compare November 18, 2026 10:35
Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • push-to-renovate-branch outside-module guard treats working-directory as a regex (.github/workflows/go-generated.yaml:191), so a . in the path lets sibling dirs like apixv1/ through
    - Match the prefix literally, e.g. awk -v p="${dir}/" 'index($0, p) != 1'

    Review by Claude Code

When Renovate bumps a code generator, its PR changes go.mod but not the
generated code, and the check fails until someone pushes the fix on the
Renovate branch. Renovate then stops updating that branch.

With push-to-renovate-branches, the workflow pushes the regenerated
code itself. The commands still run with a read-only token; a second
job, on a fresh GitHub-hosted runner and without running the
repository code, applies the result and pushes it with an App token
limited to the repository, so the required checks run again on the new
commit. It only pushes changes under working-directory, never under
.github/, stops when files it already regenerated still differ, and
does not force-push.

Refs: MK8S-516
… push

The input check failed every PR that gets no Actions secrets, such as
Dependabot and fork PRs. It now fails only when a push is due, and
warns otherwise.

The outside-working-directory check ran in the job that runs the
generators, so a compromised generator could fake it. The push job now
checks again that every path of the patch is under working-directory.

Refs: MK8S-516
@ezekiel-alexrod
ezekiel-alexrod force-pushed the improvement/MK8S-516-go-generated-renovate-push branch from 99274d4 to 4409b4a Compare November 18, 2026 10:42
Comment thread .github/workflows/go-generated.yaml Resolved
Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • go-generated job references secrets.ACTIONS_APP_PRIVATE_KEY (Validate inputs), so the App key reaches the runner that runs the generators
    - Move the key check to a separate job that runs no repo code, or into push-to-renovate-branch
    - .github/ guard can be skipped by SIGPIPE + pipefail when grep -qz exits early on a large patch
    - Read the name list into a variable before grepping, as done for comm

    Review by Claude Code

The input check read secrets.ACTIONS_APP_PRIVATE_KEY in the job that
runs the generators, so the key reached that runner. It now runs in a
job of its own, with no checkout; RENOVATE_PUSH moves to the workflow
env so both jobs share it.

The .github/ guard piped git diff into grep -q under pipefail: an early
grep exit could kill git diff and hide the match. Read the names into a
variable first, as for the loop guard.

Refs: MK8S-516
Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • push-to-renovate-branch only gates on outputs of the job that ran the generators, and those commands can change $GITHUB_ENV / $GITHUB_PATH there
    - Check inputs.push-to-renovate-branches, pull_request event, renovate/ head ref and same-repo head again in the push job's if (.github/workflows/go-generated.yaml:154)

    Review by Claude Code

The push job ran on the patch output alone, which comes from the job
that runs the generators. A generator can write RENOVATE_PUSH=true to
$GITHUB_ENV there, so a patch could be pushed to a branch that is not a
Renovate one. The job-level if now checks the branch and the repository
itself.

Refs: MK8S-516
Comment thread .github/workflows/tests.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • secrets: inherit (tests.yaml and the new docs example) passes any GIT_ACCESS_TOKEN org/repo secret to the generator job, which may be write-scoped
    - Pass ACTIONS_APP_PRIVATE_KEY (and a read-only GIT_ACCESS_TOKEN if needed) explicitly instead of inherit

    Review by Claude Code

secrets: inherit also hands GIT_ACCESS_TOKEN to the job that runs the
generators, and that org token may not be read-only.

Refs: MK8S-516
Comment thread docs/go-generated.md Resolved
@github-actions

Copy link
Copy Markdown
  • docs/go-generated.md:70 says each per-module call pushes its own commit, but only one push job per run pushes. The others stop on the moved-branch check, or fail on a non-fast-forward push when they race.
    - Say that N modules take N runs to converge.
    - Optionally, treat a rejected non-fast-forward push like the moved-branch case (notice and exit 0), so the push job does not go red.

    Review by Claude Code

Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • push-to-renovate-branch: with one call per module, parallel push jobs race past the ls-remote check and the losing git push fails red instead of exiting with a notice, which contradicts docs/go-generated.md
    - On push failure, re-check ls-remote and exit 0 with the ::notice:: when the branch moved
    - Or adjust the docs to say the other calls may fail on a rejected push

    Review by Claude Code

With one call per module, parallel push jobs can all pass the old
ls-remote check, and the losing push failed red. Push first, and only
when it is rejected check whether the branch moved.

Refs: MK8S-516
@github-actions

Copy link
Copy Markdown

LGTM

Review by Claude Code

Comment thread .github/workflows/go-generated.yaml Resolved
Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • runs-on default changed from ubuntu-24.04 to ubuntu-26.04 (.github/workflows/go-generated.yaml:29, docs/go-generated.md:105). This changes the runner for every current caller, has nothing to do with the push mode, and contradicts "Nothing changes for current callers".
    - Revert to ubuntu-24.04 in the workflow and the docs table
    - Or move the bump to its own PR and mention it in the release notes

    Review by Claude Code

No caller uses it, and every job now runs on ubuntu-26.04.

Refs: MK8S-516
Comment thread .github/workflows/go-generated.yaml Resolved
Comment thread .github/workflows/go-generated.yaml Resolved
@github-actions

Copy link
Copy Markdown
  • Breaking change: the runs-on input from main is removed, and the go-generated job is now hardcoded to ubuntu-26.04
    - Add the runs-on input back (default ubuntu-24.04) and use ${{ inputs.runs-on }} in the go-generated job
    - Add its row back in the inputs table of docs/go-generated.md

    Review by Claude Code

@ezekiel-alexrod
ezekiel-alexrod merged commit 1c3bb83 into main Nov 19, 2026
16 checks passed
@ezekiel-alexrod
ezekiel-alexrod deleted the improvement/MK8S-516-go-generated-renovate-push branch November 19, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants