@@ -3,8 +3,8 @@ name: Cherry-pick a pull request
33on :
44 workflow_dispatch :
55 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
88 required : true
99
1010jobs :
1515 cherryPick :
1616 needs : createNewVersion
1717 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 }}
2118 steps :
2219 - name : Checkout staging branch
2320 # v4
2724 token : ${{ secrets.OS_BOTIFY_TOKEN }}
2825 submodules : true
2926
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+
3044 # This command is necessary to fetch any branch other than main in the submodule.
3145 # See https://github.com/actions/checkout/issues/1815#issuecomment-2777836442 for further context.
3246 - name : Enable branch-switching in submodules
@@ -100,7 +114,7 @@ jobs:
100114 with :
101115 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
102116 USER : ${{ github.actor }}
103- PULL_REQUEST_NUMBER : ${{ github.event.inputs.PULL_REQUEST_NUMBER }}
117+ PULL_REQUEST_NUMBER : ${{ steps.getPRInfo.outputs.PR_NUMBER }}
104118
105119 - name : Cherry-pick the Mobile-Expensify version bump to Mobile-Expensify staging
106120 working-directory : Mobile-Expensify
@@ -137,8 +151,8 @@ jobs:
137151 - name : Push changes
138152 run : |
139153 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 }}
142156 else
143157 git push origin staging
144158 fi
@@ -150,13 +164,13 @@ jobs:
150164 AUTHOR_CHECKLIST=$(sed -n '/### PR Author Checklist/,$p' .github/PULL_REQUEST_TEMPLATE.md)
151165
152166 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 🍒
154168
155169 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:
156170
157171 \`\`\`bash
158172 git fetch
159- git checkout ${{ env .CONFLICT_BRANCH_NAME }}
173+ git checkout ${{ steps.getBranchName.outputs .CONFLICT_BRANCH_NAME }}
160174 git cherry-pick -S -x --mainline 1 ${{ steps.getCPMergeCommit.outputs.MERGE_COMMIT_SHA }}
161175 \`\`\`
162176
@@ -166,7 +180,7 @@ jobs:
166180 git commit --amend -m "\$(git log -1 --pretty=%B)" -m "(CP triggered by ${{ github.actor }})"
167181 \`\`\`
168182
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.
170184
171185 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.
172186
@@ -178,7 +192,7 @@ jobs:
178192
179193 # Create PR
180194 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 🍒" \
182196 --body "$PR_DESCRIPTION" \
183197 --label "Engineering,Hourly" \
184198 --base "staging"
@@ -190,15 +204,15 @@ jobs:
190204 if : fromJSON(steps.cherryPick.outputs.HAS_CONFLICTS)
191205 run : |
192206 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)"
194208 gh pr edit --add-assignee "$ORIGINAL_PR_AUTHOR"
195209 env :
196210 GITHUB_TOKEN : ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}
197211 # 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.
198212 continue-on-error : true
199213
200214 - 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'
202216 env :
203217 GITHUB_TOKEN : ${{ github.token }}
204218
@@ -214,7 +228,7 @@ jobs:
214228 attachments: [{
215229 color: "#DB4545",
216230 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 💥`,
218232 }]
219233 }
220234 env :
0 commit comments