From 88dee0eda126abde285663f3dab7ffd53c50c633 Mon Sep 17 00:00:00 2001 From: Jakub Hadvig Date: Thu, 30 Oct 2025 15:02:18 +0100 Subject: [PATCH] NO-JIRA: Add /vendor Claude code command --- .claude/commands/vendor.md | 126 +++++++++++++++++++++++++++++++++++++ Makefile | 3 + 2 files changed, 129 insertions(+) create mode 100644 .claude/commands/vendor.md diff --git a/.claude/commands/vendor.md b/.claude/commands/vendor.md new file mode 100644 index 000000000..27c9953ab --- /dev/null +++ b/.claude/commands/vendor.md @@ -0,0 +1,126 @@ +--- +description: Vendor openshift/api at a specific commit SHA +--- + +You are helping vendor the openshift/api repository at a specific commit SHA. + +# Usage + +The user can invoke this command with a commit SHA and optional JIRA ticket: +- `/vendor ` - Vendor openshift/api at the specified commit SHA + - JIRA ID will be auto-detected from branch name if it matches `CONSOLE-` or `OCPBUGS-` pattern +- `/vendor ` - Vendor with explicit JIRA ticket for commit messages (e.g., `/vendor abc123 CONSOLE-1234` or `/vendor abc123 OCPBUGS-5678`) + - Explicit JIRA ID overrides branch name detection +- `/vendor` - If no SHA provided, ask the user for it + +# Task + +Follow these steps to vendor openshift/api at the specified commit: + +## 1. Parse Arguments and Detect JIRA ID +- Extract the SHA from the first argument after /vendor +- Extract optional JIRA ticket ID from second argument (e.g., "CONSOLE-1234" or "OCPBUGS-5678") +- If no SHA is provided, ask: "Please provide the commit SHA from openshift/api to vendor (e.g., `/vendor abc123` or `/vendor abc123 CONSOLE-1234`)" +- The SHA can be either full (40 characters) or short (7+ characters) + +**Auto-detect JIRA ID from branch name:** +- Run: `git branch --show-current` to get the current branch name +- Check if branch name matches pattern `CONSOLE-` or `OCPBUGS-` (case-insensitive) +- If it matches and no JIRA ID was provided as argument, extract and use it + - Examples: + - Branch `CONSOLE-1234-feature` → JIRA ID `CONSOLE-1234` + - Branch `ocpbugs-5678-fix-bug` → JIRA ID `OCPBUGS-5678` +- If JIRA ID was provided as argument, it takes precedence over branch name +- Display which JIRA ID will be used (or "none" if not applicable) + +## 2. Check Git Status +- Run: `git status --porcelain` to check for uncommitted changes +- If there are uncommitted changes in files other than `.claude/commands/vendor.md`, warn the user and ask if they want to proceed + +## 3. Show Current Version +- Run: `grep 'github.com/openshift/api' go.mod` to show the current version +- Display it to the user so they know what will change + +## 4. Update Dependency +- Run: `go get github.com/openshift/api@` +- If this fails (invalid SHA or network error): + - Display the error message + - Ask the user to verify the SHA is valid at https://github.com/openshift/api/commits + +## 5. Update Modules and Vendor +- Run: `go mod tidy && go mod vendor` +- This tidies go.mod and updates the vendor directory +- Note: Removed `go clean -modcache` as it's unnecessarily aggressive (clears cache system-wide) + +## 6. Verify Changes +- Run: `go mod verify` +- If verification fails: + - Display the error + - Suggest running `go clean -modcache && go mod download` to re-download modules + - Ask user how to proceed + +## 7. Run Tests +- Run: `make test-unit` to verify the vendored code didn't break existing functionality +- If tests fail: + - Analyze the error output carefully + - Identify which Go package the test belongs to (e.g., `github.com/openshift/console-operator/pkg/console`) + - Fix errors by editing the relevant source files + - Re-run only the failing tests: `TESTABLE= make test-unit` + - Example: `TESTABLE=./pkg/console make test-unit` + - Continue until all tests pass (maximum 3 fix attempts) + - If tests still fail after 3 attempts, report the failures and ask how to proceed + - Once fixed, create a brief summary of the fix nature for the commit message (store in `FIX` variable) + +## 8. Commit Changes +Create one or two commits depending on whether code fixes were needed: + +**Commit 1 - Dependency bump (always created):** +- Files: `go.mod`, `go.sum`, and `vendor/` directory +- Format: `: Bump openshift/api to ` (if JIRA provided) +- Format: `Bump openshift/api to ` (if no JIRA) +- Use first 7-8 characters of SHA for SHORT-SHA + +**Commit 2 - Code fixes (only if fixes were needed):** +- Files: All other modified files +- Format: `: ` (if JIRA provided) +- Format: `` (if no JIRA) +- Example FIX: "Update API types and fix test assertions" + +Commands: +```bash +# Add and commit vendor changes +git add go.mod go.sum vendor/ +git commit -m "" + +# If fixes exist, commit them separately +git add . +git commit -m "" +``` + +## 9. Show Summary +- Run: `grep 'github.com/openshift/api' go.mod` to show the new version +- Display what changed: old version → new version +- List commits created: `git log --oneline -2` +- Confirm successful vendoring + +# Important Notes + +- The console-operator depends on openshift/api for OpenShift resource types +- Vendoring stores all dependencies in the vendor/ directory for reproducible builds +- The SHA must be a valid commit from https://github.com/openshift/api +- JIRA IDs are auto-detected from branch names matching `CONSOLE-` or `OCPBUGS-` patterns +- The two-commit approach separates mechanical changes (vendor bump) from logical changes (code fixes) +- If something goes wrong, you can rollback with: `git reset --hard HEAD~1` (or `HEAD~2` if both commits were made) + +# Error Recovery + +If the vendoring process fails at any step: +1. Identify the failing step and error message +2. For go.mod issues: Consider running `go mod tidy` again +3. For test failures: Analyze and fix up to 3 times, then ask user +4. For git issues: Check if files are in the correct state +5. User can always rollback: `git checkout go.mod go.sum && rm -rf vendor/ && go mod vendor` + +# Output Format + +Provide clear, step-by-step updates so the user knows what's happening at each stage. Use the TodoWrite tool to track progress through the steps. diff --git a/Makefile b/Makefile index f9d9b08d7..3621dbd9d 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,9 @@ test-e2e: install-go-junit-report ./test-e2e.sh .PHONY: test-e2e +build: + go build -ldflags "-X $GO_PACKAGE/pkg/version.versionFromGit=$(git describe --long --tags --abbrev=7 --match 'v[0-9]*')" -tags="ocp" -o console ./cmd/console + # Automatically install go-junit-report if not found GO_JUNIT_REPORT := $(shell command -v go-junit-report 2> /dev/null) install-go-junit-report: