Loading scripts/ci/uplift-merges.sh +35 −6 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ function fail() { echo "Error: $*" exit 1 } function drydo() { if [ "$dry_run" = true ]; then echo "$@" Loading @@ -12,6 +13,16 @@ function drydo() { fi } function usage() { echo "Usage: $0 [--release | --beta] [--no-dry-run] [--push]" echo echo " --release Required: merge into release branch (mutually exclusive with --beta)" echo " --beta Required: merge into beta branch (mutually exclusive with --release)" echo " --no-dry-run Optional: actually perform the merge" echo " --push Optional: push changes after completion" exit 1 } # Check if tools are installed command -v gh &> /dev/null || fail "gh (GitHub CLI) is not installed" command -v jq &> /dev/null || fail "jq is not installed" Loading @@ -21,7 +32,7 @@ command -v git &> /dev/null || fail "git is not installed" dry_run=true repo=${GITHUB_REPOSITORY:-thunderbird/thunderbird-android} label="task: uplift to beta" branch="beta" branch="" push=false milestones=$(gh api repos/${repo}/milestones --jq 'map(select(.state == "open" and .due_on != null)) | sort_by(.due_on)' | jq -c) Loading Loading @@ -52,11 +63,15 @@ for arg in "$@"; do shift ;; *) fail "Unknown argument: $arg" usage ;; esac done if [[ -z "$branch" ]]; then usage fi # Check if on the correct branch current_branch=$(git branch --show-current) if [ "$current_branch" != "$branch" ]; then Loading @@ -80,7 +95,7 @@ echo "Label: \"$label\"" echo "" # Fetch the uplift commits from the GitHub repository json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --json "mergedAt,mergeCommit,number,url,title,milestone" | jq -c .) json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --limit 99 --json "mergedAt,mergeCommit,number,url,title,milestone" | jq -c .) # Sort by mergedAt sorted_commits=$(echo "$json_data" | jq -c '. | sort_by(.mergedAt) | .[]') Loading @@ -99,17 +114,31 @@ do pr_url=$(echo "$commit" | jq -r '.url') pr_title=$(echo "$commit" | jq -r '.title') pr_milestone=$(echo "$commit" | jq -r '.milestone.title') echo "Cherry-picking $oid from $pr_url ($pr_title)" echo "Updating branches" git checkout main && git pull --quiet git checkout $current_branch && git pull --quiet echo "Cherry-picking $oid from $pr_url ($pr_title)" if [ "$pr_milestone" != "$expected_milestone" ]; then fail "PR https://github.com/$repo/pull/$pr_number is on milestone $pr_milestone but expected $expected_milestone" fi drydo git cherry-pick -m 1 "$oid" || fail "Failed to cherry-pick $oid" if [ "$dry_run" = true ]; then dry_run_branch="${branch}-dry-run" if git show-ref --verify --quiet refs/heads/${dry_run_branch}; then git branch -D "${dry_run_branch}" fi git checkout -b "${dry_run_branch}" echo "Using $dry_run_branch for cherry-picks" fi if ! git cherry-pick -m 1 "$oid"; then fail "Failed to cherry-pick $oid" fi if [ "$push" = true ]; then drydo git push || fail "Failed to push $oid" fi drydo gh pr edit "$pr_number" --repo "$repo" --remove-label "$label" --milestone "$target_milestone" || fail "Failed to remove label from $pr_number" drydo gh pr edit "$pr_number" --repo "$repo" --remove-label '"$label"' --milestone '"$target_milestone"' || fail "Failed to remove label from $pr_number" echo "" done <<< "$sorted_commits" Loading
scripts/ci/uplift-merges.sh +35 −6 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ function fail() { echo "Error: $*" exit 1 } function drydo() { if [ "$dry_run" = true ]; then echo "$@" Loading @@ -12,6 +13,16 @@ function drydo() { fi } function usage() { echo "Usage: $0 [--release | --beta] [--no-dry-run] [--push]" echo echo " --release Required: merge into release branch (mutually exclusive with --beta)" echo " --beta Required: merge into beta branch (mutually exclusive with --release)" echo " --no-dry-run Optional: actually perform the merge" echo " --push Optional: push changes after completion" exit 1 } # Check if tools are installed command -v gh &> /dev/null || fail "gh (GitHub CLI) is not installed" command -v jq &> /dev/null || fail "jq is not installed" Loading @@ -21,7 +32,7 @@ command -v git &> /dev/null || fail "git is not installed" dry_run=true repo=${GITHUB_REPOSITORY:-thunderbird/thunderbird-android} label="task: uplift to beta" branch="beta" branch="" push=false milestones=$(gh api repos/${repo}/milestones --jq 'map(select(.state == "open" and .due_on != null)) | sort_by(.due_on)' | jq -c) Loading Loading @@ -52,11 +63,15 @@ for arg in "$@"; do shift ;; *) fail "Unknown argument: $arg" usage ;; esac done if [[ -z "$branch" ]]; then usage fi # Check if on the correct branch current_branch=$(git branch --show-current) if [ "$current_branch" != "$branch" ]; then Loading @@ -80,7 +95,7 @@ echo "Label: \"$label\"" echo "" # Fetch the uplift commits from the GitHub repository json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --json "mergedAt,mergeCommit,number,url,title,milestone" | jq -c .) json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --limit 99 --json "mergedAt,mergeCommit,number,url,title,milestone" | jq -c .) # Sort by mergedAt sorted_commits=$(echo "$json_data" | jq -c '. | sort_by(.mergedAt) | .[]') Loading @@ -99,17 +114,31 @@ do pr_url=$(echo "$commit" | jq -r '.url') pr_title=$(echo "$commit" | jq -r '.title') pr_milestone=$(echo "$commit" | jq -r '.milestone.title') echo "Cherry-picking $oid from $pr_url ($pr_title)" echo "Updating branches" git checkout main && git pull --quiet git checkout $current_branch && git pull --quiet echo "Cherry-picking $oid from $pr_url ($pr_title)" if [ "$pr_milestone" != "$expected_milestone" ]; then fail "PR https://github.com/$repo/pull/$pr_number is on milestone $pr_milestone but expected $expected_milestone" fi drydo git cherry-pick -m 1 "$oid" || fail "Failed to cherry-pick $oid" if [ "$dry_run" = true ]; then dry_run_branch="${branch}-dry-run" if git show-ref --verify --quiet refs/heads/${dry_run_branch}; then git branch -D "${dry_run_branch}" fi git checkout -b "${dry_run_branch}" echo "Using $dry_run_branch for cherry-picks" fi if ! git cherry-pick -m 1 "$oid"; then fail "Failed to cherry-pick $oid" fi if [ "$push" = true ]; then drydo git push || fail "Failed to push $oid" fi drydo gh pr edit "$pr_number" --repo "$repo" --remove-label "$label" --milestone "$target_milestone" || fail "Failed to remove label from $pr_number" drydo gh pr edit "$pr_number" --repo "$repo" --remove-label '"$label"' --milestone '"$target_milestone"' || fail "Failed to remove label from $pr_number" echo "" done <<< "$sorted_commits"