Skip to content

Commit d0f6b37

Browse files
committed
Merge pull request #61013 from Expensify/Rory-CPToProd
[No QA] CP to prod 🚀 (cherry picked from commit 5880736) (cherry-picked to production by roryabraham)
1 parent e92c21d commit d0f6b37

5 files changed

Lines changed: 208 additions & 83 deletions

File tree

.github/actions/javascript/markPullRequestsAsDeployed/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12787,7 +12787,7 @@ async function run() {
1278712787
});
1278812788
const prNumForCPMergeCommit = commit.message.match(/Merge pull request #(\d+)[\S\s]*\(cherry picked from commit .*\)/);
1278912789
if (prNumForCPMergeCommit?.at(1) === String(prNumber)) {
12790-
const cpActor = commit.message.match(/.*\(CP triggered by (.*)\)/)?.at(1);
12790+
const cpActor = commit.message.match(/.*\(cherry-picked to .* by (.*)\)/)?.at(1);
1279112791
if (cpActor) {
1279212792
deployer = cpActor;
1279312793
}

.github/actions/javascript/markPullRequestsAsDeployed/markPullRequestsAsDeployed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async function run() {
140140
});
141141
const prNumForCPMergeCommit = commit.message.match(/Merge pull request #(\d+)[\S\s]*\(cherry picked from commit .*\)/);
142142
if (prNumForCPMergeCommit?.at(1) === String(prNumber)) {
143-
const cpActor = commit.message.match(/.*\(CP triggered by (.*)\)/)?.at(1);
143+
const cpActor = commit.message.match(/.*\(cherry-picked to .* by (.*)\)/)?.at(1);
144144
if (cpActor) {
145145
deployer = cpActor;
146146
}

.github/workflows/cherryPick.yml

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ on:
66
PULL_REQUEST_URL:
77
description: The full URL of the Expensify/App pull request to cherry-pick
88
required: true
9+
TARGET:
10+
description: CP to staging or production?
11+
required: true
12+
type: choice
13+
options:
14+
- staging
15+
- production
16+
default: staging
917

1018
jobs:
1119
createNewVersion:
1220
uses: ./.github/workflows/createNewVersion.yml
1321
secrets: inherit
22+
with:
23+
# In order to submit a new build for production review, it must have a higher PATCH version than the previously-submitted build
24+
SEMVER_LEVEL: ${{ inputs.TARGET == 'staging' && 'BUILD' || 'PATCH' }}
1425

1526
cherryPick:
1627
needs: createNewVersion
@@ -24,32 +35,32 @@ jobs:
2435
2536
- name: Verify repository
2637
run: |
27-
if [[ "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" != ${{ github.repository }} ]] && [[ "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" != "Expensify/Mobile-Expensify" ]]; then
38+
if [[ "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" != ${{ github.repository }} ]] && [[ ! "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" =~ Expensify/Mobile-Expensify* ]]; then
2839
echo "::error::❌ Cherry picks are only supported for the Expensify/App and Expensify/Mobile-Expensify repositories. Found: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}"
2940
exit 1
3041
fi
3142
3243
- name: Set conflict branch name
3344
id: getBranchName
34-
run: echo "CONFLICT_BRANCH_NAME=cherry-pick-staging-${{ steps.getPRInfo.outputs.PR_NUMBER }}-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
45+
run: echo "CONFLICT_BRANCH_NAME=cherry-pick-${{ inputs.TARGET }}-${{ steps.getPRInfo.outputs.PR_NUMBER }}-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
3546

36-
- name: Checkout staging branch with full history if cherry picking Mobile-Expensify
37-
if: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME == 'Expensify/Mobile-Expensify' }}
47+
- name: Checkout target branch with full history if cherry picking Mobile-Expensify
48+
if: ${{ startsWith(steps.getPRInfo.outputs.REPO_FULL_NAME, 'Expensify/Mobile-Expensify') }}
3849
# v4
3950
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
4051
with:
41-
ref: staging
52+
ref: ${{ inputs.TARGET }}
4253
token: ${{ secrets.OS_BOTIFY_TOKEN }}
4354
submodules: true
4455
# Only fetch depth 0 for Mobile-Expensify, because it's a submodule and we need more history to cherry pick successfully
4556
fetch-depth: 0
46-
47-
- name: Checkout staging branch without full history if cherry picking App
48-
if: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME == 'Expensify/App' }}
57+
58+
- name: Checkout target branch without full history if cherry picking App
59+
if: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME == github.repository }}
4960
# v4
5061
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
5162
with:
52-
ref: staging
63+
ref: ${{ inputs.TARGET }}
5364
token: ${{ secrets.OS_BOTIFY_TOKEN }}
5465
submodules: true
5566

