-
Notifications
You must be signed in to change notification settings - Fork 3.1k
239 lines (212 loc) · 10.6 KB
/
cherryPick.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Cherry-pick a pull request
on:
workflow_dispatch:
inputs:
PULL_REQUEST_NUMBER:
description: The number of a pull request to CP
required: true
NEW_VERSION:
description: The new app version
required: false
default: ''
jobs:
validateActor:
runs-on: ubuntu-latest
outputs:
IS_DEPLOYER: ${{ fromJSON(steps.isUserDeployer.outputs.isTeamMember) || github.actor == 'OSBotify' }}
steps:
- id: isUserDeployer
uses: tspascoal/get-user-teams-membership@baf2e6adf4c3b897bd65a7e3184305c165aec872
with:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
username: ${{ github.actor }}
team: mobile-deployers
createNewVersion:
needs: validateActor
runs-on: ubuntu-latest
if: ${{ fromJSON(needs.validateActor.outputs.IS_DEPLOYER) && github.event.inputs.NEW_VERSION == '' }}
outputs:
NEW_VERSION: ${{ steps.getNewVersion.outputs.NEW_VERSION }}
steps:
- name: Checkout main branch
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
ref: main
token: ${{ secrets.OS_BOTIFY_TOKEN }}
- uses: softprops/turnstyle@8db075d65b19bf94e6e8687b504db69938dc3c65
with:
poll-interval-seconds: 10
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create new BUILD version
uses: Expensify/App/.github/actions/triggerWorkflowAndWait@main
with:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
WORKFLOW: createNewVersion.yml
INPUTS: '{ "SEMVER_LEVEL": "BUILD" }'
- name: Pull main to get the new version
id: getNewVersion
run: |
git pull origin main
echo "New version is $(npm run print-version --silent)"
echo "::set-output name=NEW_VERSION::$(npm run print-version --silent)"
cherryPick:
needs: [validateActor, createNewVersion]
if: ${{ always() && fromJSON(needs.validateActor.outputs.IS_DEPLOYER) }}
runs-on: ubuntu-latest
steps:
# Version: 2.3.4
- name: Checkout staging branch
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
with:
ref: staging
token: ${{ secrets.OS_BOTIFY_TOKEN }}
- name: Decrypt Botify GPG key
run: cd .github/workflows && gpg --quiet --batch --yes --decrypt --passphrase="$LARGE_SECRET_PASSPHRASE" --output OSBotify-private-key.asc OSBotify-private-key.asc.gpg
env:
LARGE_SECRET_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
- name: Import Botify GPG Key
run: cd .github/workflows && gpg --import OSBotify-private-key.asc
- name: Set up git for Botify
run: |
git config user.signingkey 367811D53E34168C
git config commit.gpgsign true
git config user.name OSBotify
git config user.email infra+osbotify@expensify.com
- name: Create branch for new pull request
run: |
git checkout -b ${{ github.actor }}-cherry-pick-staging-${{ github.event.inputs.PULL_REQUEST_NUMBER }}
git push --set-upstream origin ${{ github.actor }}-cherry-pick-staging-${{ github.event.inputs.PULL_REQUEST_NUMBER }}
- name: Get merge commit for CP pull request
id: getCPMergeCommit
uses: Expensify/App/.github/actions/getPullRequestDetails@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USER: ${{ github.actor }}
PULL_REQUEST_NUMBER: ${{ github.event.inputs.PULL_REQUEST_NUMBER }}
- name: Save correct NEW_VERSION to env
env:
NEW_VERSION: ${{ github.event.inputs.NEW_VERSION }}
run: |
if [ -z "$NEW_VERSION" ]; then
echo "NEW_VERSION=${{ needs.createNewVersion.outputs.NEW_VERSION }}" >> "$GITHUB_ENV"
echo "New version is ${{ env.NEW_VERSION }}"
else
echo "NEW_VERSION=${{ github.event.inputs.NEW_VERSION }}" >> "$GITHUB_ENV"
echo "New version is ${{ env.NEW_VERSION }}"
fi;
- name: Get merge commit for version-bump pull request
id: getVersionBumpMergeCommit
uses: Expensify/App/.github/actions/getPullRequestDetails@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
USER: OSBotify
TITLE_REGEX: Update version to ${{ env.NEW_VERSION }}
- name: Cherry-pick the version-bump to new branch
run: |
git fetch
git cherry-pick -S -x --mainline 1 --strategy=recursive -Xtheirs ${{ steps.getVersionBumpMergeCommit.outputs.MERGE_COMMIT_SHA }}
- name: Cherry-pick the merge commit of target PR to new branch
id: cherryPick
run: |
echo "Attempting to cherry-pick ${{ steps.getCPMergeCommit.outputs.MERGE_COMMIT_SHA }}"
if git cherry-pick -S -x --mainline 1 ${{ steps.getCPMergeCommit.outputs.MERGE_COMMIT_SHA }}; then
echo "🎉 No conflicts! CP was a success, PR can be automerged 🎉"
echo "::set-output name=SHOULD_AUTOMERGE::true"
else
echo "😞 PR can't be automerged, there are merge conflicts in the following files:"
git --no-pager diff --name-only --diff-filter=U
git add .
GIT_MERGE_AUTOEDIT=no git cherry-pick --continue
echo "::set-output name=SHOULD_AUTOMERGE::false"
fi
- name: Push changes to CP branch
run: git push
- name: Create Pull Request
id: createPullRequest
# Version: 2.4.3
uses: repo-sync/pull-request@65194d8015be7624d231796ddee1cd52a5023cb3
with:
source_branch: ${{ github.actor }}-cherry-pick-staging-${{ github.event.inputs.PULL_REQUEST_NUMBER }}
destination_branch: staging
github_token: ${{ secrets.OS_BOTIFY_TOKEN }}
pr_title: '🍒 Cherry pick PR #${{ github.event.inputs.PULL_REQUEST_NUMBER }} to staging 🍒'
pr_body: '🍒 Cherry pick https://github.com/Expensify/App/pull/${{ github.event.inputs.PULL_REQUEST_NUMBER }} to staging 🍒'
pr_label: automerge
- name: Check if ShortVersionString is up to date
id: isShortVersionStringUpdated
uses: Expensify/App/.github/actions/checkBundleVersionStringMatch@main
- name: Auto-assign PR if there are merge conflicts or if the bundle versions are mismatched
if: ${{ !fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) || !fromJSON(steps.isShortVersionStringUpdated.outputs.BUNDLE_VERSIONS_MATCH) }}
uses: actions-ecosystem/action-add-labels@a8ae047fee0ca28235f9764e1c478d2136dc15c1
with:
number: ${{ steps.createPullRequest.outputs.pr_number }}
labels: |
Engineering
Hourly
- name: Assign the PR to the deployer
if: ${{ !fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) }}
uses: actions-ecosystem/action-add-assignees@a73fcabd82d847c5e7433fcfdd58ef9f7e8a3993
with:
number: ${{ steps.createPullRequest.outputs.pr_number }}
github_token: ${{ secrets.GITHUB_TOKEN }}
assignees: ${{ steps.getCPMergeCommit.outputs.MERGE_ACTOR }}
- name: If PR has merge conflicts, comment with instructions for assignee
if: ${{ !fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) }}
uses: actions-ecosystem/action-create-comment@cd098164398331c50e7dfdd0dfa1b564a1873fac
with:
github_token: ${{ secrets.OS_BOTIFY_TOKEN }}
number: ${{ steps.createPullRequest.outputs.pr_number }}
body: |
This pull request has merge conflicts and can not be automatically merged. :disappointed:
Please manually resolve the conflicts, push your changes, and then request another reviewer to review and merge.
**Important:** There may be conflicts that GitHub is not able to detect, so please _carefully_ review this pull request before approving.
- name: If PR has a bundle version mismatch, comment with the instructions for assignee
if: ${{ !fromJSON(steps.isShortVersionStringUpdated.outputs.BUNDLE_VERSIONS_MATCH) }}
uses: actions-ecosystem/action-create-comment@cd098164398331c50e7dfdd0dfa1b564a1873fac
with:
github_token: ${{ secrets.OS_BOTIFY_TOKEN }}
number: ${{ steps.createPullRequest.outputs.pr_number }}
body: |
The CFBundleShortVersionString value in this PR is not compatible with the CFBundleVersion, so cherry picking it will result in an iOS deploy failure.
Please manually resolve the mismatch, push your changes, and then request another reviewer to review and merge.
**Important:** This mismatch can be caused by a failed Update Protected Branch workflow followed by a manual CP, but please confirm the cause of the mismatch before updating any version numbers.
- name: Check for an auto approve
# Important: only auto-approve if there was no merge conflict!
if: ${{ fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) }}
# Version: 2.0.0
uses: hmarr/auto-approve-action@6a9ec7556f0a7fa5b49527a1eea4878b8a22d2e0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ steps.createPullRequest.outputs.pr_number }}
- name: Check if pull request is mergeable
id: isPullRequestMergeable
uses: Expensify/App/.github/actions/isPullRequestMergeable@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_NUMBER: ${{ steps.createPullRequest.outputs.pr_number }}
- name: Check for an auto merge
# Important: only auto-merge if there was no merge conflict!
if: ${{ fromJSON(steps.cherryPick.outputs.SHOULD_AUTOMERGE) && fromJSON(steps.isPullRequestMergeable.outputs.IS_MERGEABLE) }}
# Version: 0.12.0
uses: pascalgn/automerge-action@39d831e1bb389bd242626bc25d4060064a97181c
env:
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
PULL_REQUEST: ${{ steps.createPullRequest.outputs.pr_number }}
- name: 'Announces a CP failure in the #announce Slack room'
uses: 8398a7/action-slack@v3
if: ${{ failure() }}
with:
status: custom
custom_payload: |
{
channel: '#announce',
attachments: [{
color: "#DB4545",
pretext: `<!subteam^S4TJJ3PSL>`,
text: `💥 Failed to CP https://github.com/Expensify/App/pull/${{ github.event.inputs.PULL_REQUEST_NUMBER }} to staging 💥`,
}]
}
env:
GITHUB_TOKEN: ${{ github.token }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}