add ciignore (#153)

Builds with changes only to files mentioned in `.ciignore` will fail on circleci at the `check_build_worthiness` step.
This commit is contained in:
Shahidh K Muhammed
2018-07-18 11:00:52 +05:30
committed by GitHub
parent 5985bf8e9e
commit 92935bed40
3 changed files with 68 additions and 4 deletions

7
.ciignore Normal file
View File

@@ -0,0 +1,7 @@
*.md
LICENSE
scripts/*
assets/*
.circleci/*
.ciignore
.gitignore

45
.circleci/ciignore.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Exit with error if diff with origin/master only contains files mentioned in
# .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]%/*}/../)"
if [[ ! -a "$ROOT/.ciignore" ]]; then
exit # If .ciignore doesn't exists, just quit this script
fi
changes="$(git diff-tree --no-commit-id --name-only -r origin/master..HEAD)"
echo "CHANGES FROM ORIGIN/MASTER:"
echo $changes
echo
# Load the patterns we want to skip into an array
mapfile -t blacklist < "$ROOT/.ciignore"
for i in "${blacklist[@]}"
do
# Remove the current pattern from the list of changes
changes=( ${changes[@]/$i/} )
if [[ ${#changes[@]} -eq 0 ]]; then
# If we've exhausted the list of changes before we've finished going
# through patterns, that's okay, just quit the loop
break
fi
done
if [[ ${#changes[@]} -gt 0 ]]; then
# If there's still changes left, then we have stuff to build, leave the commit alone.
echo "Files that are not ignored present in commits, need to build, succeed the job"
exit
fi
echo "Only ignored files are present in commits, no need to build, fail the job"
exit 1

View File

@@ -42,6 +42,17 @@ refs:
version: 2
jobs:
# check if this should be built or not, fails if
# changes only contains files in .ciignore
check_build_worthiness:
docker:
- image: hasura/graphql-engine-cli-builder:v0.2
working_directory: ~/graphql-engine
steps:
- checkout
- run:
name: check build worthiness
command: .circleci/ciignore.sh
# test build the server binary
test_and_build_server:
docker:
@@ -65,7 +76,6 @@ jobs:
name: test and build server binary
working_directory: ./server
command: |
# TODO: make test
DATABASE_URL="postgres://gql_test:@localhost:5432/gql_test" make ci-binary-and-test
make ci-image
make ci-save-image
@@ -156,7 +166,6 @@ jobs:
- ~/.npm
- ~/.cache
- *wait_for_postgres
# ignore console test for now
- run:
name: test console
command: .circleci/test-console.sh
@@ -193,7 +202,11 @@ workflows:
version: 2
build_and_test:
jobs:
- test_and_build_server: *filter_only_vtags
- check_build_worthiness: *filter_only_vtags
- test_and_build_server:
<<: *filter_only_vtags
requires:
- check_build_worthiness
- test_and_build_cli:
<<: *filter_only_vtags
requires:
@@ -201,7 +214,6 @@ workflows:
- test_and_build_console:
<<: *filter_only_vtags
requires:
- test_and_build_server
- test_and_build_cli
- deploy:
<<: *filter_only_vtags_dev_release_branches