2018-07-18 08:30:52 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-12-07 10:44:30 +03:00
|
|
|
# Exit with error if diff with origin/master only contains files mentioned in
|
2018-07-18 08:30:52 +03:00
|
|
|
# .ciignore so that the build can be stopped.
|
|
|
|
#
|
|
|
|
# Adapted from:
|
|
|
|
# https://circleci.com/blog/circleci-hacks-automate-the-decision-to-skip-builds-using-a-git-hook/
|
|
|
|
# https://github.com/dollarshaveclub/harmless-changes/blob/master/index.sh
|
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
ROOT="$(readlink -f ${BASH_SOURCE[0]%/*}/../)"
|
|
|
|
|
2019-03-07 08:58:03 +03:00
|
|
|
# make build directory
|
|
|
|
mkdir -p /build/ciignore
|
2018-12-04 08:03:20 +03:00
|
|
|
|
2018-07-20 23:08:16 +03:00
|
|
|
# always build tagged builds
|
|
|
|
if [[ ! -z "$CIRCLE_TAG" ]]; then
|
|
|
|
echo "Skipping check for tags"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2019-03-07 19:17:27 +03:00
|
|
|
# always build release branch
|
|
|
|
if [[ "$CIRCLE_BRANCH" = "release-"* ]]; then
|
|
|
|
echo "Skipping check for release branch"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2019-03-07 15:18:06 +03:00
|
|
|
# get the diff
|
2018-07-18 08:46:52 +03:00
|
|
|
if [[ ! -z "$CIRCLE_COMPARE_URL" ]]; then
|
|
|
|
# CIRCLE_COMPARE_URL is not empty, use it to get the diff
|
2018-08-06 17:06:48 +03:00
|
|
|
if [[ $CIRCLE_COMPARE_URL = *"commit"* ]]; then
|
|
|
|
COMMIT_RANGE=$(echo $CIRCLE_COMPARE_URL | sed 's:^.*/commit/::g')~1
|
|
|
|
else
|
|
|
|
COMMIT_RANGE=$(echo $CIRCLE_COMPARE_URL | sed 's:^.*/compare/::g')
|
|
|
|
fi
|
2018-07-18 08:46:52 +03:00
|
|
|
echo "Diff: $COMMIT_RANGE"
|
2020-03-29 09:31:30 +03:00
|
|
|
changes="$(git diff $COMMIT_RANGE --name-only -- . ':!scripts' ':!assets' ':!docs' ':!community' ':!install-manifests' ':!github' ':!*.md' ':!.ciignore' ':!.gitignore' ':!LICENSE' ':!.github')"
|
2020-12-07 10:44:30 +03:00
|
|
|
elif [[ "$CIRCLE_BRANCH" == "master" ]]; then
|
|
|
|
# CIRCLE_COMPARE_URL is not set, but branch is master, diff with last commit
|
2019-03-07 15:18:06 +03:00
|
|
|
echo "Diff: HEAD~1"
|
2020-03-29 09:31:30 +03:00
|
|
|
changes="$(git diff HEAD~1 --name-only -- . ':!scripts' ':!assets' ':!docs' ':!community' ':!install-manifests' ':!github' ':!*.md' ':!.ciignore' ':!.gitignore' ':!LICENSE' ':!.github')"
|
2018-07-18 08:46:52 +03:00
|
|
|
else
|
2020-12-07 10:44:30 +03:00
|
|
|
# CIRCLE_COMPARE_URL is not set, branch is not master, diff with origin/master
|
|
|
|
echo "Diff: origin/master..HEAD"
|
|
|
|
changes="$(git diff-tree --no-commit-id --name-only -r origin/master..HEAD -- . ':!scripts' ':!assets' ':!docs' ':!community' ':!install-manifests' ':!github' ':!*.md' ':!.ciignore' ':!.gitignore' ':!LICENSE' ':!.github')"
|
2018-07-18 08:46:52 +03:00
|
|
|
fi
|
2018-07-18 08:30:52 +03:00
|
|
|
|
2018-07-18 08:46:52 +03:00
|
|
|
echo "Changes in this build:"
|
2018-07-18 08:30:52 +03:00
|
|
|
echo $changes
|
|
|
|
echo
|
|
|
|
|
2020-03-13 11:25:47 +03:00
|
|
|
if [[ ! -z "$changes" ]]; then
|
|
|
|
# If there's still changes left, then we have stuff to build, leave the commit alone.
|
2018-07-18 08:30:52 +03:00
|
|
|
echo "Files that are not ignored present in commits, need to build, succeed the job"
|
2020-03-13 11:25:47 +03:00
|
|
|
exit
|
2018-07-18 08:30:52 +03:00
|
|
|
fi
|
|
|
|
|
2019-03-07 08:58:03 +03:00
|
|
|
echo "Only ignored files are present in commits, build is not required, write the skip_job file"
|
|
|
|
echo "true" > /build/ciignore/skip_job.txt
|
2020-12-07 10:44:30 +03:00
|
|
|
exit
|