-
Notifications
You must be signed in to change notification settings - Fork 173
ci(backport): add mergiraf + Claude fallback and workflow_dispatch trigger #4375
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
base: main
Are you sure you want to change the base?
Changes from all commits
f44c17b
3f0b7e7
4143ded
b6e853e
a756e23
5627553
64a2281
2112787
5fc93c4
04f1d17
bacfe60
eb97c31
3a2c8d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| if [[ $# -ne 2 ]]; then | ||
| echo "usage: $0 PR_NUMBER TARGET_BRANCH" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| pr_number="$1" | ||
| target_branch="$2" | ||
|
|
||
| : "${GITHUB_OUTPUT:?GITHUB_OUTPUT is not set}" | ||
| : "${GH_TOKEN:?GH_TOKEN is not set}" | ||
|
|
||
| meta=$(gh pr view "${pr_number}" --json state,title,mergeCommit \ | ||
| -q '{state,title,sha:.mergeCommit.oid}') | ||
| if [[ "$(jq -r '.state' <<<"${meta}")" != "MERGED" ]]; then | ||
| echo "PR #${pr_number} is not merged; refusing to backport" >&2 | ||
| exit 1 | ||
| fi | ||
| title=$(jq -r '.title' <<<"${meta}") | ||
| sha=$(jq -r '.sha' <<<"${meta}") | ||
|
|
||
| echo "backporting PR #${pr_number} (${sha}) to ${target_branch}" | ||
|
|
||
| branch="backport-${pr_number}-to-${target_branch}" | ||
| if git ls-remote --exit-code --heads origin "${branch}" >/dev/null; then | ||
| existing_pr=$(gh pr list --head "${branch}" --state open --json number,url -q '.[0]') | ||
| echo "branch '${branch}' already exists on origin: ${existing_pr:-no open PR}" >&2 | ||
| echo "delete the branch (and close its PR) and re-run to retry" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| git fetch origin "${target_branch}" | ||
| git checkout -b "${branch}" "origin/${target_branch}" | ||
|
|
||
| cherry_status=0 | ||
| git cherry-pick -x "${sha}" || cherry_status=$? | ||
|
|
||
| if [[ "${cherry_status}" -ne 0 ]]; then | ||
| mapfile -t conflicted < <(git diff --name-only --diff-filter=U) | ||
|
|
||
| if [[ ${#conflicted[@]} -eq 0 ]]; then | ||
| echo "cherry-pick failed (status ${cherry_status}) with no conflicted paths" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| git add -- "${conflicted[@]}" | ||
|
Comment on lines
+40
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When One edge case to consider: if the cherry-pick fails for a reason other than conflicts (e.g., the commit doesn't exist, or an empty commit), |
||
| git commit -m "backport: cherry-pick #${pr_number} to ${target_branch}" \ | ||
| -m "Cherry-picked from ${sha}; conflict markers committed for resolution." | ||
| fi | ||
|
|
||
| git push -u origin "${branch}" | ||
|
|
||
| pr_url=$(gh pr create \ | ||
| --base "${target_branch}" \ | ||
| --head "${branch}" \ | ||
| --draft \ | ||
| --title "[Backport ${target_branch}] ${title}" \ | ||
| --body "Backport of #${pr_number} to \`${target_branch}\`.") | ||
|
Comment on lines
+55
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding |
||
| pr_number_new="${pr_url##*/}" | ||
|
|
||
| if [[ -z "${pr_number_new}" || ! "${pr_number_new}" =~ ^[0-9]+$ ]]; then | ||
| echo "Could not parse new PR number from gh output: ${pr_url}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "created_pull_numbers=${pr_number_new}" >>"${GITHUB_OUTPUT}" | ||
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.
Is
id-token: writeneeded here? The original workflow only hadcontents: writeandpull-requests: write. Neither the korthout action, the dispatch script, nor the Claude action appear to require OIDC tokens. If this was added for a future need, it'd be worth commenting why — otherwise removing it would tighten the permission scope.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.
https://github.com/anthropics/claude-code-action/blob/main/docs/faq.md#why-am-i-getting-oidc-authentication-errors