@@ -74,24 +85,14 @@ jobs:
7485
id: getPreviousVersion
7586
uses: ./.github/actions/javascript/getPreviousVersion
7687
with:
77-
SEMVER_LEVEL: "PATCH"
88+
SEMVER_LEVEL: ${{ inputs.TARGET == 'staging' && 'PATCH' || 'MINOR' }}
7889

7990
- name: Fetch history of relevant refs if cherry picking an App change
80-
if: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME == 'Expensify/App' }}
91+
if: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME == github.repository }}
8192
run: |
82-
# Temporary hack during transition when -staging suffix is being added to tags
83-
if git ls-remote origin refs/tags/${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }} | grep -q . ; then
84-
git fetch origin main staging --no-recurse-submodules --no-tags --shallow-exclude ${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }}
85-
else
86-
git fetch origin main staging --no-recurse-submodules --no-tags --shallow-exclude ${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }}-staging
87-
fi
93+
git fetch origin main ${{ inputs.TARGET }} --no-recurse-submodules --no-tags --shallow-exclude ${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }}
8894
cd Mobile-Expensify
89-
# Temporary hack during transition when -staging suffix is being added to tags
90-
if git ls-remote origin refs/tags/${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }} | grep -q . ; then
91-
git fetch origin main staging --no-recurse-submodules --no-tags --shallow-exclude ${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }}
92-
else
93-
git fetch origin main staging --no-recurse-submodules --no-tags --shallow-exclude ${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }}-staging
94-
fi
95+
git fetch origin main ${{ inputs.TARGET }} --no-recurse-submodules --no-tags --shallow-exclude ${{ steps.getPreviousVersion.outputs.PREVIOUS_VERSION }}
9596
9697
- name: Get E/App version bump commit
9798
id: getVersionBumpCommit
@@ -129,33 +130,35 @@ jobs:
129130
env:
130131
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
131132

