diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-09-25 13:14:27 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-09-26 11:18:38 +0200 |
commit | 8875f009ce8360db142f1a55a97f13100d6e8267 (patch) | |
tree | c6dfb0508ef2ba0fc11310abbff7d0b66feb3881 | |
parent | cd01c29082500e67d446a42df7b01344b0995599 (diff) | |
download | qtlocation-mapboxgl-upstream/release-chai.tar.gz |
compare clang-tidy with merge base instead of masterupstream/release-chai
-rw-r--r-- | circle.yml | 14 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rwxr-xr-x | scripts/clang-tools.sh | 5 | ||||
-rwxr-xr-x | scripts/environment.js | 34 |
4 files changed, 49 insertions, 5 deletions
diff --git a/circle.yml b/circle.yml index de5a8ce74e..aa5200f9e7 100644 --- a/circle.yml +++ b/circle.yml @@ -66,6 +66,15 @@ workflows: only: /node-.*/ step-library: + - &npm-install + run: + name: npm install + command: npm install --ignore-scripts + - &prepare-environment + run: + name: Prepare environment + command: touch "$BASH_ENV" && ./scripts/environment.js | tee -a "$BASH_ENV" + - &generate-cache-key run: name: Generate cache key @@ -299,13 +308,12 @@ jobs: BUILDTYPE: Debug steps: - checkout + - *npm-install + - *prepare-environment - *generate-cache-key - *restore-cache - *reset-ccache-stats - run: - name: Fetch 'origin/master' branch - command: git fetch origin master:refs/remotes/origin/master - - run: name: Generate compilation database command: make compdb - *show-ccache-stats diff --git a/package.json b/package.json index b081539874..c5a2162488 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "npm-run-all": "^4.0.2" }, "devDependencies": { + "@octokit/rest": "^15.9.2", "aws-sdk": "^2.3.5", "csscolorparser": "^1.0.2", "ejs": "^2.4.1", diff --git a/scripts/clang-tools.sh b/scripts/clang-tools.sh index bdda4544b9..735c758d64 100755 --- a/scripts/clang-tools.sh +++ b/scripts/clang-tools.sh @@ -2,6 +2,7 @@ set -e set -o pipefail +set -u CLANG_TIDY_PREFIX=${CLANG_TIDY_PREFIX:-$(scripts/mason.sh PREFIX clang-tidy VERSION 4.0.1)} CLANG_TIDY=${CLANG_TIDY:-${CLANG_TIDY_PREFIX}/bin/clang-tidy} @@ -33,7 +34,7 @@ function run_clang_tidy() { } function run_clang_tidy_diff() { - OUTPUT=$(git diff origin/master --src-prefix=${CDUP} --dst-prefix=${CDUP} | \ + OUTPUT=$(git diff ${CIRCLE_MERGE_BASE} --src-prefix=${CDUP} --dst-prefix=${CDUP} | \ ${CLANG_TIDY_PREFIX}/share/clang-tidy-diff.py \ -clang-tidy-binary ${CLANG_TIDY} \ 2>/dev/null) @@ -45,7 +46,7 @@ function run_clang_tidy_diff() { function run_clang_format() { echo "Running clang-format on $0..." - DIFF_FILES=$(git diff origin/master --name-only *cpp) + DIFF_FILES=$(git diff ${CIRCLE_MERGE_BASE} --name-only *cpp) echo "${DIFF_FILES}" | xargs -I{} -P ${JOBS} bash -c 'run_clang_format' {} ${CLANG_FORMAT} -i ${CDUP}/$0 || exit 1 } diff --git a/scripts/environment.js b/scripts/environment.js new file mode 100755 index 0000000000..cb533a74a8 --- /dev/null +++ b/scripts/environment.js @@ -0,0 +1,34 @@ +#!/usr/bin/env node + +// Output some `export` commands with a few extra environment variables. They'll be evaluated +// into the build environment and available for use in later steps. + +const github = require('@octokit/rest')(); +const {execSync} = require('child_process'); + +const pr = process.env['CIRCLE_PULL_REQUEST']; +const head = process.env['CIRCLE_SHA1'] || 'HEAD'; +if (pr) { + const number = +pr.match(/\/(\d+)\/?$/)[1]; + return github.pullRequests.get({ + owner: 'mapbox', + repo: 'mapbox-gl-native', + number + }).then(({data}) => { + const base = data.base.ref; + const mergeBase = execSync(`git merge-base origin/${base} ${head}`).toString().trim(); + + console.log(`export CIRCLE_TARGET_BRANCH=${base}`); + console.log(`export CIRCLE_MERGE_BASE=${mergeBase}`); + }); +} else { + for (const sha of execSync(`git rev-list --max-count=10 ${head}`).toString().trim().split('\n')) { + const base = execSync(`git branch -r --contains ${sha} origin/master origin/release-*`).toString().split('\n')[0].trim().replace(/^origin\//, ''); + if (base.match(/^(master|release-[a-z]+)$/)) { + const mergeBase = execSync(`git merge-base origin/${base} ${head}`).toString().trim(); + console.log(`export CIRCLE_TARGET_BRANCH=${base}`); + console.log(`export CIRCLE_MERGE_BASE=${mergeBase}`); + break; + } + } +} |