From fd0b392c8b5e0867010965cac769d69744a36ccb Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 6 Apr 2017 22:44:56 -0700 Subject: [PATCH 1/3] Introduce GITHUB_DEFAULT_BRANCH environment var to fix diff checking on branch builds --- check-diff.sh | 20 +++++++++++--------- readme.md | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/check-diff.sh b/check-diff.sh index 07d6b57..944da2c 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -56,18 +56,20 @@ function set_environment_variables { CHECK_SCOPE=${CHECK_SCOPE:-patches} # 'all', 'changed-files', 'patches' if [ "$TRAVIS" == true ]; then + GITHUB_DEFAULT_BRANCH=${GITHUB_DEFAULT_BRANCH:-master} if [[ "$TRAVIS_PULL_REQUEST" != 'false' ]]; then - - # Make sure the remote branch is fetched. - if [[ -z "$DIFF_BASE" ]] && ! git rev-parse --verify --quiet "$TRAVIS_BRANCH"; then - git fetch origin "$TRAVIS_BRANCH" - git branch "$TRAVIS_BRANCH" FETCH_HEAD - fi - - DIFF_BASE=${DIFF_BASE:-$TRAVIS_BRANCH} + DIFF_BASE_BRANCH=$TRAVIS_BRANCH else - DIFF_BASE=${DIFF_BASE:-$TRAVIS_COMMIT^} + DIFF_BASE_BRANCH=$GITHUB_DEFAULT_BRANCH fi + + # Make sure the remote branch is fetched. + if [[ -z "$DIFF_BASE" ]] && ! git rev-parse --verify --quiet "$DIFF_BASE_BRANCH" > /dev/null; then + git fetch origin "$DIFF_BASE_BRANCH" + git branch "$DIFF_BASE_BRANCH" FETCH_HEAD + fi + + DIFF_BASE=${DIFF_BASE:-$DIFF_BASE_BRANCH} DIFF_HEAD=${DIFF_HEAD:-$TRAVIS_COMMIT} else DIFF_BASE=${DIFF_BASE:-HEAD} diff --git a/readme.md b/readme.md index 37151b3..1846580 100644 --- a/readme.md +++ b/readme.md @@ -128,6 +128,7 @@ You may customize the behavior of the `.travis.yml` and `pre-commit` hook by specifying a `.dev-lib` (formerly `.ci-env.sh`) Bash script in the root of the repo, for example: ```bash +GITHUB_DEFAULT_BRANCH=develop PHPCS_GITHUB_SRC=xwp/PHP_CodeSniffer PHPCS_GIT_TREE=phpcs-patch PHPCS_IGNORE='tests/*,includes/vendor/*' # See also PATH_INCLUDES below @@ -139,7 +140,7 @@ PATH_INCLUDES="docroot/wp-content/plugins/acme-* docroot/wp-content/themes/acme- CHECK_SCOPE=patches ``` -The `PATH_INCLUDES` is especially useful when the dev-lib is used in the context of an entire site, so you can target just the themes and plugins that you're responsible for. For *excludes*, you can specify a `PHPCS_IGNORE` var and override the `.jshintignore` (it would be better to have a `PATH_EXCLUDES` as well). +Set `GITHUB_DEFAULT_BRANCH` to be whatever your default branch is in GitHub; this is use when doing diff-checks on changes in a branch build on Travis CI. The `PATH_INCLUDES` is especially useful when the dev-lib is used in the context of an entire site, so you can target just the themes and plugins that you're responsible for. For *excludes*, you can specify a `PHPCS_IGNORE` var and override the `.jshintignore`; there is a `PATH_EXCLUDES_PATTERN` as well. ## Pre-commit tips From 6b55025a7b3cd66ae6aca860ea485077aa834076 Mon Sep 17 00:00:00 2001 From: Derek Herman Date: Thu, 10 Aug 2017 11:56:11 -0700 Subject: [PATCH 2/3] Ensure base branch env variable is CI agnostic --- check-diff.sh | 4 ++-- readme.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/check-diff.sh b/check-diff.sh index 944da2c..48dd212 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -56,11 +56,11 @@ function set_environment_variables { CHECK_SCOPE=${CHECK_SCOPE:-patches} # 'all', 'changed-files', 'patches' if [ "$TRAVIS" == true ]; then - GITHUB_DEFAULT_BRANCH=${GITHUB_DEFAULT_BRANCH:-master} + DEFAULT_BASE_BRANCH=${DEFAULT_BASE_BRANCH:-master} if [[ "$TRAVIS_PULL_REQUEST" != 'false' ]]; then DIFF_BASE_BRANCH=$TRAVIS_BRANCH else - DIFF_BASE_BRANCH=$GITHUB_DEFAULT_BRANCH + DIFF_BASE_BRANCH=$DEFAULT_BASE_BRANCH fi # Make sure the remote branch is fetched. diff --git a/readme.md b/readme.md index 1846580..fa3e4a1 100644 --- a/readme.md +++ b/readme.md @@ -128,7 +128,7 @@ You may customize the behavior of the `.travis.yml` and `pre-commit` hook by specifying a `.dev-lib` (formerly `.ci-env.sh`) Bash script in the root of the repo, for example: ```bash -GITHUB_DEFAULT_BRANCH=develop +DEFAULT_BASE_BRANCH=develop PHPCS_GITHUB_SRC=xwp/PHP_CodeSniffer PHPCS_GIT_TREE=phpcs-patch PHPCS_IGNORE='tests/*,includes/vendor/*' # See also PATH_INCLUDES below @@ -140,7 +140,7 @@ PATH_INCLUDES="docroot/wp-content/plugins/acme-* docroot/wp-content/themes/acme- CHECK_SCOPE=patches ``` -Set `GITHUB_DEFAULT_BRANCH` to be whatever your default branch is in GitHub; this is use when doing diff-checks on changes in a branch build on Travis CI. The `PATH_INCLUDES` is especially useful when the dev-lib is used in the context of an entire site, so you can target just the themes and plugins that you're responsible for. For *excludes*, you can specify a `PHPCS_IGNORE` var and override the `.jshintignore`; there is a `PATH_EXCLUDES_PATTERN` as well. +Set `DEFAULT_BASE_BRANCH` to be whatever your default branch is in GitHub; this is use when doing diff-checks on changes in a branch build on Travis CI. The `PATH_INCLUDES` is especially useful when the dev-lib is used in the context of an entire site, so you can target just the themes and plugins that you're responsible for. For *excludes*, you can specify a `PHPCS_IGNORE` var and override the `.jshintignore`; there is a `PATH_EXCLUDES_PATTERN` as well. ## Pre-commit tips From bda6546bee8c90e59e6fedcfd8286f16d75e3126 Mon Sep 17 00:00:00 2001 From: Derek Herman Date: Thu, 10 Aug 2017 11:59:11 -0700 Subject: [PATCH 3/3] Move env variable out of conditional --- check-diff.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check-diff.sh b/check-diff.sh index 48dd212..06697d0 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -36,6 +36,7 @@ function set_environment_variables { PROJECT_SLUG=${PROJECT_SLUG:-$( basename "$PROJECT_DIR" | sed 's/^wp-//' )} PATH_INCLUDES=${PATH_INCLUDES:-./} PATH_EXCLUDES_PATTERN=${PATH_EXCLUDES_PATTERN:-'^(.*/)?(vendor|bower_components|node_modules)/.*'} + DEFAULT_BASE_BRANCH=${DEFAULT_BASE_BRANCH:-master} if [ -z "$PROJECT_TYPE" ]; then if [ -e style.css ]; then @@ -56,7 +57,6 @@ function set_environment_variables { CHECK_SCOPE=${CHECK_SCOPE:-patches} # 'all', 'changed-files', 'patches' if [ "$TRAVIS" == true ]; then - DEFAULT_BASE_BRANCH=${DEFAULT_BASE_BRANCH:-master} if [[ "$TRAVIS_PULL_REQUEST" != 'false' ]]; then DIFF_BASE_BRANCH=$TRAVIS_BRANCH else