Skip to content

[release-1.9] ci: auto-update bundle manifests on same-repo PRs - #3227

Merged
rm3l merged 1 commit into
redhat-developer:release-1.9from
rm3l:cherry-pick/release-1.9/ci/auto-update-bundle-manifests-on-pr
Jul 20, 2026
Merged

[release-1.9] ci: auto-update bundle manifests on same-repo PRs#3227
rm3l merged 1 commit into
redhat-developer:release-1.9from
rm3l:cherry-pick/release-1.9/ci/auto-update-bundle-manifests-on-pr

Conversation

@rm3l

@rm3l rm3l commented Jul 20, 2026

Copy link
Copy Markdown
Member

Manual cherry-pick of #3169

@sonarqubecloud

Copy link
Copy Markdown

@rhdh-qodo-merge

Copy link
Copy Markdown

PR Summary by Qodo

CI: auto-update bundle manifests on same-repo PRs

⚙️ Configuration changes ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Regenerate bundle manifests in PR checks and detect meaningful diffs (ignoring createdAt).
• Auto-commit/push regenerated manifests back to same-repo PR branches when out of sync.
• Fail the job only when manifests changed and auto-push did not succeed.
Diagram

graph TD
A["PR event"] --> B["Checkout PR branch"] --> C["Setup Go"] --> D["Regenerate bundles"] --> E{"Bundle changed?"}
E -- "no" --> F["Pass: up to date"]
E -- "yes" --> G{"Same-repo PR?"}
G -- "no" --> K["Fail: out of sync"]
G -- "yes" --> H["Auto-commit + push"] --> I{"Push succeeded?"}
I -- "yes" --> J["Pass: updated"]
I -- "no" --> K
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep checks read-only (no auto-push)
  • ➕ No need for write permissions or bot token
  • ➕ Simpler security posture; avoids modifying contributor branches
  • ➖ Creates more manual work and PR churn for maintainers/contributors
  • ➖ Repeated CI failures until developers regenerate and commit locally
2. Use pull_request_target for write access
  • ➕ Can push fixes even for forked PRs (if desired)
  • ➕ Simplifies permissions management in some setups
  • ➖ Higher security risk (runs in base repo context); requires strict hardening
  • ➖ Generally discouraged unless carefully sandboxed
3. Open an automated follow-up PR (bot branch) instead of pushing to PR
  • ➕ Avoids writing to contributor branches directly
  • ➕ Still provides automated regeneration with clear audit trail
  • ➖ Adds extra PRs and coordination overhead
  • ➖ More complexity in automation and branch management

Recommendation: The current approach is a good balance: it only auto-pushes on same-repo PRs (reducing fork-related risk), uses best-effort push with a clear fallback failure, and keeps the existing diff check semantics (ignoring createdAt-only churn). The main consideration is ensuring the bot token scope is minimal and rotating/monitoring it appropriately.

Files changed (1) +42 / -6

Other (1) +42 / -6
pr-bundle-diff-checks.yamlAuto-regenerate and optionally push bundle manifest updates on PRs +42/-6

Auto-regenerate and optionally push bundle manifest updates on PRs

• Updates the bundle validation workflow to regenerate bundles, detect meaningful diffs (ignoring createdAt-only changes), and record change status via step outputs. For same-repo PRs, it best-effort commits and pushes regenerated bundle/config/dist artifacts using a bot token; otherwise it fails with a clear error when out of sync.

.github/workflows/pr-bundle-diff-checks.yaml

@rm3l
rm3l merged commit 50989a6 into redhat-developer:release-1.9 Jul 20, 2026
5 checks passed
@rm3l
rm3l deleted the cherry-pick/release-1.9/ci/auto-update-bundle-manifests-on-pr branch July 20, 2026 16:22
@rhdh-qodo-merge

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. check step lacks strict mode 📘 Rule violation ☼ Reliability
Description
The workflow run scripts do not enable strict mode (e.g., set -euo pipefail) and do not validate
required runtime env vars (like GITHUB_OUTPUT), reducing robustness and making failures easier to
miss in CI. This violates the shell hardening compliance requirements for script blocks executed in
the workflow, including critical git operations.
Code

.github/workflows/pr-bundle-diff-checks.yaml[R41-51]

+        run: |
          # Since operator-sdk 1.26.0, `make bundle` changes the `createdAt` field from the bundle every time we run it.
          # The `git diff` below checks if only the createdAt field has changed. If it is the only change, it is ignored.
          # Inspired from https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333
          if git diff --quiet -I'^    createdAt: ' bundle config dist; then
            echo "✅ Bundle manifests are up to date"
+            echo "changed=false" >> "$GITHUB_OUTPUT"
+          else
+            echo "Bundle manifests are out of sync"
+            echo "changed=true" >> "$GITHUB_OUTPUT"
+          fi
Relevance

