From b5a955359969fd6ff337f0b425b3c229ee8e2319 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 30 Apr 2019 16:47:56 -0500 Subject: [PATCH] ci: revise azure pipelines config to report branch and service name to coveralls --- azure-pipelines.yml | 10 ++++++++++ scripts/coveralls-branch-name.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 scripts/coveralls-branch-name.js diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d86ef96c8..c38351bd0 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -85,6 +85,14 @@ steps: yarn config set cache-folder "${PWD}/Yarn" &>/dev/null popd &>/dev/null npm run ci:full + if [[ "$AGENT_OS" = "Linux" ]]; then + OS="Linux" + fi + if [[ "$AGENT_OS" = "Darwin" ]]; then + OS="macOS" + fi + export COVERALLS_GIT_BRANCH=$(node scripts/coveralls-branch-name) + export COVERALLS_SERVICE_NAME="Azure Pipelines (${OS})" npm run coveralls condition: ne( variables['Agent.OS'], 'Windows_NT' ) displayName: 'Test (*nix)' @@ -97,6 +105,8 @@ steps: yarn config set cache-folder "$($PWD.Path)\Yarn" | out-null popd npm run ci:full + $env:COVERALLS_GIT_BRANCH=node scripts/coveralls-branch-name + $env:COVERALLS_SERVICE_NAME="Azure Pipelines (Windows)" npm run coveralls condition: eq( variables['Agent.OS'], 'Windows_NT' ) displayName: 'Test (Windows)' diff --git a/scripts/coveralls-branch-name.js b/scripts/coveralls-branch-name.js new file mode 100644 index 000000000..25c2787fc --- /dev/null +++ b/scripts/coveralls-branch-name.js @@ -0,0 +1,17 @@ +/* global process require */ + +const {execSync} = require('child_process'); + +const nameRevCmd = 'git name-rev --name-only HEAD'; +let branchName = execSync(nameRevCmd).toString().trim(); + +if (branchName.startsWith('remotes/pull')) { + execSync('git checkout "HEAD^2"', {stdio: 'ignore'}); + const _branchName = branchName; + branchName = execSync(nameRevCmd).toString().trim().split('/').slice(2).join('/'); + execSync(`git checkout ${_branchName}`, {stdio: 'ignore'}); +} else if (branchName.startsWith('remotes/origin')) { + branchName = branchName.split('/').slice(2).join('/'); +} + +process.stdout.write(branchName);