summaryrefslogtreecommitdiff
path: root/scripts/environment.js
blob: b071a484e706b388ff72a2b7c844e4191e283e05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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}`);
    });
}