⭐⭐ Medium

Some workflow “script hardening” feedback was discussed/partly adopted, but no clear precedent
enforcing set -euo pipefail.

PR-#2293

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 5 requires hardened shell scripting, including enabling strict mode and validating
required environment variables. In .github/workflows/pr-bundle-diff-checks.yaml, the `Check for
changes step uses a multi-line shell script that writes to GITHUB_OUTPUT` without first setting
strict mode or confirming GITHUB_OUTPUT is present, and the `Auto-commit and push updated bundle
manifests (autopush) run block performs critical git operations (e.g., git config, git add`,
git commit, git push) without enabling strict mode at the start of the script, which can mask
partial failures and lead to inconsistent behavior.

.github/workflows/pr-bundle-diff-checks.yaml[41-51]
.github/workflows/pr-bundle-diff-checks.yaml[61-76]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The workflow contains multi-line `run` scripts that do not explicitly enable strict mode (`set -euo pipefail`) and, where applicable, do not validate required runtime environment variables (e.g., `GITHUB_OUTPUT`) before use. This can allow silent/partial failures (including during critical git operations) and violates the shell hardening compliance requirements for CI scripts.

## Issue Context
PR Compliance ID 5 requires hardened shell scripting practices in CI, including strict mode and validating required env vars to ensure predictable failure handling and to prevent brittle behavior (ShellCheck-aligned practices). The affected steps include `Check for changes` (writes to `GITHUB_OUTPUT`) and `Auto-commit and push updated bundle manifests` (runs multiple `git` commands).

## Fix Focus Areas
- .github/workflows/pr-bundle-diff-checks.yaml[41-51]
- .github/workflows/pr-bundle-diff-checks.yaml[61-76]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Untracked outputs not detected 🐞 Bug ≡ Correctness
Description
The workflow decides whether manifests changed using only git diff, which ignores untracked files,
so newly generated files under bundle/, config/, or dist/ can be missed and the workflow will
incorrectly set changed=false. This can let out-of-sync generated outputs pass without failing and
without triggering the auto-commit/push.
Code

.github/workflows/pr-bundle-diff-checks.yaml[R45-51]

          if git diff --quiet -I'^    createdAt: ' bundle config dist; then
            echo "✅ Bundle manifests are up to date"
+            echo "changed=false" >> "$GITHUB_OUTPUT"
+          else
+            echo "Bundle manifests are out of sync"
+            echo "changed=true" >> "$GITHUB_OUTPUT"
+          fi
Relevance

⭐⭐ Medium

