Skip to content

Commit

Permalink
Merge pull request #747 from LaurentGoderre/implement-743
Browse files Browse the repository at this point in the history
Skip the images build when no images changed
  • Loading branch information
PeterDaveHello authored May 29, 2018
2 parents 9dc7c5b + bffff57 commit 40fd374
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ sudo: false

language: generic

services:
- docker
addons:
apt:
packages:
- docker-ce
before_install:
- source functions.sh && images_updated $TRAVIS_COMMIT_RANGE || tests_updated $TRAVIS_COMMIT_RANGE || travis_terminate

script: ./test-build.sh $NODE_VERSION $VARIANT

Expand Down
51 changes: 51 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,54 @@ function sort_versions() {

echo "${sorted[@]}"
}

function commit_range() {
local commit_id_end=${1}
shift
local commit_id_start=${1}

if [ -z "${commit_id_start}" ]; then
if [ -z "${commit_id_end}" ]; then
echo "HEAD~1..HEAD"
elif [[ "${commit_id_end}" =~ .. ]]; then
echo "${commit_id_end}"
else
echo "${commit_id_end}~1..${commit_id_end}"
fi
else
echo "${commit_id_end}..${commit_id_start}"
fi
}

function images_updated() {
local commit_range
local versions
local images_changed

commit_range="$(commit_range "$@")"

IFS=' ' read -ra versions <<<"$(
IFS=','
get_versions
)"
images_changed=$(git diff --name-only "${commit_range}" "${versions[@]}")

if [ -z "${images_changed}" ]; then
return 1
fi
return 0
}

function tests_updated() {
local commit_range
local test_changed

commit_range="$(commit_range "$@")"

test_changed=$(git diff --name-only "${commit_range}" test*)

if [ -z "${test_changed}" ]; then
return 1
fi
return 0
}
18 changes: 1 addition & 17 deletions generate-stackbrew-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ UPSTREAM_SLUG="docker-library/${REPO_NAME}"
DOCKER_SLUG="nodejs/docker-node"
gitpath="../${REPO_NAME}"

function updated() {
local versions
local images_changed

IFS=' ' read -ra versions <<<"$(
IFS=','
get_versions
)"
images_changed=$(git diff --name-only "${COMMIT_ID}".."${COMMIT_ID}"~1 "${versions[@]}")

if [ -z "${images_changed}" ]; then
return 1
fi
return 0
}

function auth_header() {
echo "Authorization: token ${GITHUB_API_TOKEN}"
}
Expand Down Expand Up @@ -104,7 +88,7 @@ function comment_payload() {
}"
}

if updated; then
if images_updated "${COMMIT_ID}"; then

permission_check

Expand Down
8 changes: 2 additions & 6 deletions travis.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ sudo: false

language: generic

services:
- docker
addons:
apt:
packages:
- docker-ce
before_install:
- source functions.sh && images_updated $TRAVIS_COMMIT_RANGE || tests_updated $TRAVIS_COMMIT_RANGE || travis_terminate

script: ./test-build.sh $NODE_VERSION $VARIANT

Expand Down

0 comments on commit 40fd374

Please sign in to comment.