forked from broadinstitute/cromwell
-
Notifications
You must be signed in to change notification settings - Fork 6
108 lines (90 loc) · 4.14 KB
/
combine_scalasteward_prs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: combine-scalasteward-prs
# With a thousand thanks to Qi who showed us this in Leonardo: https://github.com/DataBiosphere/leonardo/pull/1975
# Allows manually triggering of workflow on a selected branch via the GitHub Actions tab.
# GitHub blog demo: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/.
on:
workflow_dispatch:
inputs:
prLimit:
description: 'How many scala-steward PRs to consolidate in total'
required: true
default: 1000
prGroupSize:
description: 'How many scala-steward PRs to consolidate in each "consolidated" PR'
required: true
default: 5
jiraTicketId:
description: 'A Jira ticket ID to associate the new PRs with'
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Merge scala-steward PRs
id: msp
run: |
export GITHUB_TOKEN=${{ secrets.BROADBOT_GITHUB_TOKEN }}
PR_LIMIT=${{ github.event.inputs.prLimit }}
PR_GROUP_SIZE=${{ github.event.inputs.prGroupSize }}
echo "BASH_VERSION=${BASH_VERSION}"
git config user.name "broadbot"
echo "Fetching repo state..."
git fetch --quiet
git fetch origin develop:origin_develop
echo "Bringing in PRs:"
gh pr list --limit 1000 | grep 'scala-steward:' | tac | head -n${PR_LIMIT}
PR_LIST=($(gh pr list --limit 1000 | grep 'scala-steward:' | cut -d$'\t' -f 1 | tac | head -n${PR_LIMIT} | tr '\n' ' '))
PR_LIST_LENGTH=${#PR_LIST[@]}
echo "PR_LIST=${PR_LIST[@]}"
echo "PR_LIST_COUNT=${#PR_LIST[@]}"
NEXT_INDEX=0
NEXT_SLICE=("${PR_LIST[@]:$NEXT_INDEX:$PR_GROUP_SIZE}")
while [[ "${#NEXT_SLICE[@]}" -gt "0" ]]
do
FIRST_PR="${NEXT_SLICE[0]}"
LAST_PR="${NEXT_SLICE[-1]}"
NEW_BRANCH="consolidated-scala-steward-prs-${FIRST_PR}-${LAST_PR}-$(date +'%Y-%m-%d_%H-%M')"
echo "NEW_BRANCH=${NEW_BRANCH}"
git checkout origin_develop
echo "develop is currently at: $(git rev-parse --verify HEAD)"
git checkout -B ${NEW_BRANCH}
SUCCESSFUL_PRS=()
UNSUCCESSFUL_PRS=()
for pr in ${NEXT_SLICE[@]}
do
echo "Bringing in: $pr"
git fetch origin pull/${pr}/head:pr_${pr}_temp
git checkout ${NEW_BRANCH}
echo "${NEW_BRANCH} is currently at: $(git rev-parse --verify HEAD)"
git checkout pr_${pr}_temp
echo "pr_${pr}_temp is currently at: $(git rev-parse --verify HEAD)"
git rebase "${NEW_BRANCH}" "pr_${pr}_temp" && EXIT_CODE=$? || EXIT_CODE=$?
if [ "${EXIT_CODE}" == "0" ]
then
git checkout ${NEW_BRANCH}
git reset --hard "pr_${pr}_temp"
SUCCESSFUL_PRS+=( "
* #$pr" )
else
echo "Unexpected exit code: ${EXIT_CODE}"
git rebase --abort
git checkout ${NEW_BRANCH}
UNSUCCESSFUL_PRS+=( "
* #$pr" )
fi
done <<< ${NEXT_SLICE[@]}
echo "SUCCESSFUL_PRS=${SUCCESSFUL_PRS[@]}"
echo "UNSUCCESSFUL_PRS=${UNSUCCESSFUL_PRS[@]}"
if [[ "${#SUCCESSFUL_PRS[@]}" -gt "0" ]]
then
git push origin "${NEW_BRANCH}"
gh pr create \
--title "[${{ github.event.inputs.jiraTicketId }}] Scala-steward shepherding consolidation (${FIRST_PR} to ${LAST_PR})" \
--body "This PR was generated automatically by the github action: https://github.com/broadinstitute/cromwell/actions/workflows/combine_scalasteward_prs.yml
Consolidates scala-steward PRs: ${SUCCESSFUL_PRS[*]}
Merge conflicts during consolidation (if non-empty, this list of PRs will need to be manually applied): ${UNSUCCESSFUL_PRS[*]}"
fi
NEXT_INDEX=$(( NEXT_INDEX + PR_GROUP_SIZE ))
NEXT_SLICE=("${PR_LIST[@]:$NEXT_INDEX:$PR_GROUP_SIZE}")
done