diff --git a/.ciignore b/.ciignore new file mode 100644 index 0000000000000..7e2a869d6b4b7 --- /dev/null +++ b/.ciignore @@ -0,0 +1,7 @@ +*.md +LICENSE +scripts/* +assets/* +.circleci/* +.ciignore +.gitignore diff --git a/.circleci/ciignore.sh b/.circleci/ciignore.sh new file mode 100755 index 0000000000000..a09b3ba42f975 --- /dev/null +++ b/.circleci/ciignore.sh @@ -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 diff --git a/.circleci/config.yml b/.circleci/config.yml index b74499ce22f5d..e05db13686ae7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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