-
Notifications
You must be signed in to change notification settings - Fork 43
chore(SREP-4482, SREP-4486, SREP-4800: Boilerplate Update for Agentic SDLC Rollout) #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
charlesgong
wants to merge
4
commits into
openshift:main
Choose a base branch
from
charlesgong:SREP-4485
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b78a8f
add: pre-commit hooks golden standard (SREP-4485)
charlesgong 27e43a4
fix: use fmt.Fprintf instead of WriteString(fmt.Sprintf) (SREP-4485)
charlesgong 291d36b
update: boilerplate update (SREP-4485)
charlesgong cc66876
chore: boilerplate update with new: true golangci flag (SREP-4485)
charlesgong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| build_root_image: | ||
| name: boilerplate | ||
| namespace: openshift | ||
| tag: image-v8.3.5 | ||
| tag: image-v8.3.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| Run pre-commit hooks on this repository following the agentic SDLC golden rules (SREP-4450). | ||
|
|
||
| ## Usage | ||
| - `/pre-commit` — run on staged files (default, fastest) | ||
| - `/pre-commit --all-files` — run on all files (first-time setup, CI equivalent) | ||
| - `/pre-commit <hook-id>` — run a single hook by ID (targeted debugging) | ||
|
|
||
| ## What you must do | ||
|
|
||
| ### Step 1 — Preflight checks | ||
|
|
||
| 1. Confirm `.pre-commit-config.yaml` exists in the repo root. If not, tell the user and stop. | ||
| 2. Confirm `pre-commit` is installed: run `which pre-commit`. If not found, run `pip install pre-commit` or `pip3 install pre-commit`. | ||
| 3. Confirm hooks are installed: check if `.git/hooks/pre-commit` exists. If not, run `pre-commit install`. | ||
|
|
||
| ### Step 2 — Run hooks | ||
|
|
||
| Determine the run mode from `$ARGUMENTS`: | ||
| - `--all-files` → run `pre-commit run --all-files` | ||
| - `<hook-id>` (a word that is not a flag) → run `pre-commit run <hook-id>` | ||
| - empty or default → run `pre-commit run` (staged files only) | ||
|
|
||
| Capture the full stdout and stderr output. | ||
|
|
||
| ### Step 3 — Parse and categorise results | ||
|
|
||
| For each hook in the output, classify it as one of: | ||
| - **Passed** — hook exited 0, no changes | ||
| - **Auto-fixed** — hook exited non-zero but modified files (trailing-whitespace, end-of-file-fixer) | ||
| - **Failed** — hook exited non-zero, no auto-fix | ||
|
|
||
| Extract for each failure: | ||
| - Hook ID and name | ||
| - Affected files and line numbers if present | ||
| - The error message | ||
| - Whether it is a security hook (gitleaks, rbac-wildcard-check) | ||
|
|
||
| ### Step 4 — Handle auto-fixes (idempotency loop, golden rule 9) | ||
|
|
||
| If any hooks auto-fixed files: | ||
| 1. Stage the modified files: `git add <auto-fixed files>` | ||
| 2. Re-run the hooks on staged files | ||
| 3. Report what was fixed | ||
|
|
||
| ### Step 5 — Retry on failure (golden rule 19, max 2 iterations) | ||
|
|
||
| Track `attempt_count` starting at 1. | ||
|
|
||
| For each non-security failure with an identifiable fix: | ||
| 1. Apply the fix (edit the file, run the suggested command) | ||
| 2. Stage the changes | ||
| 3. Re-run `pre-commit run` | ||
| 4. Increment `attempt_count` | ||
|
|
||
| **Stop retrying when:** | ||
| - All hooks pass → report success | ||
| - `attempt_count` reaches 3 → stop, escalate to human (see Step 6) | ||
| - A security hook fails → stop immediately, escalate to human (see Step 6) | ||
|
|
||
| ### Step 6 — Escalate to human when required | ||
|
|
||
| Escalate (do not retry further) when: | ||
| - A **security hook** fires (gitleaks, rbac-wildcard-check) — these require human judgment | ||
| - Hooks still fail after **2 fix-and-retry attempts** | ||
| - A hook **timed out** — this indicates a systemic issue, not a fixable code problem | ||
|
|
||
| When escalating, report: | ||
| - Which hook is failing | ||
| - The exact error output | ||
| - What was already attempted | ||
| - The recommended next action for the human | ||
|
|
||
| ### Step 7 — Final report | ||
|
|
||
| Always end with a structured summary: | ||
|
|
||
| ``` | ||
| PRE-COMMIT SUMMARY | ||
| ================== | ||
| Passed: <list of hook IDs> | ||
| Auto-fixed: <list of hook IDs> → files staged | ||
| Fixed: <list of hook IDs> → changes applied | ||
| Failed: <list of hook IDs> → escalated to human | ||
| Attempts: <N> of 2 maximum | ||
| ``` | ||
|
|
||
| ## Rules you must never break | ||
|
|
||
| - **Never run `git commit --no-verify`** — bypassing all hooks is not permitted | ||
| - **Never modify `.pre-commit-config.yaml`** to suppress a failing hook | ||
| - **Never retry more than twice** — escalate on the third failure | ||
| - **Never auto-fix a security hook failure** — always escalate to human | ||
| - **Always stage auto-fixed files** before re-running — do not leave unstaged modifications | ||
| - **Always report what changed** — the human must be able to review every fix you applied | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # ============================================================================= | ||
| # Tier 1 — Common Pre-Commit Hooks for OSD Operators | ||
| # SREP-4485 | Golden rules: SREP-4450 | ||
| # ============================================================================= | ||
| # | ||
| # INSTALL | ||
| # pip install pre-commit | ||
| # pre-commit install | ||
| # | ||
| # USAGE | ||
| # pre-commit run # staged files only (developer / agent workflow) | ||
| # pre-commit run --all-files # full repo (CI / first-time setup) | ||
| # | ||
| # BYPASS (golden rule 16) | ||
| # Skip one hook: SKIP=hook-id git commit | ||
| # Never use: git commit --no-verify | ||
| # Agents: never bypass any hook | ||
| # Security hooks: never bypassable under any circumstances | ||
| # | ||
| # CI RELATIONSHIP (golden rule 17) | ||
| # These hooks mirror ci/prow/lint. CI remains the authoritative gate. | ||
| # Every check here also runs in CI. Pre-commit is developer convenience. | ||
| # | ||
| # AGENT USAGE (golden rule 1, 7, 19) | ||
| # Agents run: pre-commit run | ||
| # Output: PRE_COMMIT=1 is set automatically — hooks emit structured output | ||
| # Retry: max 2 fix-and-retry iterations before escalating to human | ||
| # | ||
| # TIMING TARGETS (golden rule 2, 3) | ||
| # Total run: <= 10s target / <= 60s hard limit on a 10-file changeset | ||
| # Hooks run fastest-first (golden rule 13). Each hook has a timeout guard. | ||
| # | ||
| # FIRST RUN NOTE | ||
| # Auto-fix hooks (trailing-whitespace, end-of-file-fixer) will correct | ||
| # pre-existing violations on the first run. Stage and commit those fixes | ||
| # separately before day-to-day use. | ||
| # | ||
| # ============================================================================= | ||
|
|
||
| repos: | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 1. FILE HYGIENE + YAML SYNTAX | target < 2s | auto-fix + error | ||
| # - check-merge-conflict: detects unresolved merge markers | ||
| # - trailing-whitespace: removes trailing spaces (auto-fix) | ||
| # - end-of-file-fixer: ensures single EOF newline (auto-fix) | ||
| # - check-yaml: validates YAML syntax in deploy/ manifests; | ||
| # mirrors ci/prow/lint: olm-deploy-yaml-validate | ||
| # --------------------------------------------------------------------------- | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 # pinned immutable tag | ||
| hooks: | ||
| - id: check-merge-conflict | ||
| - id: trailing-whitespace | ||
| args: [--markdown-linebreak-ext=md] | ||
| - id: end-of-file-fixer | ||
| - id: check-yaml | ||
| name: YAML syntax (deploy/) | ||
| files: ^deploy/.*\.ya?ml$ | ||
| args: [--allow-multiple-documents] | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 2. SECRETS DETECTION | target < 5s | always blocking | ||
| # Scans all file types (YAML, shell, config) — gosec covers Go only. | ||
| # High-confidence findings block; configure .gitleaks.toml for allowlist. | ||
| # --------------------------------------------------------------------------- | ||
| - repo: https://github.com/gitleaks/gitleaks | ||
| rev: v8.18.0 # pinned immutable tag (golden rule 15) | ||
| hooks: | ||
| - id: gitleaks | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 3. STATIC ANALYSIS | target < 15s cached | error | ||
| # Mirrors ci/prow/lint: go-check exactly (same version + config as CI). | ||
| # Linter config: boilerplate/openshift/golang-osd-operator/golangci.yml | ||
| # --------------------------------------------------------------------------- | ||
| - repo: https://github.com/golangci/golangci-lint | ||
| rev: v2.0.2 # pinned immutable tag — must match CI (golden rule 15) | ||
| hooks: | ||
| - id: golangci-lint | ||
| args: | ||
| - --config=boilerplate/openshift/golang-osd-operator/golangci.yml | ||
| - --timeout=120s # graceful timeout (golden rule 3) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Local hooks — compile, dependency, security | ||
| # | ||
| # TIMEOUT NOTE (golden rule 3) | ||
| # Uses portable timeout detection: 'timeout' on Linux, 'gtimeout' on macOS. | ||
| # macOS: brew install coreutils | ||
| # Linux: timeout is available by default (GNU coreutils) | ||
| # --------------------------------------------------------------------------- | ||
| - repo: local | ||
| hooks: | ||
|
|
||
| # ----------------------------------------------------------------------- | ||
| # 4. COMPILE CHECK | target < 10s cached | error | ||
| # Catches import cycles and type errors before golangci-lint runs. | ||
| # Note: go build ./... writes no binary to the repo (compile check only). | ||
| # Fix: resolve compilation errors reported by go build. | ||
| # ----------------------------------------------------------------------- | ||
| - id: go-build | ||
| name: go build | ||
| language: system | ||
| entry: bash -c 'T=$(command -v timeout || command -v gtimeout || echo); ${T:+$T 30s} go build ./...' | ||
| types: [go] | ||
| pass_filenames: false | ||
|
|
||
| # ----------------------------------------------------------------------- | ||
| # 5. DEPENDENCY DRIFT | target < 10s | error | ||
| # Detects uncommitted go.mod/go.sum changes after go mod tidy. | ||
| # Fix: run 'go mod tidy' and stage go.mod and go.sum. | ||
| # ----------------------------------------------------------------------- | ||
| - id: go-mod-tidy | ||
| name: go mod tidy | ||
| language: system | ||
| entry: bash -c 'T=$(command -v timeout || command -v gtimeout || echo); ${T:+$T 60s} go mod tidy && git diff --exit-code go.mod go.sum' | ||
| files: '(\.go$|go\.(mod|sum)$)' | ||
| exclude: '^vendor/' | ||
| pass_filenames: false | ||
|
|
||
| # ----------------------------------------------------------------------- | ||
| # 6. RBAC WILDCARD CHECK | target < 5s | warn-only (blocking after cleanup) | ||
| # Rejects wildcard RBAC in deploy/ manifests (verbs/resources: ["*"] | ||
| # or multi-line - '*' format). Logic lives in standard.mk target | ||
| # 'rbac-wildcard-check' for readability and reuse. | ||
| # Fix: replace wildcards with explicit verbs and resource names. | ||
| # ----------------------------------------------------------------------- | ||
| - id: rbac-wildcard-check | ||
| name: RBAC wildcard permissions | ||
| language: system | ||
| entry: bash -c 'make rbac-wildcard-check' | ||
| files: ^deploy/.*\.ya?ml$ | ||
| pass_filenames: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| image-v8.3.5 | ||
| image-v8.3.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 294b1978042a939fb940bc8ae89e498991a7ca43 | ||
| b6e7575196e8c17274c85d2c22178ad51290c237 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a language hint to the fenced summary block (markdownlint MD040).
Line 77 uses a fenced code block without a language, which triggers lint and can fail docs checks.
Suggested patch
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.claude/commands/pre-commit.md around lines 77 - 85, The fenced code block
showing the "PRE-COMMIT SUMMARY" in .claude/commands/pre-commit.md lacks a
language hint which triggers markdownlint MD040; update the opening fence for
that block (the block containing the "PRE-COMMIT SUMMARY" header and list) to
include a language hint (e.g., change the opening
totext) so the fencedsummary block is annotated and the lint rule is satisfied.