From 821eba42eec9ab1c29b7b41a10073b87dc46942f Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:20:24 +0100 Subject: [PATCH 1/9] feat(go-generated): push the regenerated code on Renovate branches 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 --- .github/workflows/go-generated.yaml | 124 ++++++++++++++++++++++++++++ .github/workflows/tests.yaml | 5 ++ CLAUDE.md | 2 +- docs/go-generated.md | 55 ++++++++++++ 4 files changed, 185 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index ce41e06..15911db 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -4,6 +4,7 @@ # It runs the commands that regenerate the code (go.sum, mocks, CRDs, ...) and fails # when the result differs from what is committed, so a PR cannot merge with stale # generated files. `git status --porcelain` also sees new untracked files. +# On a Renovate branch, it can also push the regenerated code (push-to-renovate-branches). name: go-generated @@ -27,10 +28,23 @@ on: required: false default: ubuntu-24.04 type: string + push-to-renovate-branches: + description: 'On a renovate/* branch of this repository, push the regenerated code instead of only failing' + required: false + default: false + type: boolean + actions-app-id: + description: 'GitHub App ID used to push the regenerated code (usually vars.ACTIONS_APP_ID)' + required: false + default: '' + type: string secrets: GIT_ACCESS_TOKEN: description: 'Token to fetch private github.com/scality modules' required: false + ACTIONS_APP_PRIVATE_KEY: + description: 'Private key of the GitHub App, required with push-to-renovate-branches' + required: false permissions: contents: read @@ -38,15 +52,37 @@ permissions: jobs: go-generated: runs-on: ${{ inputs.runs-on }} + outputs: + patch: ${{ steps.patch.outputs.patch }} + artifact: ${{ steps.patch.outputs.artifact }} + env: + # Push mode: a renovate/* branch of this repository, never a fork. + RENOVATE_PUSH: >- + ${{ inputs.push-to-renovate-branches && github.event_name == 'pull_request' + && startsWith(github.head_ref, 'renovate/') + && github.event.pull_request.head.repo.full_name == github.repository }} defaults: run: working-directory: ${{ inputs.working-directory }} steps: + # On every PR, so a caller learns about a missing App config before a Renovate PR needs it. + - name: Validate inputs + if: inputs.push-to-renovate-branches + working-directory: ${{ github.workspace }} + env: + APP_ID: ${{ inputs.actions-app-id }} + HAS_KEY: ${{ secrets.ACTIONS_APP_PRIVATE_KEY != '' }} + run: | + if [ -z "$APP_ID" ] || [ "$HAS_KEY" != "true" ]; then + echo "::error::push-to-renovate-branches needs actions-app-id and the ACTIONS_APP_PRIVATE_KEY secret" + exit 1 + fi - name: Checkout uses: actions/checkout@v7 with: # The commands run repo code: keep the job token out of .git/config. persist-credentials: false + ref: ${{ env.RENOVATE_PUSH == 'true' && github.event.pull_request.head.sha || '' }} - name: Set up Go uses: actions/setup-go@v7 with: @@ -67,6 +103,32 @@ jobs: env: COMMANDS: ${{ inputs.commands }} run: bash -euo pipefail -c "$COMMANDS" + # See "Renovate branches" in docs/go-generated.md for the design of the push. + - name: Save the regenerated code for the Renovate branch + id: patch + if: env.RENOVATE_PUSH == 'true' + run: | + outside=$(git status --porcelain -- ':/' ':!.') + if [ -n "$outside" ]; then + echo "::error::The commands changed files outside working-directory, nothing is pushed:" + echo "$outside" + exit 1 + fi + git add -A . + git diff --cached --binary > "$RUNNER_TEMP/regenerated.patch" + if [ -s "$RUNNER_TEMP/regenerated.patch" ]; then + echo "patch=true" >> "$GITHUB_OUTPUT" + # Unique per call: a caller may run this workflow once per module in one run. + echo "artifact=go-generated-patch-${GITHUB_JOB}-$(date +%s%N)" >> "$GITHUB_OUTPUT" + fi + git reset -q + - name: Upload the regenerated code + if: steps.patch.outputs.patch == 'true' + uses: actions/upload-artifact@v7 + with: + name: ${{ steps.patch.outputs.artifact }} + path: ${{ runner.temp }}/regenerated.patch + retention-days: 1 - name: Check that nothing changed env: COMMANDS: ${{ inputs.commands }} @@ -78,3 +140,65 @@ jobs: git diff exit 1 fi + + push-to-renovate-branch: + needs: go-generated + # The check above fails on purpose: the pushed commit starts a new run, which passes. + if: ${{ !cancelled() && needs.go-generated.outputs.patch == 'true' }} + # Not inputs.runs-on: this job holds a write token, so it gets a fresh GitHub-hosted VM. + runs-on: ubuntu-24.04 + steps: + - uses: actions/create-github-app-token@v3 + id: app-token + with: + app-id: ${{ inputs.actions-app-id }} + private-key: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }} + repositories: ${{ github.event.repository.name }} + permission-contents: write + - name: Checkout + uses: actions/checkout@v7 + with: + ref: ${{ github.event.pull_request.head.sha }} + token: ${{ steps.app-token.outputs.token }} + # The loop guard reads every commit of the branch since the base. + fetch-depth: 0 + - name: Download the regenerated code + uses: actions/download-artifact@v7 + with: + name: ${{ needs.go-generated.outputs.artifact }} + path: ${{ runner.temp }} + - name: Commit and push + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + APP_SLUG: ${{ steps.app-token.outputs.app-slug }} + BASE_REF: ${{ github.base_ref }} + HEAD_REF: ${{ github.head_ref }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + user_id=$(gh api "/users/${APP_SLUG}%5Bbot%5D" --jq .id) + email="${user_id}+${APP_SLUG}[bot]@users.noreply.github.com" + git apply --index "$RUNNER_TEMP/regenerated.patch" + # --no-renames: a move out of .github/ must show its old path too. + if git diff --cached --name-only --no-renames -z | grep -qz '^\.github/'; then + echo "::error::The regenerated code changes .github/, it is not pushed." + exit 1 + fi + # Loop guard: files this App already regenerated on the branch, all modules together. + base=$(git merge-base HEAD "origin/${BASE_REF}") + done_files=$(git log --format='%H %ae' "${base}..HEAD" | awk -v e="$email" '$2 == e {print $1}' | + xargs -r -n1 git show --name-only --no-renames --format= | sort -u) + # In a variable: `| grep -q` can stop comm early, and pipefail then hides the match. + again=$(comm -12 <(git diff --cached --name-only --no-renames | sort) <(echo "$done_files")) + if [ -n "$again" ]; then + echo "::error::These files were already regenerated on this branch and still differ:" + echo "$again" + exit 1 + fi + git -c core.hooksPath=/dev/null -c user.name="${APP_SLUG}[bot]" -c user.email="$email" \ + commit -q -m "chore(deps): regenerate the code" + if [ "$(git ls-remote origin "refs/heads/${HEAD_REF}" | cut -f1)" != "$HEAD_SHA" ]; then + echo "::notice::${HEAD_REF} moved since this run started, nothing pushed." + exit 0 + fi + git -c core.hooksPath=/dev/null push origin "HEAD:refs/heads/${HEAD_REF}" + echo "Pushed as ${APP_SLUG}[bot] <${email}>. Add this email to gitIgnoredAuthors in the Renovate config." >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bd2cf78..b0dcacb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -38,8 +38,13 @@ jobs: go-generated: uses: ./.github/workflows/go-generated.yaml + # Push mode only pushes on a renovate/* branch: here it checks the inputs and the + # condition, and stays a plain check. + secrets: inherit with: working-directory: tests/go-generated + push-to-renovate-branches: true + actions-app-id: ${{ vars.ACTIONS_APP_ID }} release-dry-run: uses: ./.github/workflows/release.yaml diff --git a/CLAUDE.md b/CLAUDE.md index d1f5265..9caa8c1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -21,7 +21,7 @@ This is **scality/workflows**, a repository of reusable GitHub Actions workflows | `lfs-warning.yaml` | Validates file sizes in PRs, warns about files not tracked by Git LFS | | `release.yaml` | Computes the next semver off the last GA tag and pushes an annotated `v*` tag | | `promote.yaml` | Creates a GitHub Release from a pushed `v*` tag (pre-release on hyphenated tags) | -| `go-generated.yaml` | Reruns the Go code generation (`go mod tidy`, `go generate`, ...) and fails when the result differs from what is committed | +| `go-generated.yaml` | Reruns the Go code generation (`go mod tidy`, `go generate`, ...) and fails when the result differs from what is committed; can push the regenerated code on Renovate branches | | `claude-code-review.yml` | AI-powered PR review via Anthropic API (Workload Identity Federation), reports costs to `cost-center-review` | | `claude-code-dependency-review.yml` | AI-powered review of Dependabot/Renovate bumps via Anthropic API (Workload Identity Federation), reports costs to `cost-center-review` | diff --git a/docs/go-generated.md b/docs/go-generated.md index 4ff7bfe..17b1fb7 100644 --- a/docs/go-generated.md +++ b/docs/go-generated.md @@ -32,6 +32,58 @@ jobs: make manifests generate ``` +## Renovate branches + +When Renovate bumps a code generator (oapi-codegen, mockery, controller-tools), its PR +changes `go.mod` but not the generated code, so this check fails until someone runs the +commands and pushes on the Renovate branch. Renovate then stops updating that branch. + +With `push-to-renovate-branches`, the workflow pushes the regenerated code itself on a +`renovate/*` branch of the repository. The check still fails on the Renovate commit, and +the pushed commit starts a new run that passes. + +```yaml +jobs: + go-generated: + uses: scality/workflows/.github/workflows/go-generated.yaml@v2 + secrets: inherit + with: + push-to-renovate-branches: true + actions-app-id: ${{ vars.ACTIONS_APP_ID }} +``` + +How it stays safe: + +- The commands run with a read-only token. A second job, which never runs the code of + the repository (git hooks are disabled), applies the result and pushes it. +- The push uses a GitHub App token limited to the repository, because a push made with + `GITHUB_TOKEN` starts no workflow, so the required checks would never run. +- It only runs on a `renovate/*` branch of the repository, never on a fork. +- The pushed commit only holds changes under `working-directory`, never under `.github/`. + When the commands change files outside `working-directory`, nothing is pushed. + Several calls, one per module, each push their own commit. +- It does not loop: when files the App already regenerated on the branch still differ, + the job fails instead of pushing again. +- The push job runs on a fresh GitHub-hosted runner, whatever `runs-on` says: it holds a + write token, and must not share a machine with the job that ran the generators. +- It does not force-push. If Renovate moved the branch meanwhile, it pushes nothing: the + new commit starts its own run, which regenerates again. + +Limits: + +- On a Renovate branch, the commands run on the branch head, not on its merge with the + base branch. A base change that needs regeneration is caught on the next PR. +- The pushed code is what the generators wrote. A compromised generator could add code + there, so keep these PRs under human review: do not automerge a PR that holds a + regeneration commit. + +The inputs are checked on every PR, so a missing App ID or key shows up before a +Renovate PR needs it. + +The commit author is the GitHub App. Add its email, printed in the run summary, to +`gitIgnoredAuthors` in the Renovate config: otherwise Renovate sees a foreign commit and +stops updating the branch. + Code generators run through `go generate` are best declared as `tool` in `go.mod` (`go get -tool github.com/vektra/mockery/v3`): their version is then pinned and updated like any other dependency. @@ -43,9 +95,12 @@ updated like any other dependency. | `commands` | Commands that regenerate the code | `go mod tidy` and `go generate ./...` | | `working-directory` | Directory that holds the `go.mod` | `.` | | `runs-on` | Runner label | `ubuntu-24.04` | +| `push-to-renovate-branches` | Push the regenerated code on a `renovate/*` branch | `false` | +| `actions-app-id` | GitHub App ID used for that push (usually `vars.ACTIONS_APP_ID`) | `''` | ## Secrets | Name | Description | | ------------------ | ------------------------------------------------------------------ | | `GIT_ACCESS_TOKEN` | Optional, to fetch private `github.com/scality` modules. The commands can read it: use a read-only token | +| `ACTIONS_APP_PRIVATE_KEY` | Private key of the GitHub App, required with `push-to-renovate-branches` | From 4409b4a71c260c69c6d92c9a6475e57291d1dd12 Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:30:48 +0100 Subject: [PATCH 2/9] fix(go-generated): warn without secrets, recheck the patch before the 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 --- .github/workflows/go-generated.yaml | 21 ++++++++++++++++++--- docs/go-generated.md | 8 +++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index 15911db..b84459e 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -65,7 +65,8 @@ jobs: run: working-directory: ${{ inputs.working-directory }} steps: - # On every PR, so a caller learns about a missing App config before a Renovate PR needs it. + # An error only when a push is due. Elsewhere a warning, so a caller sees a missing App + # config early, while PRs that get no Actions secrets (Dependabot, forks) stay green. - name: Validate inputs if: inputs.push-to-renovate-branches working-directory: ${{ github.workspace }} @@ -74,8 +75,9 @@ jobs: HAS_KEY: ${{ secrets.ACTIONS_APP_PRIVATE_KEY != '' }} run: | if [ -z "$APP_ID" ] || [ "$HAS_KEY" != "true" ]; then - echo "::error::push-to-renovate-branches needs actions-app-id and the ACTIONS_APP_PRIVATE_KEY secret" - exit 1 + msg="push-to-renovate-branches needs actions-app-id and the ACTIONS_APP_PRIVATE_KEY secret" + if [ "$RENOVATE_PUSH" = "true" ]; then echo "::error::$msg"; exit 1; fi + echo "::warning::$msg" fi - name: Checkout uses: actions/checkout@v7 @@ -173,6 +175,7 @@ jobs: APP_SLUG: ${{ steps.app-token.outputs.app-slug }} BASE_REF: ${{ github.base_ref }} HEAD_REF: ${{ github.head_ref }} + WORKING_DIRECTORY: ${{ inputs.working-directory }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | user_id=$(gh api "/users/${APP_SLUG}%5Bbot%5D" --jq .id) @@ -183,6 +186,18 @@ jobs: echo "::error::The regenerated code changes .github/, it is not pushed." exit 1 fi + # Checked again here: the first job ran the generators, which could fake its checks. + dir="${WORKING_DIRECTORY#./}"; dir="${dir%/}" + if [ -n "$dir" ] && [ "$dir" != "." ]; then + # A literal prefix, not a regex: a "." in working-directory must not match any char. + outside=$(git diff --cached --name-only --no-renames -z | tr '\0' '\n' | + awk -v p="${dir}/" 'index($0, p) != 1') + if [ -n "$outside" ]; then + echo "::error::The patch changes files outside ${dir}/, it is not pushed:" + echo "$outside" + exit 1 + fi + fi # Loop guard: files this App already regenerated on the branch, all modules together. base=$(git merge-base HEAD "origin/${BASE_REF}") done_files=$(git log --format='%H %ae' "${base}..HEAD" | awk -v e="$email" '$2 == e {print $1}' | diff --git a/docs/go-generated.md b/docs/go-generated.md index 17b1fb7..6c98202 100644 --- a/docs/go-generated.md +++ b/docs/go-generated.md @@ -60,7 +60,8 @@ How it stays safe: `GITHUB_TOKEN` starts no workflow, so the required checks would never run. - It only runs on a `renovate/*` branch of the repository, never on a fork. - The pushed commit only holds changes under `working-directory`, never under `.github/`. - When the commands change files outside `working-directory`, nothing is pushed. + When the commands change files outside `working-directory`, nothing is pushed. The push + job checks this again, since the first job ran the generators. Several calls, one per module, each push their own commit. - It does not loop: when files the App already regenerated on the branch still differ, the job fails instead of pushing again. @@ -77,8 +78,9 @@ Limits: there, so keep these PRs under human review: do not automerge a PR that holds a regeneration commit. -The inputs are checked on every PR, so a missing App ID or key shows up before a -Renovate PR needs it. +The inputs are checked on every PR: a missing App ID or key fails the run when a push +is due, and only warns otherwise, so PRs that get no Actions secrets (Dependabot, forks) +stay green. The commit author is the GitHub App. Add its email, printed in the run summary, to `gitIgnoredAuthors` in the Renovate config: otherwise Renovate sees a foreign commit and From 0f70c374abb357eb7ffb55c232618c672f8e3636 Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:46:19 +0100 Subject: [PATCH 3/9] fix(go-generated): keep the App key away from the generators 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 --- .github/workflows/go-generated.yaml | 47 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index b84459e..d8b2bb4 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -49,27 +49,22 @@ on: permissions: contents: read +env: + # Push mode: a renovate/* branch of this repository, never a fork. + RENOVATE_PUSH: >- + ${{ inputs.push-to-renovate-branches && github.event_name == 'pull_request' + && startsWith(github.head_ref, 'renovate/') + && github.event.pull_request.head.repo.full_name == github.repository }} + jobs: - go-generated: - runs-on: ${{ inputs.runs-on }} - outputs: - patch: ${{ steps.patch.outputs.patch }} - artifact: ${{ steps.patch.outputs.artifact }} - env: - # Push mode: a renovate/* branch of this repository, never a fork. - RENOVATE_PUSH: >- - ${{ inputs.push-to-renovate-branches && github.event_name == 'pull_request' - && startsWith(github.head_ref, 'renovate/') - && github.event.pull_request.head.repo.full_name == github.repository }} - defaults: - run: - working-directory: ${{ inputs.working-directory }} + # A job of its own: it reads the App key, so it must not run with the generators. + # An error only when a push is due. Elsewhere a warning, so a caller sees a missing App + # config early, while PRs that get no Actions secrets (Dependabot, forks) stay green. + validate-push-inputs: + if: inputs.push-to-renovate-branches + runs-on: ubuntu-24.04 steps: - # An error only when a push is due. Elsewhere a warning, so a caller sees a missing App - # config early, while PRs that get no Actions secrets (Dependabot, forks) stay green. - name: Validate inputs - if: inputs.push-to-renovate-branches - working-directory: ${{ github.workspace }} env: APP_ID: ${{ inputs.actions-app-id }} HAS_KEY: ${{ secrets.ACTIONS_APP_PRIVATE_KEY != '' }} @@ -79,6 +74,16 @@ jobs: if [ "$RENOVATE_PUSH" = "true" ]; then echo "::error::$msg"; exit 1; fi echo "::warning::$msg" fi + + go-generated: + runs-on: ${{ inputs.runs-on }} + outputs: + patch: ${{ steps.patch.outputs.patch }} + artifact: ${{ steps.patch.outputs.artifact }} + defaults: + run: + working-directory: ${{ inputs.working-directory }} + steps: - name: Checkout uses: actions/checkout@v7 with: @@ -181,8 +186,10 @@ jobs: user_id=$(gh api "/users/${APP_SLUG}%5Bbot%5D" --jq .id) email="${user_id}+${APP_SLUG}[bot]@users.noreply.github.com" git apply --index "$RUNNER_TEMP/regenerated.patch" - # --no-renames: a move out of .github/ must show its old path too. - if git diff --cached --name-only --no-renames -z | grep -qz '^\.github/'; then + # --no-renames: a move out of .github/ must show its old path too. In a variable: + # `| grep -q` can stop git diff early, and pipefail then hides the match. + names=$(git diff --cached --name-only --no-renames -z | tr '\0' '\n') + if printf '%s\n' "$names" | awk 'index($0, ".github/") == 1 {found=1} END {exit !found}'; then echo "::error::The regenerated code changes .github/, it is not pushed." exit 1 fi From 396c857cdfe2ca8b6ba99d486d8c7ac1385882f3 Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:01:44 +0100 Subject: [PATCH 4/9] fix(go-generated): check the branch again before the push job runs 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 --- .github/workflows/go-generated.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index d8b2bb4..7f58d53 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -151,7 +151,13 @@ jobs: push-to-renovate-branch: needs: go-generated # The check above fails on purpose: the pushed commit starts a new run, which passes. - if: ${{ !cancelled() && needs.go-generated.outputs.patch == 'true' }} + # The branch condition again, not only the output of the job that ran the generators: + # they can write to $GITHUB_ENV there. A job-level `if` cannot read env, so it is inlined. + if: >- + ${{ !cancelled() && needs.go-generated.outputs.patch == 'true' + && inputs.push-to-renovate-branches && github.event_name == 'pull_request' + && startsWith(github.head_ref, 'renovate/') + && github.event.pull_request.head.repo.full_name == github.repository }} # Not inputs.runs-on: this job holds a write token, so it gets a fresh GitHub-hosted VM. runs-on: ubuntu-24.04 steps: From 22946a10afee8a8db0a35ee6edd0f2684ea20d25 Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:15:02 +0100 Subject: [PATCH 5/9] fix(go-generated): pass only the App key to the push-mode example 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 --- .github/workflows/tests.yaml | 3 ++- docs/go-generated.md | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b0dcacb..8811e16 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -40,7 +40,8 @@ jobs: uses: ./.github/workflows/go-generated.yaml # Push mode only pushes on a renovate/* branch: here it checks the inputs and the # condition, and stays a plain check. - secrets: inherit + secrets: + ACTIONS_APP_PRIVATE_KEY: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }} with: working-directory: tests/go-generated push-to-renovate-branches: true diff --git a/docs/go-generated.md b/docs/go-generated.md index 6c98202..9448292 100644 --- a/docs/go-generated.md +++ b/docs/go-generated.md @@ -46,12 +46,17 @@ the pushed commit starts a new run that passes. jobs: go-generated: uses: scality/workflows/.github/workflows/go-generated.yaml@v2 - secrets: inherit + secrets: + ACTIONS_APP_PRIVATE_KEY: ${{ secrets.ACTIONS_APP_PRIVATE_KEY }} with: push-to-renovate-branches: true actions-app-id: ${{ vars.ACTIONS_APP_ID }} ``` +Pass the secrets one by one, not with `secrets: inherit`: the commands can read +`GIT_ACCESS_TOKEN`, so only pass it when the repository needs private modules, and only +with a read-only token. + How it stays safe: - The commands run with a read-only token. A second job, which never runs the code of From 0b9febf1fa6ecf8e0716df6227e308bef08d8f51 Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:20:47 +0100 Subject: [PATCH 6/9] docs(go-generated): say that N modules take N runs to push Refs: MK8S-516 --- docs/go-generated.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/go-generated.md b/docs/go-generated.md index 9448292..739c0ee 100644 --- a/docs/go-generated.md +++ b/docs/go-generated.md @@ -67,7 +67,8 @@ How it stays safe: - The pushed commit only holds changes under `working-directory`, never under `.github/`. When the commands change files outside `working-directory`, nothing is pushed. The push job checks this again, since the first job ran the generators. - Several calls, one per module, each push their own commit. + With one call per module, each run pushes one module: the first push moves the branch, + the other calls push nothing, and the next run regenerates the remaining modules. - It does not loop: when files the App already regenerated on the branch still differ, the job fails instead of pushing again. - The push job runs on a fresh GitHub-hosted runner, whatever `runs-on` says: it holds a From 62ed166be6fc2732160f9ab612a78b2dead2457e Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:28:10 +0100 Subject: [PATCH 7/9] fix(go-generated): treat a rejected push on a moved branch as a notice 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/workflows/go-generated.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index 7f58d53..b51ffa4 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -224,9 +224,13 @@ jobs: fi git -c core.hooksPath=/dev/null -c user.name="${APP_SLUG}[bot]" -c user.email="$email" \ commit -q -m "chore(deps): regenerate the code" - if [ "$(git ls-remote origin "refs/heads/${HEAD_REF}" | cut -f1)" != "$HEAD_SHA" ]; then - echo "::notice::${HEAD_REF} moved since this run started, nothing pushed." - exit 0 + # Not forced: when the branch moved (Renovate, or another module's push job), + # the push is rejected and the new commit starts its own run. + if ! git -c core.hooksPath=/dev/null push origin "HEAD:refs/heads/${HEAD_REF}"; then + if [ "$(git ls-remote origin "refs/heads/${HEAD_REF}" | cut -f1)" != "$HEAD_SHA" ]; then + echo "::notice::${HEAD_REF} moved since this run started, nothing pushed." + exit 0 + fi + exit 1 fi - git -c core.hooksPath=/dev/null push origin "HEAD:refs/heads/${HEAD_REF}" echo "Pushed as ${APP_SLUG}[bot] <${email}>. Add this email to gitIgnoredAuthors in the Renovate config." >> "$GITHUB_STEP_SUMMARY" From 464e4b1a2824fd50fc683d3f45c837cb8f07cf3f Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:14:56 +0100 Subject: [PATCH 8/9] ci(go-generated): run on ubuntu-26.04 Refs: MK8S-516 --- .github/workflows/go-generated.yaml | 6 +++--- docs/go-generated.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index b51ffa4..de3b4f1 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -26,7 +26,7 @@ on: runs-on: description: 'Runner label' required: false - default: ubuntu-24.04 + default: ubuntu-26.04 type: string push-to-renovate-branches: description: 'On a renovate/* branch of this repository, push the regenerated code instead of only failing' @@ -62,7 +62,7 @@ jobs: # config early, while PRs that get no Actions secrets (Dependabot, forks) stay green. validate-push-inputs: if: inputs.push-to-renovate-branches - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - name: Validate inputs env: @@ -159,7 +159,7 @@ jobs: && startsWith(github.head_ref, 'renovate/') && github.event.pull_request.head.repo.full_name == github.repository }} # Not inputs.runs-on: this job holds a write token, so it gets a fresh GitHub-hosted VM. - runs-on: ubuntu-24.04 + runs-on: ubuntu-26.04 steps: - uses: actions/create-github-app-token@v3 id: app-token diff --git a/docs/go-generated.md b/docs/go-generated.md index 739c0ee..2323dfa 100644 --- a/docs/go-generated.md +++ b/docs/go-generated.md @@ -102,7 +102,7 @@ updated like any other dependency. | ------------------- | ------------------------------------ | ------------------------------------ | | `commands` | Commands that regenerate the code | `go mod tidy` and `go generate ./...` | | `working-directory` | Directory that holds the `go.mod` | `.` | -| `runs-on` | Runner label | `ubuntu-24.04` | +| `runs-on` | Runner label | `ubuntu-26.04` | | `push-to-renovate-branches` | Push the regenerated code on a `renovate/*` branch | `false` | | `actions-app-id` | GitHub App ID used for that push (usually `vars.ACTIONS_APP_ID`) | `''` | From d5ff9e646a2cf660ded9def431aed693fb94ea91 Mon Sep 17 00:00:00 2001 From: Alex Rodriguez <131964409+ezekiel-alexrod@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:04:48 +0100 Subject: [PATCH 9/9] refactor(go-generated): drop the runs-on input No caller uses it, and every job now runs on ubuntu-26.04. Refs: MK8S-516 --- .github/workflows/go-generated.yaml | 8 +------- docs/go-generated.md | 3 --- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/go-generated.yaml b/.github/workflows/go-generated.yaml index de3b4f1..1fb35bb 100644 --- a/.github/workflows/go-generated.yaml +++ b/.github/workflows/go-generated.yaml @@ -23,11 +23,6 @@ on: required: false default: . type: string - runs-on: - description: 'Runner label' - required: false - default: ubuntu-26.04 - type: string push-to-renovate-branches: description: 'On a renovate/* branch of this repository, push the regenerated code instead of only failing' required: false @@ -76,7 +71,7 @@ jobs: fi go-generated: - runs-on: ${{ inputs.runs-on }} + runs-on: ubuntu-26.04 outputs: patch: ${{ steps.patch.outputs.patch }} artifact: ${{ steps.patch.outputs.artifact }} @@ -158,7 +153,6 @@ jobs: && inputs.push-to-renovate-branches && github.event_name == 'pull_request' && startsWith(github.head_ref, 'renovate/') && github.event.pull_request.head.repo.full_name == github.repository }} - # Not inputs.runs-on: this job holds a write token, so it gets a fresh GitHub-hosted VM. runs-on: ubuntu-26.04 steps: - uses: actions/create-github-app-token@v3 diff --git a/docs/go-generated.md b/docs/go-generated.md index 2323dfa..ecd6cb5 100644 --- a/docs/go-generated.md +++ b/docs/go-generated.md @@ -71,8 +71,6 @@ How it stays safe: the other calls push nothing, and the next run regenerates the remaining modules. - It does not loop: when files the App already regenerated on the branch still differ, the job fails instead of pushing again. -- The push job runs on a fresh GitHub-hosted runner, whatever `runs-on` says: it holds a - write token, and must not share a machine with the job that ran the generators. - It does not force-push. If Renovate moved the branch meanwhile, it pushes nothing: the new commit starts its own run, which regenerates again. @@ -102,7 +100,6 @@ updated like any other dependency. | ------------------- | ------------------------------------ | ------------------------------------ | | `commands` | Commands that regenerate the code | `go mod tidy` and `go generate ./...` | | `working-directory` | Directory that holds the `go.mod` | `.` | -| `runs-on` | Runner label | `ubuntu-26.04` | | `push-to-renovate-branches` | Push the regenerated code on a `renovate/*` branch | `false` | | `actions-app-id` | GitHub App ID used for that push (usually `vars.ACTIONS_APP_ID`) | `''` |