No historical evidence found about reviewers flagging git-diff checks missing untracked-file
detection in workflows.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The workflow’s change check relies solely on git diff over bundle/config/dist, but the build
targets can create new files such as dist/$(PROFILE)/install.yaml for each profile discovered from
config/manifests/*, which can be untracked when new profiles/files are introduced.

.github/workflows/pr-bundle-diff-checks.yaml[39-51]
Makefile[1-1]
Makefile[269-280]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The change detection step uses `git diff` only. `git diff` does not report newly created untracked files, so the workflow can incorrectly conclude there were no changes and skip both the auto-push attempt and the failure gate.

## Issue Context
`make bundles build-installers` can create new output files (e.g., `dist/<profile>/install.yaml`). Profiles are derived from directories under `config/manifests`, so a PR adding a new profile directory can generate new files that are untracked until added.

## Fix Focus Areas
- .github/workflows/pr-bundle-diff-checks.yaml[39-51]
- Makefile[1-1]
- Makefile[269-280]

## Proposed fix
Update the "Check for changes" step to consider both:
1) tracked diffs (ignoring createdAt), AND
2) untracked files under `bundle`, `config`, and `dist`.

Example approach (bash):
- Keep the existing `git diff --quiet -I'^    createdAt: '` check.
- Add an untracked check such as:
 - `UNTRACKED=$(git ls-files --others --exclude-standard bundle config dist)`
 - Treat `changed=true` if `UNTRACKED` is non-empty.
This preserves the createdAt ignore logic while preventing false "no changes" when new generated files appear.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Overprivileged PR workflow token 🐞 Bug ⛨ Security
Description
The pull_request job grants contents: write while executing PR-controlled code (`make bundles
build-installers), enabling same-repo PR code to use the automatically-provided GITHUB_TOKEN` to
write to the repo beyond the intended bot push. This is an unnecessary expansion of privileges
because the actual push is done via secrets.RHDH_BOT_TOKEN, not the workflow token.
Code

.github/workflows/pr-bundle-diff-checks.yaml[R19-20]

+    permissions:
+      contents: write
Relevance

⭐ Low

Least-privilege/permissions tightening for workflows was previously rejected (kept `permissions:
contents: write`).

PR-#2141

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The workflow is triggered on pull_request, checks out the PR head, and runs make ... from that
PR branch; granting contents: write at the job level exposes a write-capable GITHUB_TOKEN during
execution of PR-controlled code.

.github/workflows/pr-bundle-diff-checks.yaml[3-9]
.github/workflows/pr-bundle-diff-checks.yaml[14-21]
.github/workflows/pr-bundle-diff-checks.yaml[23-38]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This workflow runs on `pull_request` and executes PR-controlled build logic, but the job grants `contents: write` to the default `GITHUB_TOKEN`. That token is available to all `run:` steps, so any code executed from the PR branch can potentially use it to perform repository write operations.

## Issue Context
The workflow already uses a separate secret (`RHDH_BOT_TOKEN`) to push regenerated manifests; therefore `contents: write` is not needed for the validation/regeneration steps.

## Fix Focus Areas
- .github/workflows/pr-bundle-diff-checks.yaml[14-21]

## Proposed fix
- Change the job permissions to least-privilege (typically `contents: read`), or remove the explicit `permissions:` block to rely on the repository default (ensuring it is read-only for PR workflows).
- Keep using `RHDH_BOT_TOKEN` for the auto-push step (no need for `GITHUB_TOKEN` write permissions).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ  2 issues published inline · 3 in summary

Qodo Logo

Comment on lines +41 to +51
run: |
# Since operator-sdk 1.26.0, `make bundle` changes the `createdAt` field from the bundle every time we run it.
# The `git diff` below checks if only the createdAt field has changed. If it is the only change, it is ignored.
# Inspired from https://github.com/operator-framework/operator-sdk/issues/6285#issuecomment-1415350333
if git diff --quiet -I'^ createdAt: ' bundle config dist; then
echo "✅ Bundle manifests are up to date"
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "Bundle manifests are out of sync"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. check step lacks strict mode 📘 Rule violation ☼ Reliability

The workflow run scripts do not enable strict mode (e.g., set -euo pipefail) and do not validate
required runtime env vars (like GITHUB_OUTPUT), reducing robustness and making failures easier to
miss in CI. This violates the shell hardening compliance requirements for script blocks executed in
the workflow, including critical git operations.
Agent Prompt
## Issue description
The workflow contains multi-line `run` scripts that do not explicitly enable strict mode (`set -euo pipefail`) and, where applicable, do not validate required runtime environment variables (e.g., `GITHUB_OUTPUT`) before use. This can allow silent/partial failures (including during critical git operations) and violates the shell hardening compliance requirements for CI scripts.

## Issue Context
PR Compliance ID 5 requires hardened shell scripting practices in CI, including strict mode and validating required env vars to ensure predictable failure handling and to prevent brittle behavior (ShellCheck-aligned practices). The affected steps include `Check for changes` (writes to `GITHUB_OUTPUT`) and `Auto-commit and push updated bundle manifests` (runs multiple `git` commands).

## Fix Focus Areas
- .github/workflows/pr-bundle-diff-checks.yaml[41-51]
- .github/workflows/pr-bundle-diff-checks.yaml[61-76]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines 45 to +51
if git diff --quiet -I'^ createdAt: ' bundle config dist; then
echo "✅ Bundle manifests are up to date"
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "Bundle manifests are out of sync"
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Untracked outputs not detected 🐞 Bug ≡ Correctness

The workflow decides whether manifests changed using only git diff, which ignores untracked files,
so newly generated files under bundle/, config/, or dist/ can be missed and the workflow will
incorrectly set changed=false. This can let out-of-sync generated outputs pass without failing and
without triggering the auto-commit/push.
Agent Prompt
## Issue description
The change detection step uses `git diff` only. `git diff` does not report newly created untracked files, so the workflow can incorrectly conclude there were no changes and skip both the auto-push attempt and the failure gate.

## Issue Context
`make bundles build-installers` can create new output files (e.g., `dist/<profile>/install.yaml`). Profiles are derived from directories under `config/manifests`, so a PR adding a new profile directory can generate new files that are untracked until added.

## Fix Focus Areas
- .github/workflows/pr-bundle-diff-checks.yaml[39-51]
- Makefile[1-1]
- Makefile[269-280]

## Proposed fix
Update the "Check for changes" step to consider both:
1) tracked diffs (ignoring createdAt), AND
2) untracked files under `bundle`, `config`, and `dist`.

Example approach (bash):
- Keep the existing `git diff --quiet -I'^    createdAt: '` check.
- Add an untracked check such as:
  - `UNTRACKED=$(git ls-files --others --exclude-standard bundle config dist)`
  - Treat `changed=true` if `UNTRACKED` is non-empty.
This preserves the createdAt ignore logic while preventing false "no changes" when new generated files appear.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@rhdh-qodo-merge rhdh-qodo-merge Bot added the enhancement New feature or request label Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant