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
15 changes: 13 additions & 2 deletions .github/workflows/uplift-merges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
scripts/uplift-merges.sh
sparse-checkout-cone-mode: false

- name: Configure for push
if: ${{ !inputs.dryRun }}
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Run uplift script
env:
GH_TOKEN: ${{ github.token }}
DRYRUN: ${{ inputs.dryRun && '' || '--no-dry-run' }}
DRYRUN: ${{ !inputs.dryRun && '--no-dry-run' || '' }}
BRANCH: ${{ github.ref_name }}
PUSH: ${{ !inputs.dryRun && '--push' || '' }}
run: |
bash scripts/uplift-merges.sh $DRYRUN --$BRANCH
bash scripts/uplift-merges.sh $DRYRUN --$BRANCH $PUSH | tee $GITHUB_STEP_SUMMARY
64 changes: 33 additions & 31 deletions scripts/uplift-merges.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#!/bin/bash

# Check if gh is installed
if ! command -v gh &> /dev/null; then
echo "Error: gh (GitHub CLI) is not installed."
exit 1
fi
function fail() {
echo "Error: $*"
exit 1
}

# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed."
exit 1
fi

# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Error: git is not installed."
exit 1
fi
# 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"
command -v git &> /dev/null || fail "git is not installed"

# Default values
dry_run=true
repo=${GITHUB_REPOSITORY:-thunderbird/thunderbird-android}
label="task: uplift to beta"
branch="beta"
push=false

# Parse command-line arguments
for arg in "$@"; do
Expand All @@ -41,26 +34,32 @@ for arg in "$@"; do
branch="beta"
shift
;;
--push)
push=true
shift
;;
*)
echo "Unknown argument: $arg"
exit 1
fail "Unknown argument: $arg"
;;
esac
done

# Check if on the correct branch
current_branch=$(git branch --show-current)
if [ "$current_branch" != "$branch" ]; then
echo "Error: You are not on the $branch branch. Please switch to the $branch branch."
exit 1
fail "You are not on the $branch branch. Please switch to the $branch branch."
fi

if [ "$dry_run" = true ]
then
echo "Dry run in progress, to disable pass --no-dry-run"
fi

echo "Dry run: $dry_run, to disable dry run pass --no-dry-run"
echo "Label: \"$label\""
echo ""

# Fetch the uplift commits from the GitHub repository
json_data=$(gh pr list --repo "$repo" --label "$label" --state closed --json "mergedAt,mergeCommit,number,url")
json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --json "mergedAt,mergeCommit,number,url,title" | jq -c .)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You had closed, any specific reason? merged seems more useful since it would skip PRs that were closed before they were merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason.


# Sort by mergedAt
sorted_commits=$(echo "$json_data" | jq -c '. | sort_by(.mergedAt) | .[]')
Expand All @@ -72,22 +71,25 @@ if [ -z "$sorted_commits" ]; then
fi

# Generate git cherry-pick commands
for commit in $sorted_commits; do
while IFS= read -r commit
do
oid=$(echo "$commit" | jq -r '.mergeCommit.oid')
pr_number=$(echo "$commit" | jq -r '.number')
pr_url=$(echo "$commit" | jq -r '.url')
echo "Cherry-picking $oid from $pr_url"
pr_title=$(echo "$commit" | jq -r '.title')
echo "Cherry-picking $oid from $pr_url ($pr_title)"

if [ "$dry_run" = false ]; then
if git cherry-pick -m 1 "$oid"; then
gh pr edit "$pr_number" --remove-label "$label"
else
echo "Failed to cherry-pick $oid"
exit 1
git cherry-pick -m 1 "$oid" || fail "Failed to cherry-pick $oid"
if [ "$push" = true ]; then
git push || fail "Failed to push $oid"
fi

gh pr edit "$pr_number" --repo "$repo" --remove-label "$label" || fail "Failed to remove label from $pr_number"
else
echo "git cherry-pick -m 1 $oid"
echo "gh pr edit $pr_number --remove-label \"$label\""
[ "$push" = true ] && echo git push
echo "gh pr edit $pr_number --repo \"$repo\" --remove-label \"$label\""
fi
echo ""
done
done <<< "$sorted_commits"