[CI] Add /sync-changelog comment trigger to retry failed changelog sync PRs - #20578
Draft
mrodm wants to merge 44 commits into
Draft
[CI] Add /sync-changelog comment trigger to retry failed changelog sync PRs#20578mrodm wants to merge 44 commits into
mrodm wants to merge 44 commits into
Conversation
Replaces all mage backport targets with a self-contained Go sub-module at cmd/backport/ that builds a `backport` binary. The sub-module has its own go.mod and cmd/backport/.go-version (pinned to main's Go version) so the tool always compiles with a modern toolchain even on backport branches that carry an older root .go-version (e.g. 1.19/1.20). Key changes: - cmd/backport/main.go: CLI binary with subcommands validate-inventory, check-active, validate-branch-name, check-owners, detect-packages, render/parse/update-checklist, sync-changelog, post-comment, apply, check-changelog-versions, add-entry - cmd/backport/go.mod: standalone sub-module; mage pinned via `tool` directive (Go 1.24+); no replace directive — fully self-contained - Library packages moved from dev/backports/ into the sub-module; dev/citools, dev/codeowners, dev/gitutil copied (originals kept for root module use); dead code pruned from the copies - Binary output: build/backport (gitignored, matching elastic-package convention); BACKPORT_BIN exported in common.sh - with_backport() builds in a subshell so the Go version switch does not leak into the caller (fixes go mod tidy in backport_branch.sh) - All Buildkite scripts and GitHub Actions workflows updated; new check-backport-tool Buildkite step runs cmd/backport tests using cmd/backport/.go-version Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- non_package_patterns.txt: replace ^dev/backports/ (deleted) with ^cmd/backport/; add check_backport_tool.sh; sort entries alphabetically - pull-requests.json: add check_backport_tool.sh to skip_ci_on_only_changed; cmd/backport/ is intentionally not skipped so tool changes run full CI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- dev/gitutil: remove Git.RunToStderr (no callers in root module; cmd/backport/gitutil keeps its own copy used by apply and sync) - dev/citools: make parsePackageManifest private (only called internally by ReadPackageManifest in the same file) - dev/codeowners: remove ParseOwners (no callers outside tests; cmd/backport/codeowners keeps its own copy used by compare.go) - dev/codeowners test: drop TestParseOwners; replace remaining ParseOwners calls with a mustParseOwners helper that calls scanGithubOwners directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move ReportFailedTests and RequiresUpdate (the two mage targets that import go-gh/v2 via dev/testsreporter and dev/requiresupdate) into a new magefile_main_only.go. These targets are only invoked from main-branch pipelines; backport branches never call them. Update backport_branch.sh to exclude this file and the two dev packages when creating a backport branch, so go mod tidy drops go-gh/v2. This allows backport branches to retain their original Go version — .go-version is no longer copied from main. go mod tidy now runs in a subshell that installs Go from the backport branch's own .go-version via gvm; main's Go version is restored in the parent shell afterwards. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds Format (go-licenser + goimports) and Check (Build → Format → Tidy → Test) targets to the cmd/backport magefile, matching the root magefile pattern. Tool deps pinned via tools.go (//go:build tools) consistent with the root module. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Change the build output path from $GITHUB_WORKSPACE/backport to $GITHUB_WORKSPACE/build/backport in all four backport workflows and process-checked-branches.sh, consistent with the Buildkite BACKPORT_BIN path and the magefile Build target. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The run: value started with a double-quoted string, causing YAML to treat it as a quoted scalar and leave the subcommand as invalid trailing content. Convert to a block scalar (run: |) to match the surrounding steps. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Go's flag package stops parsing at the first non-flag argument, so --json must come before the positional SHA arguments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…onflicts When a commit on main touches multiple packages, cherry-picking it onto a backport branch that doesn't have all the same packages previously reported a spurious conflict instead of succeeding. Add resetNonPackageChanges() which iterates git status --porcelain after the cherry-pick and resets each file outside the target package dir to HEAD: - git checkout HEAD -- file (handles clean staged changes and UU conflicts) - git rm --force -- file fallback (handles DU modify/delete conflicts where HEAD has the file deleted, e.g. packages absent from the backport branch) A note is printed to stderr when files outside the package are reset. Add three integration tests covering all three cases: - modify/delete conflict (file absent from backport branch) - regular UU conflict (file exists on both branches, different edits) - clean apply to other package (file exists, no conflict, still discarded) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace `go test` with `mage check` so the CI step exercises Build, Format, Tidy, and Test together. Add check_git_diff at the end to catch any files left dirty by format or tidy. Use add_bin_path + with_mage (from common.sh) to set up Go and install mage from inside cmd/backport/, matching the version pinned in cmd/backport/.go-version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Changes to the main-only mage targets file should not trigger package tests. Also fixes a stale test path (dev/backports/ no longer exists) replaced with the correct cmd/backport/ path. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update all references in backport_branch.sh, non_package_patterns.txt, and test_non_package_patterns.sh. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
It is dev tooling (duplicate-name checker), not package content. Consistent with dev/codeowners, dev/gitutil, and similar patterns. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Backport branches must use the backport implementation from cmd/backport.
- Add `already_exists` outcome to `buildCommentBody` with a message linking the existing sync PR (falls back to branch name when no URL). - Append a `/sync-changelog` retry hint to all failure comments so maintainers can discover the retry command where they need it. - Thread `existingSyncPRURL` through `PostComment` and `buildCommentBody`. - Cover new behaviour with table-driven tests (TDD). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Fetch the remote-tracking ref before pushing so --force-with-lease has something to compare against, then overwrite the branch. This allows a retry to cleanly replace a stale working branch left by a previous failed run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Rename syncPRExists → existingSyncPR returning the PR URL so callers can surface it in comments rather than just a boolean. - Add ExistingSyncPRURL to CollectResult; populate it on the early-return path when a sync PR already exists. - Add knownPRNumber param to Collect to skip the merge-commit→PR association retry/backoff when the PR number is already known. - Wire BACKPORT_PR_NUMBER and EXISTING_SYNC_PR_URL through the mage targets; emit already_exists outcome when a sync PR already exists. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Add an issue_comment trigger so maintainers can retry a failed changelog sync by commenting /sync-changelog on the originating backport PR. - Split into two jobs with job-level ifs: sync-changelog (push) and retry-changelog (issue_comment), eliminating the zero-SHA guard step and all per-step proceed conditions. - retry-changelog gates execution on four sequential checks: PR is merged, actor has write/admin permission, base branch is backport-*, and the merge commit can be resolved to a before/after SHA pair. - Extract the shared setup steps (Go, mage, git, sync, comment) into a new composite action at .github/actions/sync-backport-changelog so both jobs reuse them without duplication. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Explains that citools, codeowners, and gitutil are local copies of their dev/ counterparts, and why a replace directive is not used. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
🚀 Benchmarks reportTo see the full report comment with |
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mrodm
commented
Aug 6, 2026
| # list all directories that are packages from the root of the repository | ||
| list_all_directories() { | ||
| mage -d "${WORKSPACE}" listPackages | ||
| mage -d "${WORKSPACE}" listPackages |grep -E '^packages/(nginx|elastic_package_registry)$' |
Collaborator
Author
There was a problem hiding this comment.
To be reverted before merging.
5 tasks
Merge separate_backport_tool into add-sync-changelog-comment. Conflict resolutions: - magefile.go: remove backport mage targets; they now live in cmd/backport/magefile.go. Daily-job targets moved to magefile_daily_jobs.go. - backport_branch.sh: merge both diff lines — include cmd/backport/ from separate_backport_tool and .github/actions/ + .github/workflows/ from HEAD. - sync-backport-changelog.yml: keep the two-job structure (sync-changelog on push, retry-changelog on issue_comment) from HEAD. Additional fixes needed after the merge: - action.yml: replace mage syncBackportChangelog/postBackportComment with the cmd/backport binary (go build -C cmd/backport, then backport sync-changelog / backport post-comment). Uses cmd/backport/.go-version. - cmd/backport/main.go: align runSyncChangelog and runPostComment with the updated signatures (4-arg Collect, 7-arg PostComment), add already_exists outcome, existing_sync_pr_url outputs, and pre-error output writes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
9 tasks
Conflict resolutions: - backport_branch.sh: removed .go-version from the diagnostic diff (root .go-version is not updated by the script; cmd/backport/.go-version is covered by the cmd/backport/ entry already copied from main); kept .github/actions/ and .github/workflows/ from our branch. - cmd/backport/main.go: kept all sync-changelog enhancements from our branch (4-arg Collect with BACKPORT_PR_NUMBER, already_exists outcome, existing_sync_pr_url outputs, pre-error output writes, 7-arg PostComment with EXISTING_SYNC_PR_URL). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
💚 Build Succeeded
History
cc @mrodm |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proposed commit message
WHAT:
retry-changelogjob insync-backport-changelog.ymltriggered byissue_commentevents. Guards: PR must be merged, commenter must have write/admin permission, base must be abackport-*branch..github/actions/sync-backport-changelog/holding the shared setup steps (Go, mage, git, sync, comment) reused by both the push and comment jobs.sync-changelogjob simplified to a job-levelif, removing the zero-SHA guard step and all per-stepproceedconditions.existingSyncPRincollect.gonow returns the PR URL (was bool) and only checks open PRs — merged/closed sync PRs no longer block future retries.Collectaccepts an optionalknownPRNumberto skip the merge-commit→PR association retry/backoff on the retry path.CreateSyncPRinsync.gousesgit fetch+--force-with-leaseto safely overwrite a stale working branch left by a previous failed run.already_existsoutcome surfaces the URL of an existing open sync PR instead of the misleading "versions already present on main" message./sync-changelogretry hint so maintainers can discover the command where they need it.SyncBackportChangelogmage target writes outputs before returning aCreateSyncPRerror, ensuring the comment step always fires..github/actions/added tonon_package_patterns.txtandpull-requests.jsonso changes to composite actions don't trigger package tests.WHY: When
gh pr createfails after the working branch has already been pushed (transient API error, rate limit), there is no self-service recovery path — the only option was pushing a dummy commit to the backport branch to re-trigger the workflow. The/sync-changelogcommand provides a clean retry path directly from the PR where the failure is reported.Author's Checklist
mainfirst (theissue_commenttrigger only activates once the workflow is on the default branch)--force-with-leasepath)backport_branch.sh)How to test this PR locally
The
issue_commenttrigger only fires when the workflow is on the default branch. To test on a fork:mainon your fork.backport-*branch, push a changelog change, let the push workflow run (or simulate a failure)./sync-changelog.retry-changelogjob runs and posts a success/skipped comment.Edge cases to verify:
already_existscomment with PR link--force-with-leaseoverwrites it cleanlyThis PR has been tested on a fork:
/sync-changelogon an open PR--force-with-leasepath)Related issues