forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPullRequestsMergedBetweenTest.sh
executable file
·330 lines (269 loc) · 10.8 KB
/
getPullRequestsMergedBetweenTest.sh
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
# Fail immediately if there is an error thrown
set -e
TEST_DIR=$(dirname "$(dirname "$(cd "$(dirname "$0")" || exit 1;pwd)/$(basename "$0")")")
SCRIPTS_DIR="$TEST_DIR/../scripts"
DUMMY_DIR="$HOME/DumDumRepo"
getPullRequestsMergedBetween="$TEST_DIR/utils/getPullRequestsMergedBetween.mjs"
source "$SCRIPTS_DIR/shellUtils.sh"
function print_version {
< package.json jq -r .version
}
### Phase 0: Verify necessary tools are installed (all tools should be pre-installed on all GitHub Actions runners)
if ! command -v jq &> /dev/null
then
error "command jq could not be found, install it with \`brew install jq\` (macOS) or \`apt-get install jq\` (Linux) and re-run this script"
exit 1
fi
if ! command -v npm &> /dev/null
then
error "command npm could not be found, install it and re-run this script"
exit 1
fi
### Setup
title "Starting setup"
info "Creating new dummy repo at $DUMMY_DIR"
mkdir "$DUMMY_DIR"
cd "$DUMMY_DIR" || exit 1
success "Successfully created dummy repo at $(pwd)"
info "Initializing npm project in $DUMMY_DIR"
if [[ $(npm init -y) ]]
then
success "Successfully initialized npm project"
else
error "Failed initializing npm project"
exit 1
fi
info "Installing node dependencies..."
if [[ $(npm install underscore && npm install) ]]
then
success "Successfully installed node dependencies"
else
error "Failed installing node dependencies"
exit 1
fi
info "Initializing Git repo..."
git init -b main
git config user.email "[email protected]"
git config user.name "test"
git add package.json package-lock.json
git commit -m "Initial commit"
info "Bumping version to 1.0.1"
npm --no-git-tag-version version 1.0.1 -m "Update version to 1.0.1"
git add package.json
git commit -m "Update version to 1.0.1"
info "Creating branches..."
git checkout -b staging
git checkout -b production
git checkout main
success "Initialized Git repo!"
info "Creating initial tag..."
git checkout staging
git tag "$(print_version)"
git checkout main
success "Created initial tag $(print_version)"
success "Setup complete!"
title "Scenario #1: Merge a pull request while the checklist is unlocked"
# Create "PR 1", and merge that PR to main.
info "Creating PR #1"
git checkout main
git checkout -b pr-1
echo "Changes from PR #1" >> PR1.txt
git add PR1.txt
git commit -m "Changes from PR #1"
success "Created PR #1 in branch pr-1"
info "Merging PR #1 to main"
git checkout main
git merge pr-1 --no-ff -m "Merge pull request #1 from Expensify/pr-1"
git branch -d pr-1
success "Merged PR #1 to main"
# Bump the version to 1.0.2
info "Bumping version to 1.0.2"
git checkout main
git checkout -b version-bump
npm --no-git-tag-version version 1.0.2 -m "Update version to 1.0.2"
git add package.json package-lock.json
git commit -m "Update version to $(print_version)"
git checkout main
git merge version-bump --no-ff -m "Merge pull request #2 from Expensify/version-bump"
info "Merged PR #2 to main"
git branch -d version-bump
success "Version bumped to $(print_version) on main"
# Merge main into staging
info "Merging main into staging..."
git checkout staging
git checkout -b update-staging-from-main
git merge --no-edit -Xtheirs main || { git diff --name-only --diff-filter=U | xargs git rm; git -c core.editor=true merge --continue; }
git checkout staging
git merge update-staging-from-main --no-ff -m "Merge pull request #3 from Expensify/update-staging-from-main"
info "Merged PR #3 to staging"
git branch -d update-staging-from-main
success "Merged main into staging!"
# Tag staging
info "Tagging new version..."
git checkout staging
git tag "$(print_version)"
git checkout main
success "Created new tag $(print_version)"
# Verify output for checklist and deploy comment
info "Checking output of getPullRequestsMergedBetween 1.0.1 1.0.2"
output=$(node "$getPullRequestsMergedBetween" '1.0.1' '1.0.2')
assert_equal "$output" "[ '1' ]"
success "Scenario #1 completed successfully!"
title "Scenario #2: Merge a pull request with the checklist locked, but don't CP it"
info "Creating PR #4 and merging it into main..."
git checkout main
git checkout -b pr-4
echo "Changes from PR #4" >> PR4.txt
git add PR4.txt
git commit -m "Changes from PR #4"
git checkout main
git merge pr-4 --no-ff -m "Merge pull request #4 from Expensify/pr-4"
info "Merged PR #4 into main"
git branch -d pr-4
success "Created PR #4 and merged it to main!"
success "Scenario #2 completed successfully!"
title "Scenario #3: Merge a pull request with the checklist locked and CP it to staging"
info "Creating PR #5 and merging it into main..."
git checkout main
git checkout -b pr-5
echo "Changes from PR #5" >> PR5.txt
git add PR5.txt
git commit -m "Changes from PR #5"
git checkout main
git merge pr-5 --no-ff -m "Merge pull request #5 from Expensify/pr-5"
PR_5_MERGE_COMMIT="$(git log -1 --format='%H')"
info "Merged PR #5 into main"
git branch -d pr-5
success "Created PR #5 and merged it to main!"
info "Bumping version to 1.0.3 on main..."
git checkout main
git checkout -b version-bump
npm --no-git-tag-version version 1.0.3 -m "Update version to 1.0.3"
git add package.json package-lock.json
git commit -m "Update version to $(print_version)"
git checkout main
git merge version-bump --no-ff -m "Merge pull request #6 from Expensify/version-bump"
VERSION_BUMP_MERGE_COMMIT="$(git log -1 --format='%H')"
info "Merged PR #6 into main"
git branch -d version-bump
success "Bumped version to 1.0.3 on main!"
info "Cherry picking PR #5 and the version bump to staging..."
git checkout staging
git checkout -b cherry-pick-staging-5
git cherry-pick -x --mainline 1 --strategy=recursive -Xtheirs "$PR_5_MERGE_COMMIT"
git cherry-pick -x --mainline 1 "$VERSION_BUMP_MERGE_COMMIT"
git checkout staging
git merge cherry-pick-staging-5 --no-ff -m "Merge pull request #7 from Expensify/cherry-pick-staging-5"
git branch -d cherry-pick-staging-5
info "Merged PR #7 into staging"
success "Successfully cherry-picked PR #5 to staging!"
info "Tagging the new version on staging..."
git checkout staging
git tag "$(print_version)"
success "Created tag $(print_version)"
# Verify output for checklist
info "Checking output of getPullRequestsMergedBetween 1.0.1 1.0.3"
output=$(node "$getPullRequestsMergedBetween" '1.0.1' '1.0.3')
assert_equal "$output" "[ '7', '5', '1' ]"
# Verify output for deploy comment
info "Checking output of getPullRequestsMergedBetween 1.0.2 1.0.3"
output=$(node "$getPullRequestsMergedBetween" '1.0.2' '1.0.3')
assert_equal "$output" "[ '7', '5' ]"
success "Scenario #3 completed successfully!"
title "Scenario #4: Close the checklist"
title "Scenario #4A: Run the production deploy"
info "Updating production from staging..."
git checkout production
git checkout -b update-production-from-staging
git merge --no-edit -Xtheirs staging || { git diff --name-only --diff-filter=U | xargs git rm; git -c core.editor=true merge --continue; }
git checkout production
git merge update-production-from-staging --no-ff -m "Merge pull request #8 from Expensify/update-production-from-staging"
info "Merged PR #8 into production"
git branch -d update-production-from-staging
success "Updated production from staging!"
# Verify output for release body and production deploy comments
info "Checking output of getPullRequestsMergedBetween 1.0.1 1.0.3"
output=$(node "$getPullRequestsMergedBetween" '1.0.1' '1.0.3')
assert_equal "$output" "[ '7', '5', '1' ]"
success "Scenario #4A completed successfully!"
title "Scenario #4B: Run the staging deploy and create a new checklist"
info "Bumping version to 1.1.0 on main..."
git checkout main
git checkout -b version-bump
npm --no-git-tag-version version 1.1.0 -m "Update version to 1.1.0"
git add package.json package-lock.json
git commit -m "Update version to $(print_version)"
git checkout main
git merge version-bump --no-ff -m "Merge pull request #9 from Expensify/version-bump"
info "Merged PR #9 into main"
git branch -d version-bump
success "Successfully updated version to 1.1.0 on main!"
info "Updating staging from main..."
git checkout staging
git checkout -b update-staging-from-main
git merge --no-edit -Xtheirs main || { git diff --name-only --diff-filter=U | xargs git rm; git -c core.editor=true merge --continue; }
git checkout staging
git merge update-staging-from-main --no-ff -m "Merge pull request #10 from Expensify/update-staging-from-main"
info "Merged PR #10 into staging"
git branch -d update-staging-from-main
success "Successfully updated staging from main!"
info "Tagging new version on staging..."
git checkout staging
git tag "$(print_version)"
success "Successfully tagged version $(print_version) on staging"
# Verify output for new checklist and staging deploy comments
info "Checking output of getPullRequestsMergedBetween 1.0.3 1.1.0"
output=$(node "$getPullRequestsMergedBetween" '1.0.3' '1.1.0')
assert_equal "$output" "[ '4' ]"
success "Scenario #4B completed successfully!"
title "Scenario #5: Merging another pull request when the checklist is unlocked"
info "Creating PR #11 and merging it to main..."
git checkout main
git checkout -b pr-11
echo "Changes from PR #11" >> PR11.txt
git add PR11.txt
git commit -m "Changes from PR #11"
git checkout main
git merge pr-11 --no-ff -m "Merge pull request #11 from Expensify/pr-11"
info "Merged PR #11 into main"
git branch -d pr-11
success "Created PR #11 and merged it into main!"
info "Bumping version to 1.1.1 on main..."
git checkout main
git checkout -b version-bump
npm --no-git-tag-version version 1.1.1 -m "Update version to 1.1.1"
git add package.json package-lock.json
git commit -m "Update version to $(cat package.json | jq -r .version)"
git checkout main
git merge version-bump --no-ff -m "Merge pull request #12 from Expensify/version-bump"
info "Merged PR #12 into main"
git branch -d version-bump
success "Bumped version to 1.1.1 on main!"
info "Merging main into staging..."
git checkout staging
git checkout -b update-staging-from-main
git merge --no-edit -Xtheirs main || { git diff --name-only --diff-filter=U | xargs git rm; git -c core.editor=true merge --continue; }
git checkout staging
git merge update-staging-from-main --no-ff -m "Merge pull request #13 from Expensify/update-staging-from-main"
info "Merged PR #13 into staging"
git branch -d update-staging-from-main
success "Merged main into staging!"
info "Tagging staging..."
git checkout staging
git tag "$(print_version)"
success "Successfully tagged version $(print_version) on staging"
# Verify output for checklist
info "Checking output of getPullRequestsMergedBetween 1.0.3 1.1.1"
output=$(node "$getPullRequestsMergedBetween" '1.0.3' '1.1.1')
assert_equal "$output" "[ '11', '4' ]"
# Verify output for deploy comment
info "Checking output of getPullRequestsMergedBetween 1.1.0 1.1.1"
output=$(node "$getPullRequestsMergedBetween" '1.1.0' '1.1.1')
assert_equal "$output" "[ '11' ]"
success "Scenario #6 completed successfully!"
### Cleanup
title "Cleaning up..."
cd "$TEST_DIR" || exit 1
rm -rf "$DUMMY_DIR"
success "All tests passed! Hooray!"