@@ -3,8 +3,8 @@ name: Cherry-pick a pull request
3
3
on :
4
4
workflow_dispatch :
5
5
inputs :
6
- PULL_REQUEST_NUMBER :
7
- description : The number of a pull request to CP
6
+ PULL_REQUEST_URL :
7
+ description : The full URL of the Expensify/App pull request to cherry-pick
8
8
required : true
9
9
10
10
jobs :
15
15
cherryPick :
16
16
needs : createNewVersion
17
17
runs-on : ubuntu-latest
18
- env :
19
- # The name of the branch created if there are conflicts when CPing the PR.
20
- CONFLICT_BRANCH_NAME : cherry-pick-staging-${{ github.event.inputs.PULL_REQUEST_NUMBER }}-${{ github.run_id }}-${{ github.run_attempt }}
21
18
steps :
22
19
- name : Checkout staging branch
23
20
# v4
27
24
token : ${{ secrets.OS_BOTIFY_TOKEN }}
28
25
submodules : true
29
26
27
+ - name : Extract PR information
28
+ id : getPRInfo
29
+ run : |
30
+ echo "REPO_FULL_NAME=$(echo '${{ github.event.inputs.PULL_REQUEST_URL }}' | sed -E 's|https://github.com/([^/]+/[^/]+)/pull/.*|\1|')" >> "$GITHUB_OUTPUT"
31
+ echo "PR_NUMBER=$(echo '${{ github.event.inputs.PULL_REQUEST_URL }}' | sed -E 's|.*/pull/([0-9]+).*|\1|')" >> "$GITHUB_OUTPUT"
32
+
33
+ - name : Verify repository
34
+ run : |
35
+ if [ "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" != "Expensify/App" ]; then
36
+ echo "::error::❌ Cherry picks are only supported for the Expensify/App repository. Found: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}"
37
+ exit 1
38
+ fi
39
+
40
+ - name : Set conflict branch name
41
+ id : getBranchName
42
+ run : echo "CONFLICT_BRANCH_NAME=cherry-pick-staging-${{ steps.getPRInfo.outputs.PR_NUMBER }}-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
43
+
30
44
# This command is necessary to fetch any branch other than main in the submodule.
31
45
# See https://github.com/actions/checkout/issues/1815#issuecomment-2777836442 for further context.
32
46
- name : Enable branch-switching in submodules
@@ -100,7 +114,7 @@ jobs:
100
114
with :
101
115
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
102
116
USER : ${{ github.actor }}
103
- PULL_REQUEST_NUMBER : ${{ github.event.inputs.PULL_REQUEST_NUMBER }}
117
+ PULL_REQUEST_NUMBER : ${{ steps.getPRInfo.outputs.PR_NUMBER }}
104
118
105
119
- name : Cherry-pick the Mobile-Expensify version bump to Mobile-Expensify staging
106
120
working-directory : Mobile-Expensify
@@ -137,8 +151,8 @@ jobs:
137
151
- name : Push changes
138
152
run : |
139
153
if [[ ${{steps.cherryPick.outputs.HAS_CONFLICTS}} == 'true' ]]; then
140
- git checkout -b ${{ env .CONFLICT_BRANCH_NAME }}
141
- git push --set-upstream origin ${{ env .CONFLICT_BRANCH_NAME }}
154
+ git checkout -b ${{ steps.getBranchName.outputs .CONFLICT_BRANCH_NAME }}
155
+ git push --set-upstream origin ${{ steps.getBranchName.outputs .CONFLICT_BRANCH_NAME }}
142
156
else
143
157
git push origin staging
144
158
fi
@@ -150,13 +164,13 @@ jobs:
150
164
AUTHOR_CHECKLIST=$(sed -n '/### PR Author Checklist/,$p' .github/PULL_REQUEST_TEMPLATE.md)
151
165
152
166
PR_DESCRIPTION=$(cat <<EOF
153
- 🍒 Cherry pick https://github.com/Expensify/App/pull/ ${{ github.event.inputs.PULL_REQUEST_NUMBER }} to staging 🍒
167
+ 🍒 Cherry pick ${{ github.event.inputs.PULL_REQUEST_URL }} to staging 🍒
154
168
155
169
This PR had conflicts when we tried to cherry-pick it to staging. You'll need to manually perform the cherry-pick, using the following steps:
156
170
157
171
\`\`\`bash
158
172
git fetch
159
- git checkout ${{ env .CONFLICT_BRANCH_NAME }}
173
+ git checkout ${{ steps.getBranchName.outputs .CONFLICT_BRANCH_NAME }}
160
174
git cherry-pick -S -x --mainline 1 ${{ steps.getCPMergeCommit.outputs.MERGE_COMMIT_SHA }}
161
175
\`\`\`
162
176
@@ -166,7 +180,7 @@ jobs:
166
180
git commit --amend -m "\$(git log -1 --pretty=%B)" -m "(CP triggered by ${{ github.actor }})"
167
181
\`\`\`
168
182
169
- That will help us keep track of who triggered this CP. Once all that's done, push your changes with \`git push origin ${{ env .CONFLICT_BRANCH_NAME }}\`, and then open this PR for review.
183
+ That will help us keep track of who triggered this CP. Once all that's done, push your changes with \`git push origin ${{ steps.getBranchName.outputs .CONFLICT_BRANCH_NAME }}\`, and then open this PR for review.
170
184
171
185
Note that you **must** test this PR, and both the author and reviewer checklist should be completed, just as if you were merging the PR to main.
172
186
@@ -178,7 +192,7 @@ jobs:
178
192
179
193
# Create PR
180
194
gh pr create \
181
- --title "🍒 Cherry pick PR #${{ github.event.inputs.PULL_REQUEST_NUMBER }} to staging 🍒" \
195
+ --title "🍒 Cherry pick PR #${{ steps.getPRInfo.outputs.PR_NUMBER }} to staging 🍒" \
182
196
--body "$PR_DESCRIPTION" \
183
197
--label "Engineering,Hourly" \
184
198
--base "staging"
@@ -190,15 +204,15 @@ jobs:
190
204
if : fromJSON(steps.cherryPick.outputs.HAS_CONFLICTS)
191
205
run : |
192
206
gh pr edit --add-assignee "${{ github.actor }},${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }}"
193
- ORIGINAL_PR_AUTHOR="$(gh pr view ${{ github.event.inputs.PULL_REQUEST_NUMBER }} --json author --jq .author.login)"
207
+ ORIGINAL_PR_AUTHOR="$(gh pr view ${{ github.event.inputs.PULL_REQUEST_URL }} --json author --jq .author.login)"
194
208
gh pr edit --add-assignee "$ORIGINAL_PR_AUTHOR"
195
209
env :
196
210
GITHUB_TOKEN : ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}
197
211
# In cases when the original PR author is outside the org, the `gh pr edit` command will fail. But we don't want to fail the workflow in that case.
198
212
continue-on-error : true
199
213
200
214
- name : Label original PR with CP Staging
201
- run : gh pr edit ${{ inputs.PULL_REQUEST_NUMBER }} --add-label 'CP Staging'
215
+ run : gh pr edit ${{ github.event. inputs.PULL_REQUEST_URL }} --add-label 'CP Staging'
202
216
env :
203
217
GITHUB_TOKEN : ${{ github.token }}
204
218
@@ -214,7 +228,7 @@ jobs:
214
228
attachments: [{
215
229
color: "#DB4545",
216
230
pretext: `<!subteam^S4TJJ3PSL>`,
217
- text: `💥 Failed to CP https://github.com/Expensify/App/pull/ ${{ github.event.inputs.PULL_REQUEST_NUMBER }} to staging 💥`,
231
+ text: `💥 Failed to CP ${{ github.event.inputs.PULL_REQUEST_URL }} to staging 💥`,
218
232
}]
219
233
}
220
234
env :
0 commit comments