Skip to content

Commit 79581ff

Browse files
committed
travis deduping on prs
closes #12438 Author: Jeff Reback <[email protected]> Closes #15780 from jreback/dedupe and squashes the following commits: 64f217e [Jeff Reback] replace . by space b6f2a62 [Jeff Reback] formatting 0c33d9b [Jeff Reback] tests commit 24f6ae6 [Jeff Reback] CI: fast finish travis builds for the same PR
1 parent fb7af6e commit 79581ff

File tree

3 files changed

+102
-21
lines changed

3 files changed

+102
-21
lines changed

.travis.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,14 @@ matrix:
177177
- USE_CACHE=true
178178

179179
before_install:
180+
- echo "Checking to see if this build is outdated"
181+
- ci/travis_fast_finish.py || { echo "Failing outdated build to end it."; exit 1; }
180182
- echo "before_install"
181183
- source ci/travis_process_gbq_encryption.sh
182-
- echo $VIRTUAL_ENV
183184
- export PATH="$HOME/miniconda3/bin:$PATH"
184185
- df -h
185-
- date
186186
- pwd
187187
- uname -a
188-
- python -V
189188
- git --version
190189
- git tag
191190
- ci/before_install_travis.sh

ci/install_travis.sh

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
#!/bin/bash
22

3-
# There are 2 distinct pieces that get zipped and cached
4-
# - The venv site-packages dir including the installed dependencies
5-
# - The pandas build artifacts, using the build cache support via
6-
# scripts/use_build_cache.py
7-
#
8-
# if the user opted in to use the cache and we're on a whitelisted fork
9-
# - if the server doesn't hold a cached version of venv/pandas build,
10-
# do things the slow way, and put the results on the cache server
11-
# for the next time.
12-
# - if the cache files are available, instal some necessaries via apt
13-
# (no compiling needed), then directly goto script and collect 200$.
14-
#
15-
3+
# edit the locale file if needed
164
function edit_init()
175
{
186
if [ -n "$LOCALE_OVERRIDE" ]; then
@@ -26,15 +14,18 @@ function edit_init()
2614
fi
2715
}
2816

17+
echo
2918
echo "[install_travis]"
3019
edit_init
3120

3221
home_dir=$(pwd)
33-
echo "[home_dir: $home_dir]"
22+
echo
23+
echo "[home_dir]: $home_dir"
3424

3525
# install miniconda
3626
MINICONDA_DIR="$HOME/miniconda3"
3727

28+
echo
3829
echo "[Using clean Miniconda install]"
3930

4031
if [ -d "$MINICONDA_DIR" ]; then
@@ -49,14 +40,17 @@ else
4940
fi
5041
time bash miniconda.sh -b -p "$MINICONDA_DIR" || exit 1
5142

43+
echo
5244
echo "[show conda]"
5345
which conda
5446

47+
echo
5548
echo "[update conda]"
5649
conda config --set ssl_verify false || exit 1
5750
conda config --set always_yes true --set changeps1 false || exit 1
5851
conda update -q conda
5952

53+
echo
6054
echo "[add channels]"
6155
# add the pandas channel to take priority
6256
# to add extra packages
@@ -73,26 +67,28 @@ fi
7367
conda info -a || exit 1
7468

7569
# set the compiler cache to work
70+
echo
7671
if [ "$USE_CACHE" ] && [ "${TRAVIS_OS_NAME}" == "linux" ]; then
7772
echo "[Using ccache]"
7873
export PATH=/usr/lib/ccache:/usr/lib64/ccache:$PATH
7974
gcc=$(which gcc)
80-
echo "[gcc: $gcc]"
75+
echo "[gcc]: $gcc"
8176
ccache=$(which ccache)
82-
echo "[ccache: $ccache]"
77+
echo "[ccache]: $ccache"
8378
export CC='ccache gcc'
8479
elif [ "$USE_CACHE" ] && [ "${TRAVIS_OS_NAME}" == "osx" ]; then
8580
echo "[Using ccache]"
8681
time brew install ccache
8782
export PATH=/usr/local/opt/ccache/libexec:$PATH
8883
gcc=$(which gcc)
89-
echo "[gcc: $gcc]"
84+
echo "[gcc]: $gcc"
9085
ccache=$(which ccache)
91-
echo "[ccache: $ccache]"
86+
echo "[ccache]: $ccache"
9287
else
9388
echo "[Not using ccache]"
9489
fi
9590

91+
echo
9692
echo "[create env]"
9793

9894
# may have installation instructions for this build
@@ -106,13 +102,15 @@ else
106102
fi
107103

