8000 BLD: Use GitHub's merge refs to test PRs on CircleCI · scikit-learn/scikit-learn@adc2b67 · GitHub
[go: up one dir, main page]

Skip to content

Commit adc2b67

Browse files
committed
BLD: Use GitHub's merge refs to test PRs on CircleCI
Unlike other CIs, CircleCI does not test the merge commit of a PR with its base branch. Instead it tests the PR's head commit. The problem with this is the PR's status could differ when it is merged with the base branch. For instance, if one needs changes in the base branch to get their PR to pass, they must rebase/merge to get them into the history the PR. This normally isn't a problem, but sometimes things do go wrong when doing this merge/rebase, which adds a new unneeded difficulty. Alternatively, a passing PR could turn out to fail when merged into the base branch because some new content in the base branch was not tested against in the PR. To solve these issues, we checkout the merge ref for a PR (if it is a PR) from GitHub. However, it should be noted that the merge ref can be out-of-date in some cases w.r.t. the base branch. Still this is the commonly used strategy on Travis CI and AppVeyor. If we had enough info, we could ideally terminate a build that has merge conflicts. Unfortunately it doesn't seem that CircleCI gives us this info.
1 parent bddda7b commit adc2b67

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
4+
# Add `master` branch to the update list.
5+
# Otherwise CircleCI will give us a cached one.
6+
FETCH_REFS="+master:master"
7+
8+
# Update PR refs for testing.
9+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
10+
then
11+
FETCH_REFS="${FETCH_REFS} +refs/pull/${CIRCLE_PR_NUMBER}/head:pr/${CIRCLE_PR_NUMBER}/head"
12+
FETCH_REFS="${FETCH_REFS} +refs/pull/${CIRCLE_PR_NUMBER}/merge:pr/${CIRCLE_PR_NUMBER}/merge"
13+
fi
14+
15+
# Retrieve the refs.
16+
git fetch -u origin ${FETCH_REFS}
17+
18+
# Checkout the PR merge ref.
19+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
20+
then
21+
git checkout -qf "pr/${CIRCLE_PR_NUMBER}/merge"
22+
fi
23+
24+
# Check for merge conflicts.
25+
if [[ -n "${CIRCLE_PR_NUMBER}" ]]
26+
then
27+
git branch --merged | grep master > /dev/null
28+
git branch --merged | grep "pr/${CIRCLE_PR_NUMBER}/head" > /dev/null
29+
fi

circle.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
checkout:
2+
post:
3+
- ./build_tools/circle/checkout_merge_commit.sh
4+
15
dependencies:
26
cache_directories:
37
- "~/scikit_learn_data"

0 commit comments

Comments
 (0)
0