Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions scripts/go-upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ krm-functions-sdk (leaf — no upstream deps)
| `--repo=NAME` | Scope to a single repository |
| `--continue` | Don't fail-fast; accumulate errors and report at end |
| `--push` | After successful operations, create branch, commit, push, and raise draft PR |
| `--force`, `-f` | Override upstream push protection (allows push to `kptdev`) |
| `--for=CMD` | With `push` subcommand: specify which upgrade was done (default: `all`) |

## Configuration
Expand All @@ -68,12 +69,18 @@ Edit `config.env` to change target versions, repositories, or exclusions.

The `FORK_OWNER` variable controls which GitHub org/user to clone from. All repo URLs are derived from it. Defaults to `Nordix` (shared development forks). PRs always target upstream `kptdev/*` regardless of fork owner.

If `FORK_OWNER` is set to `kptdev`, the script will refuse to push branches to prevent accidental upstream modifications. The check also inspects the actual `origin` remote URL of the cloned workspace, so it catches stale workspaces previously cloned from upstream even if `FORK_OWNER` has since changed. Use `--force` to override this protection.

```bash
# Use your personal fork
FORK_OWNER=myuser ./upgrade.sh go-version

# Default: uses Nordix forks
./upgrade.sh go-version

# Push to kptdev (blocked by default)
FORK_OWNER=kptdev ./upgrade.sh all --push # ← blocked
FORK_OWNER=kptdev ./upgrade.sh all --push --force # ← allowed
```

### Target Versions
Expand Down
15 changes: 11 additions & 4 deletions scripts/go-upgrade/lib/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ Automated via go-upgrade script (AI-assisted development)."

log " committed: ${branch_name}"

# Push
# Push — protect against accidental pushes to upstream
local origin_url origin_owner
origin_url=$(cd "$dir" && (git remote get-url --push origin 2>/dev/null || git remote get-url origin))
origin_owner=$(echo "$origin_url" | sed -E 's|.*[:/]([^/]+)/[^/]+(\.git)?$|\1|')
if [[ ("$FORK_OWNER" == "kptdev" || "$origin_owner" == "kptdev") && "${FORCE:-false}" != true ]]; then
err " ${name}: refusing to push to upstream org 'kptdev' (FORK_OWNER=${FORK_OWNER}, origin owner=${origin_owner}). Use --force to override."
record_failure "push blocked: ${name} (upstream protection)"
continue
fi

if ! (cd "$dir" && git push -u origin "$branch_name" 2>&1); then
record_failure "push: ${name}"
continue
Expand All @@ -152,8 +161,7 @@ Automated via go-upgrade script (AI-assisted development)."
fi

# Determine head ref and repository IDs for cross-fork PR
local origin_repo
origin_repo=$(cd "$dir" && git remote get-url origin | sed -E 's|.*[:/]([^/]+/[^/]+)\.git$|\1|')
local origin_repo="${origin_owner}/$(echo "$origin_url" | sed -E 's|.*[:/][^/]+/||; s|\.git$||')"

log " PR: ${origin_repo}:${branch_name} → ${target}:${base_branch}"
log " commits ahead: $(cd "$dir" && git log --oneline "origin/${base_branch}..HEAD" | wc -l)"
Expand All @@ -164,7 +172,6 @@ Automated via go-upgrade script (AI-assisted development)."
# Use GraphQL mutation with headRepositoryId for reliable cross-fork PRs
local target_owner="${target%%/*}"
local target_name="${target##*/}"
local origin_owner="${origin_repo%%/*}"
local origin_name="${origin_repo##*/}"

local target_repo_id origin_repo_id
Expand Down
5 changes: 5 additions & 0 deletions scripts/go-upgrade/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ source "${SCRIPT_DIR}/lib/push.sh"
# --- Options ---
FAIL_FAST=true
GIT_PUSH=false
FORCE=false
FILTER_REPO=""
SUBCOMMAND=""
PUSH_FOR=""
Expand All @@ -62,6 +63,7 @@ Options:
--repo=NAME Run only against the specified repository
--continue Don't fail-fast; accumulate errors and report at end
--push After operations, create branch, commit, push, and raise PR
--force, -f Override upstream push protection (allows push to kptdev)
--for=CMD With 'push' subcommand: specify which upgrade was done
(go-version, lint-version, cross-deps, generate-docs, all). Default: all

Expand Down Expand Up @@ -90,6 +92,8 @@ parse_args() {
FAIL_FAST=false ;;
--push)
GIT_PUSH=true ;;
--force|-f)
FORCE=true ;;
--for=*)
PUSH_FOR="${arg#--for=}" ;;
--repo=*)
Expand Down Expand Up @@ -143,6 +147,7 @@ main() {
log "Target golangci-lint: ${TARGET_GOLANGCI_LINT_VERSION}"
log "Fork owner: ${FORK_OWNER}"
if [[ "$GIT_PUSH" == true ]]; then log "Mode: push enabled"; fi
if [[ "$FORCE" == true ]]; then log "Mode: force (upstream push protection overridden)"; fi
if [[ -n "$FILTER_REPO" ]]; then log "Repo filter: ${FILTER_REPO}"; fi
echo ""

Expand Down