Skip to content

Commit 9f5c6dd

Browse files
kewischwmontwe
authored andcommitted
Merge pull request #8628 from kewisch/uplift-merges
Add missing push in uplift merges GH action
1 parent a528da6 commit 9f5c6dd

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

.github/workflows/uplift-merges.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ jobs:
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v4
21+
with:
22+
sparse-checkout: |
23+
scripts/uplift-merges.sh
24+
sparse-checkout-cone-mode: false
25+
26+
- name: Configure for push
27+
if: ${{ !inputs.dryRun }}
28+
run: |
29+
git config --global user.name "GitHub Actions Bot"
30+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
2131
2232
- name: Run uplift script
2333
env:
2434
GH_TOKEN: ${{ github.token }}
25-
DRYRUN: ${{ inputs.dryRun && '' || '--no-dry-run' }}
35+
DRYRUN: ${{ !inputs.dryRun && '--no-dry-run' || '' }}
2636
BRANCH: ${{ github.ref_name }}
37+
PUSH: ${{ !inputs.dryRun && '--push' || '' }}
2738
run: |
28-
bash scripts/uplift-merges.sh $DRYRUN --$BRANCH
39+
bash scripts/uplift-merges.sh $DRYRUN --$BRANCH $PUSH | tee $GITHUB_STEP_SUMMARY

scripts/uplift-merges.sh

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
#!/bin/bash
22

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

9-
# Check if jq is installed
10-
if ! command -v jq &> /dev/null; then
11-
echo "Error: jq is not installed."
12-
exit 1
13-
fi
14-
15-
# Check if git is installed
16-
if ! command -v git &> /dev/null; then
17-
echo "Error: git is not installed."
18-
exit 1
19-
fi
8+
# Check if tools are installed
9+
command -v gh &> /dev/null || fail "gh (GitHub CLI) is not installed"
10+
command -v jq &> /dev/null || fail "jq is not installed"
11+
command -v git &> /dev/null || fail "git is not installed"
2012

2113
# Default values
2214
dry_run=true
2315
repo=${GITHUB_REPOSITORY:-thunderbird/thunderbird-android}
2416
label="task: uplift to beta"
2517
branch="beta"
18+
push=false
2619

2720
# Parse command-line arguments
2821
for arg in "$@"; do
@@ -41,26 +34,32 @@ for arg in "$@"; do
4134
branch="beta"
4235
shift
4336
;;
37+
--push)
38+
push=true
39+
shift
40+
;;
4441
*)
45-
echo "Unknown argument: $arg"
46-
exit 1
42+
fail "Unknown argument: $arg"
4743
;;
4844
esac
4945
done
5046

5147
# Check if on the correct branch
5248
current_branch=$(git branch --show-current)
5349
if [ "$current_branch" != "$branch" ]; then
54-
echo "Error: You are not on the $branch branch. Please switch to the $branch branch."
55-
exit 1
50+
fail "You are not on the $branch branch. Please switch to the $branch branch."
51+
fi
52+
53+
if [ "$dry_run" = true ]
54+
then
55+
echo "Dry run in progress, to disable pass --no-dry-run"
5656
fi
5757

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

6261
# Fetch the uplift commits from the GitHub repository
63-
json_data=$(gh pr list --repo "$repo" --label "$label" --state closed --json "mergedAt,mergeCommit,number,url")
62+
json_data=$(gh pr list --repo "$repo" --label "$label" --state merged --json "mergedAt,mergeCommit,number,url,title" | jq -c .)
6463

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

7473
# Generate git cherry-pick commands
75-
for commit in $sorted_commits; do
74+
while IFS= read -r commit
75+
do
7676
oid=$(echo "$commit" | jq -r '.mergeCommit.oid')
7777
pr_number=$(echo "$commit" | jq -r '.number')
7878
pr_url=$(echo "$commit" | jq -r '.url')
79-
echo "Cherry-picking $oid from $pr_url"
79+
pr_title=$(echo "$commit" | jq -r '.title')
80+
echo "Cherry-picking $oid from $pr_url ($pr_title)"
8081

8182
if [ "$dry_run" = false ]; then
82-
if git cherry-pick -m 1 "$oid"; then
83-
gh pr edit "$pr_number" --remove-label "$label"
84-
else
85-
echo "Failed to cherry-pick $oid"
86-
exit 1
83+
git cherry-pick -m 1 "$oid" || fail "Failed to cherry-pick $oid"
84+
if [ "$push" = true ]; then
85+
git push || fail "Failed to push $oid"
8786
fi
87+
88+
gh pr edit "$pr_number" --repo "$repo" --remove-label "$label" || fail "Failed to remove label from $pr_number"
8889
else
8990
echo "git cherry-pick -m 1 $oid"
90-
echo "gh pr edit $pr_number --remove-label \"$label\""
91+
[ "$push" = true ] && echo git push
92+
echo "gh pr edit $pr_number --repo \"$repo\" --remove-label \"$label\""
9193
fi
9294
echo ""
93-
done
95+
done <<< "$sorted_commits"

0 commit comments

Comments
 (0)