Skip to content

Commit ba9a167

Browse files
authored
Merge 0841e3d into 32a411d
2 parents 32a411d + 0841e3d commit ba9a167

2 files changed

Lines changed: 67 additions & 4 deletions

File tree

.circleci/config.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,25 @@ executors:
3131
resource_class: xlarge
3232

3333
commands:
34+
save_merge_commit:
35+
steps:
36+
- save_cache:
37+
name: 'Save Merge Commit'
38+
key: git-{{ .Branch }}-{{ .Revision }}
39+
paths:
40+
- .git/FETCH_HEAD
41+
restore_merge_commit:
42+
steps:
43+
- restore_cache:
44+
name: 'Restore Merge Commit'
45+
key: git-{{ .Branch }}-{{ .Revision }}
3446
setup_vm:
3547
steps:
3648
- checkout
49+
- restore_merge_commit
3750
- run:
3851
name: 'Fetch Merge Commit'
39-
command: ./.circleci/fetch_merge_commit.sh
52+
command: ./.circleci/fetch_merge_commit.sh merge
4053
- run:
4154
name: 'Check Config'
4255
command: ./.circleci/check_config.sh
@@ -61,6 +74,15 @@ commands:
6174
command: ./.circleci/fail_fast.sh
6275

6376
jobs:
77+
'Setup ENV':
78+
executor:
79+
name: amphtml-medium-executor
80+
steps:
81+
- checkout
82+
- run:
83+
name: 'Fetch Merge Commit'
84+
command: ./.circleci/fetch_merge_commit.sh fetch
85+
- save_merge_commit
6486
'Checks':
6587
executor:
6688
name: amphtml-medium-executor
@@ -231,30 +253,47 @@ jobs:
231253
workflows:
232254
'CircleCI':
233255
jobs:
256+
- 'Setup ENV':
257+
<<: *push_and_pr_builds
234258
- 'Checks':
235259
<<: *push_and_pr_builds
260+
requires:
261+
- 'Setup ENV'
236262
- 'Unminified Build':
237263
<<: *push_and_pr_builds
264+
requires:
265+
- 'Setup ENV'
238266
- 'Nomodule Build':
239267
<<: *push_and_pr_builds
268+
requires:
269+
- 'Setup ENV'
240270
- 'Module Build':
241271
<<: *push_and_pr_builds
272+
requires:
273+
- 'Setup ENV'
242274
- 'Bundle Size':
243275
<<: *push_and_pr_builds
244276
requires:
277+
- 'Setup ENV'
245278
- 'Nomodule Build'
246279
- 'Module Build'
247280
- 'Validator Tests':
248281
<<: *push_and_pr_builds
282+
requires:
283+
- 'Setup ENV'
249284
- 'Visual Diff Tests':
250285
<<: *push_and_pr_builds
251286
requires:
287+
- 'Setup ENV'
252288
- 'Nomodule Build'
253289
- 'Unit Tests':
254290
<<: *push_and_pr_builds
291+
requires:
292+
- 'Setup ENV'
255293
- 'Unminified Tests':
256294
<<: *push_and_pr_builds
257295
requires:
296+
- 'Setup ENV'
258297
- 'Unminified Build'
259298
- 'Nomodule Tests':
260299
name: 'Nomodule Tests (<< matrix.config >>)'
@@ -263,6 +302,7 @@ workflows:
263302
config: ['prod', 'canary']
264303
<<: *push_and_pr_builds
265304
requires:
305+
- 'Setup ENV'
266306
- 'Nomodule Build'
267307
- 'Module Tests':
268308
name: 'Module Tests (<< matrix.config >>)'
@@ -271,28 +311,34 @@ workflows:
271311
config: ['prod', 'canary']
272312
<<: *push_and_pr_builds
273313
requires:
314+
- 'Setup ENV'
274315
- 'Nomodule Build'
275316
- 'Module Build'
276317
- 'End-to-End Tests':
277318
<<: *push_and_pr_builds
278319
requires:
320+
- 'Setup ENV'
279321
- 'Nomodule Build'
280322
- 'Experiment Build':
281323
name: 'Experiment << matrix.exp >> Build'
282324
matrix:
283325
parameters:
284326
exp: ['A', 'B', 'C']
285327
<<: *push_and_pr_builds
328+
requires:
329+
- 'Setup ENV'
286330
- 'Experiment Tests':
287331
name: 'Experiment << matrix.exp >> Tests'
288332
matrix:
289333
parameters:
290334
exp: ['A', 'B', 'C']
291335
<<: *push_and_pr_builds
292336
requires:
337+
- 'Setup ENV'
293338
- 'Experiment << matrix.exp >> Build'
294339
# TODO(wg-performance, #12128): This takes 30 mins and fails regularly.
295340
# - 'Performance Tests':
296341
# <<: *push_builds_only
297342
# requires:
343+
# - 'Setup ENV'
298344
# - 'Nomodule Build'

.circleci/fetch_merge_commit.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ GREEN() { echo -e "\n\033[0;32m$1\033[0m"; }
2525
YELLOW() { echo -e "\n\033[0;33m$1\033[0m"; }
2626
RED() { echo -e "\n\033[0;31m$1\033[0m"; }
2727

28+
if [[ -z "$1" ]]; then
29+
echo "Usage: fetch_merge_commit.sh [fetch | merge]"
30+
fi
31+
2832
# Push builds are only run against master and amp-release branches.
2933
if [[ "$CIRCLE_BRANCH" == "master" || "$CIRCLE_BRANCH" =~ ^amp-release-* ]]; then
3034
echo $(GREEN "Nothing to do because $CIRCLE_BRANCH is not a PR branch.")
@@ -53,12 +57,25 @@ if [[ -z "$PR_NUMBER" ]]; then
5357
exit 0
5458
fi
5559

60+
if [[ "$1" == "fetch" ]]; then
61+
MERGE_BRANCH="refs/pull/$PR_NUMBER/merge"
62+
echo $(GREEN "Fetching merge SHA from $MERGE_BRANCH...")
63+
64+
(set -x && git fetch origin "$MERGE_BRANCH") || err=$?
65+
if [[ "$err" -ne "0" ]]; then
66+
echo $(RED "Failed to fetch merge commit between $CIRCLE_BRANCH and master.")
67+
echo $(RED "Please rebase your PR branch.")
68+
exit $err
69+
fi
70+
exit 0
71+
fi
72+
5673
# GitHub provides refs/pull/<PR_NUMBER>/merge, an up-to-date merge branch for
5774
# every PR branch that can be cleanly merged to master. For more details, see:
5875
# https://discuss.circleci.com/t/show-test-results-for-prospective-merge-of-a-github-pr/1662
59-
MERGE_BRANCH="refs/pull/$PR_NUMBER/merge"
60-
echo $(GREEN "Fetching merge commit from $MERGE_BRANCH...")
61-
(set -x && git pull --ff-only origin "$MERGE_BRANCH") || err=$?
76+
MERGE_SHA="$(awk '{print $1}' .git/FETCH_HEAD)"
77+
echo $(GREEN "Fetching merge commit $MERGE_SHA...")
78+
(set -x && git pull --ff-only origin "$MERGE_SHA") || err=$?
6279

6380
# If a clean merge is not possible, do not proceed with the build. GitHub's UI
6481
# will show an error indicating there was a merge conflict.

0 commit comments

Comments
 (0)