Skip to content

Commit

Permalink
ci,build: exit early if branch has an open PR
Browse files Browse the repository at this point in the history
The situation is a bit complicated.
Travis-CI allows us to enable/disable builds for PRs & and for pushed
branches/tags.

If we disable builds for PRs, we won't get any build-runs from external
forks (external contributions).

If we disable builds for branches, people won't get a chance to have the CI
do a check before opening up a PR.

If we enable both, each re-spin of a PR requires up to 2 hours to do both
builds.

A compromise solution, is to implement a check on our build-script to exit
early if we detect that for a branch/tag we have an open PR. It's not
perfect, but should reduce some time.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
  • Loading branch information
commodo committed Jan 17, 2020
1 parent bf0a22a commit 6af481d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/travis/run-build-docker.sh
Expand Up @@ -4,6 +4,7 @@ set -e
. ./ci/travis/lib.sh

ENV_VARS="BUILD_TYPE DEFCONFIG ARCH CROSS_COMPILE DTS_FILES IMAGE"
ENV_VARS="$ENV_VARS TRAVIS_COMMIT TRAVIS_PULL_REQUEST"

if [ "$DO_NOT_DOCKERIZE" = "1" ] ; then
. ./ci/travis/run-build.sh
Expand Down
36 changes: 36 additions & 0 deletions ci/travis/run-build.sh
Expand Up @@ -14,13 +14,49 @@ if [ -f "${FULL_BUILD_DIR}/env" ] ; then
. "${FULL_BUILD_DIR}/env"
fi

# allow this to be configurable; we may want to run it elsewhere
REPO_SLUG=${REPO_SLUG:-analogdevicesinc/linux}

# Run once for the entire script
sudo apt-get -qq update

apt_install() {
sudo apt-get install -y $@
}

get_pull_requests_urls() {
wget -q -O- https://api.github.com/repos/${REPO_SLUG}/pulls | jq -r '.[].commits_url'
}

get_pull_request_commits_sha() {
wget -q -O- $1 | jq -r '.[].sha'
}

branch_has_pull_request() {
if [ "$TRAVIS_PULL_REQUEST" = "true" ] ; then
return 1
fi
apt_install jq

for pr_url in $(get_pull_requests_urls) ; do
for sha in $(get_pull_request_commits_sha $pr_url) ; do
if [ "$sha" = "$TRAVIS_COMMIT" ] ; then
TRAVIS_OPEN_PR=$pr_url
export TRAVIS_OPEN_PR
return 0
fi
done
done

return 1
}

# Exit early to save some build time
if branch_has_pull_request ; then
echo_green "Not running build for branch; there is an open PR @ $TRAVIS_OPEN_PR"
exit 0
fi

if [ -z "$NUM_JOBS" ] ; then
NUM_JOBS=$(getconf _NPROCESSORS_ONLN)
NUM_JOBS=${NUM_JOBS:-1}
Expand Down

0 comments on commit 6af481d

Please sign in to comment.