diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-05 13:08:28 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-13 11:50:39 -0700 |
commit | 74ef93ab4f5e88d2d111d6400bc8d80642075544 (patch) | |
tree | 8619a34288a358b9a8f3e5908648bb7be1fc5c88 /scripts | |
parent | 3896a65c8e8c5a49981b2e4776310ee24baa6997 (diff) | |
download | qtlocation-mapboxgl-74ef93ab4f5e88d2d111d6400bc8d80642075544.tar.gz |
[build] Improve ccache freshness
Save a fresh ccache on every build by including (a checksum of) the current revision in the cache key. In the worst case, saving the cache appears to take ~1:30 for android-release; other builds appear to take a small amount of time compared to the time saved by having a fresh cache, versus a cache that's up to a week old.
Restore caches in the following priority order (all scoped to current architecture and job):
1. The cache for the current branch and revision.
2. If that doesn't exist, the most recent cache for the current branch.
3. If that doesn't exist, the cache for the parent branch and merge base, where "parent branch" means the base branch of the pull request specified by $CIRCLE_PULL_REQUEST (obtained from the GitHub API), and "merge base" means the revision returned by `git merge-base` when given the parent branch and $CIRCLE_BRANCH (obtained by executing that shell command). The intent here is to start a newly created branch off with the most relevant cache from its parent branch.
4. If that doesn't exist, the most recent cache for the parent branch.
5. If that doesn't exist, the most recent cache for master.
6. If that doesn't exist, use the most recent cache for any build.
We cannot use the branch names or revisions themselves as key segments, because CircleCI lacks a way to interpolate arbitrary environment variables into the cache key name. Instead, we write the desired value into a file and use the `{{ checksum "filename" }}` syntax.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/environment.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/environment.js b/scripts/environment.js new file mode 100755 index 0000000000..b071a484e7 --- /dev/null +++ b/scripts/environment.js @@ -0,0 +1,24 @@ +#!/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']; +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 head = process.env['CIRCLE_SHA1']; + 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}`); + }); +} |