132-
- name: Cherry-pick the Mobile-Expensify version bump to Mobile-Expensify staging
133+
- name: Cherry-pick the Mobile-Expensify version bump to Mobile-Expensify target branch
133134
working-directory: Mobile-Expensify
134135
run: |
135-
git switch staging
136+
git switch ${{ inputs.TARGET }}
136137
git cherry-pick -S -x --mainline 1 --strategy=recursive -Xtheirs ${{ steps.getMobileExpensifyVersionBumpCommit.outputs.VERSION_BUMP_SHA }}
137-
git push origin staging
138+
git commit --amend -m "$(git log -1 --pretty=%B)" -m "(cherry-picked to ${{ inputs.TARGET }} by ${{ github.actor }})"
139+
git push origin ${{ inputs.TARGET }}
138140
139-
- name: Cherry-pick the E/App version-bump to staging
141+
- name: Cherry-pick the E/App version-bump to target branch
140142
run: |
141-
git switch staging
143+
git switch ${{ inputs.TARGET }}
142144
git cherry-pick -S -x --mainline 1 --strategy=recursive -Xtheirs ${{ steps.getVersionBumpCommit.outputs.VERSION_BUMP_SHA }}
145+
git commit --amend -m "$(git log -1 --pretty=%B)" -m "(cherry-picked to ${{ inputs.TARGET }} by ${{ github.actor }})"
143146
144-
- name: Update the Mobile-Expensify submodule on E/App staging
147+
- name: Update the Mobile-Expensify submodule on E/App target branch
145148
run: |
146149
git add Mobile-Expensify
147150
git commit -m "Update Mobile-Expensify submodule version to ${{ needs.createNewVersion.outputs.NEW_VERSION }}"
148151
149152
- name: Cherry-pick the merge commit of target PR
150153
id: cherryPick
151154
# If cherry picking a Mobile-Expensify change, we need to run the cherry pick in the Mobile-Expensify directory
152-
working-directory: ${{ steps.getPRInfo.outputs.REPO_FULL_NAME == 'Expensify/Mobile-Expensify' && 'Mobile-Expensify' || '.' }}
155+
working-directory: ${{ startsWith(steps.getPRInfo.outputs.REPO_FULL_NAME, 'Expensify/Mobile-Expensify') && 'Mobile-Expensify' || '.' }}
153156
run: |
154157
echo "Attempting to cherry-pick ${{ steps.getCPMergeCommit.outputs.MERGE_COMMIT_SHA }}"
155158
if git cherry-pick -S -x --mainline 1 ${{ steps.getCPMergeCommit.outputs.MERGE_COMMIT_SHA }}; then
156159
echo "🎉 No conflicts! CP was a success, PR can be automerged 🎉"
157160
echo "HAS_CONFLICTS=false" >> "$GITHUB_OUTPUT"
158-
git commit --amend -m "$(git log -1 --pretty=%B)" -m "(CP triggered by ${{ github.actor }})"
161+
git commit --amend -m "$(git log -1 --pretty=%B)" -m "(cherry-picked to ${{ inputs.TARGET }} by ${{ github.actor }})"
159162
else
160163
echo "😞 PR can't be automerged, there are merge conflicts in the following files:"
161164
git --no-pager diff --name-only --diff-filter=U
@@ -169,10 +172,10 @@ jobs:
169172
git checkout -b ${{ steps.getBranchName.outputs.CONFLICT_BRANCH_NAME }}
170173
git push --set-upstream origin ${{ steps.getBranchName.outputs.CONFLICT_BRANCH_NAME }}
171174
else
172-
if [[ "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" == "Expensify/Mobile-Expensify" ]]; then
175+
if [[ "${{ steps.getPRInfo.outputs.REPO_FULL_NAME }}" =~ Expensify/Mobile-Expensify* ]]; then
173176
# Push Mobile-Expensify changes first
174177
cd Mobile-Expensify
175-
git push origin staging
178+
git push origin ${{ inputs.TARGET }}
176179
cd ..
177180
178181
# Update and commit the submodule reference in E/App
@@ -181,7 +184,7 @@ jobs:
181184
fi
182185
183186
# Push E/App changes
184-
git push origin staging
187+
git push origin ${{ inputs.TARGET }}
185188
fi
186189
187190
- name: Create Pull Request to manually finish CP
@@ -191,9 +194,9 @@ jobs:
191194
AUTHOR_CHECKLIST=$(sed -n '/### PR Author Checklist/,$p' .github/PULL_REQUEST_TEMPLATE.md)
192195
193196
PR_DESCRIPTION=$(cat <<EOF
194-
🍒 Cherry pick ${{ github.event.inputs.PULL_REQUEST_URL }} to staging 🍒
197+
🍒 Cherry pick ${{ github.event.inputs.PULL_REQUEST_URL }} to ${{ inputs.TARGET }} 🍒
195198
196-
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:
199+
This PR had conflicts when we tried to cherry-pick it to ${{ inputs.TARGET }}. You'll need to manually perform the cherry-pick, using the following steps:
197200
198201
\`\`\`bash
199202
git fetch
@@ -204,25 +207,25 @@ jobs:
204207
Then manually resolve conflicts, and commit the change with \`git cherry-pick --continue\`. Lastly, please run:
205208
206209
\`\`\`bash
207-
git commit --amend -m "\$(git log -1 --pretty=%B)" -m "(CP triggered by ${{ github.actor }})"
210+
git commit --amend -m "\$(git log -1 --pretty=%B)" -m "(cherry-picked to ${{ inputs.TARGET }} by ${{ github.actor }})"
208211
\`\`\`
209212
210-
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.
213+
This last part is important. It will help us keep track of who triggered this CP, and will ensure that version bumps are tracked correctly. 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.
211214
212215
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.
213216
214-
_Pro-tip:_ If this PR appears to have conflicts against the _staging_ base, it means that the version on staging has been updated. The easiest thing to do if you see this is to close the PR and re-run the CP.
217+
_Pro-tip:_ If this PR appears to have conflicts against the _${{ inputs.TARGET }}_ base, it means that the version on ${{ inputs.TARGET }} has been updated. The easiest thing to do if you see this is to close the PR and re-run the CP.
215218
216219
$AUTHOR_CHECKLIST
217220
EOF
218221
)
219222
220223
# Create PR
221224
gh pr create \
222-
--title "🍒 Cherry pick PR #${{ steps.getPRInfo.outputs.PR_NUMBER }} to staging 🍒" \
225+
--title "🍒 Cherry pick PR #${{ steps.getPRInfo.outputs.PR_NUMBER }} to ${{ inputs.TARGET }} 🍒" \
223226
--body "$PR_DESCRIPTION" \
224227
--label "Engineering,Hourly" \
225-
--base "staging"
228+
--base "${{ inputs.TARGET }}"
226229
sleep 5
227230
env:
228231
GITHUB_TOKEN: ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}
@@ -238,8 +241,8 @@ jobs:
238241
# 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.
239242
continue-on-error: true
240243

241-
- name: Label original PR with CP Staging
242-
run: gh pr edit ${{ github.event.inputs.PULL_REQUEST_URL }} --add-label 'CP Staging'
244+
- name: Label original PR with CP label
245+
run: gh pr edit ${{ github.event.inputs.PULL_REQUEST_URL }} --add-label '${{ inputs.TARGET == 'staging' && 'CP Staging' || 'CP Production' }}'
243246
env:
244247
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
245248

@@ -255,7 +258,7 @@ jobs:
255258
attachments: [{
256259
color: "#DB4545",
257260
pretext: `<!subteam^S4TJJ3PSL>`,
258-
text: `💥 Failed to CP ${{ github.event.inputs.PULL_REQUEST_URL }} to staging 💥`,
261+
text: `💥 Failed to CP ${{ github.event.inputs.PULL_REQUEST_URL }} to ${{ inputs.TARGET }} 💥`,
259262
}]
260263
}
261264
env:

0 commit comments

Comments
 (0)