108104
# build deps
105+
echo
109106
echo "[build installs]"
110107
REQ="ci/requirements-${PYTHON_VERSION}${JOB_TAG}.build"
111108
if [ -e ${REQ} ]; then
112109
time conda install -n pandas --file=${REQ} || exit 1
113110
fi
114111

115112
# may have addtl installation instructions for this build
113+
echo
116114
echo "[build addtl installs]"
117115
REQ="ci/requirements-${PYTHON_VERSION}${JOB_TAG}.build.sh"
118116
if [ -e ${REQ} ]; then
@@ -132,6 +130,7 @@ if [ "$COVERAGE" ]; then
132130
pip install coverage pytest-cov
133131
fi
134132

133+
echo
135134
if [ "$BUILD_TEST" ]; then
136135

137136
# build & install testing
@@ -151,20 +150,23 @@ else
151150
fi
152151

153152
# we may have run installations
153+
echo
154154
echo "[conda installs]"
155155
REQ="ci/requirements-${PYTHON_VERSION}${JOB_TAG}.run"
156156
if [ -e ${REQ} ]; then
157157
time conda install -n pandas --file=${REQ} || exit 1
158158
fi
159159

160160
# we may have additional pip installs
161+
echo
161162
echo "[pip installs]"
162163
REQ="ci/requirements-${PYTHON_VERSION}${JOB_TAG}.pip"
163164
if [ -e ${REQ} ]; then
164165
pip install -r $REQ
165166
fi
166167

167168
# may have addtl installation instructions for this build
169+
echo
168170
echo "[addtl installs]"
169171
REQ="ci/requirements-${PYTHON_VERSION}${JOB_TAG}.sh"
170172
if [ -e ${REQ} ]; then
@@ -176,14 +178,17 @@ if [ -z "$BUILD_TEST" ]; then
176178

177179
# remove any installed pandas package
178180
# w/o removing anything else
181+
echo
179182
echo "[removing installed pandas]"
180183
conda remove pandas --force
181184

182185
# install our pandas
186+
echo
183187
echo "[running setup.py develop]"
184188
python setup.py develop || exit 1
185189

186190
fi
187191

192+
echo
188193
echo "[done]"
189194
exit 0

ci/travis_fast_finish.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python
2+
3+
# script to cancel previous travis builds for the same PR
4+
# originally from
5+
# https://github.com/conda-forge/staged-recipes/pull/2257
6+
7+
try:
8+
from future_builtins import (
9+
map,
10+
filter,
11+
)
12+
except ImportError:
13+
pass
14+
15+
import codecs
16+
import contextlib
17+
import json
18+
import os
19+
20+
try:
21+
from urllib.request import (
22+
Request,
23+
urlopen,
24+
)
25+
except ImportError:
26+
from urllib2 import (
27+
Request,
28+
urlopen,
29+
)
30+
31+
32+
def check_latest_pr_build(repo, pr, build_num):
33+
# Not a PR so it is latest.
34+
if pr is None:
35+
return True
36+
37+
headers = {
38+
"Accept": "application/vnd.travis-ci.2+json",
39+
}
40+
url = "https://api.travis-ci.org/repos/{repo}/builds?event_type=pull_request"
41+
42+
request = Request(url.format(repo=repo), headers=headers)
43+
with contextlib.closing(urlopen(request)) as response:
44+
reader = codecs.getreader("utf-8")
45+
data = json.load(reader(response))
46+
47+
# Parse the response to get a list of build numbers for this PR.
48+
builds = data["builds"]
49+
pr_builds = filter(lambda b: b["pull_request_number"] == pr, builds)
50+
pr_build_nums = sorted(map(lambda b: int(b["number"]), pr_builds))
51+
52+
print("build_num: {}".format(build_num))
53+
print("pr_build_nums: {}".format(','.join([str(n) for n in pr_build_nums])))
54+
55+
# Check if our build number is the latest (largest)
56+
# out of all of the builds for this PR.
57+
if build_num < max(pr_build_nums):
58+
return False
59+
else:
60+
return True
61+
62+
63+
def main():
64+
repo = os.environ["TRAVIS_REPO_SLUG"]
65+
66+
pr = os.environ["TRAVIS_PULL_REQUEST"]
67+
pr = None if pr == "false" else int(pr)
68+
build_num = int(os.environ["TRAVIS_BUILD_NUMBER"])
69+
70+
print("checking for fast_finish: {}-{}-{}".format(repo, pr, build_num))
71+
72+
return int(check_latest_pr_build(repo, pr, build_num) is False)
73+
74+
75+
if __name__ == "__main__":
76+
import sys
77+
sys.exit(main())

0 commit comments

Comments
 (0)