Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject GIT_BRANCH and GIT_COMMIT_SHA in env #3

Merged
merged 3 commits into from
Aug 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createWriteStream } from 'fs';
import fetch from 'node-fetch';
import { debug, error, setFailed, getInput } from '@actions/core';
import { exec } from '@actions/exec';
import { ExecOptions } from '@actions/exec/lib/interfaces';

const DOWNLOAD_URL = `https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${platform()}-amd64`;
const EXECUTABLE = './cc-reporter';
Expand All @@ -27,6 +28,17 @@ export function downloadToFile(
});
}

function prepareEnv() {
const env = process.env as { [key: string]: string };

if (process.env.GITHUB_SHA !== undefined)
env.GIT_COMMIT_SHA = process.env.GITHUB_SHA;
if (process.env.GITHUB_REF !== undefined)
env.GIT_BRANCH = process.env.GITHUB_REF;

return env;
}

export function run(
downloadUrl: string = DOWNLOAD_URL,
executable: string = EXECUTABLE,
Expand All @@ -43,16 +55,19 @@ export function run(
setFailed('🚨 CC Reporter download failed!');
return reject(err);
}
const execOpts: ExecOptions = {
env: prepareEnv()
};
try {
lastExitCode = await exec(executable, ['before-build']);
lastExitCode = await exec(executable, ['before-build'], execOpts);
debug('✅ CC Reporter before-build checkin completed...');
} catch (err) {
error(err);
setFailed('🚨 CC Reporter before-build checkin failed!');
return reject(err);
}
try {
lastExitCode = await exec(coverageCommand);
lastExitCode = await exec(coverageCommand, undefined, execOpts);
if (lastExitCode !== 0) {
throw new Error(`Coverage run exited with code ${lastExitCode}`);
}
Expand All @@ -63,11 +78,11 @@ export function run(
return reject(err);
}
try {
await exec(executable, [
'after-build',
'--exit-code',
lastExitCode.toString()
]);
await exec(
executable,
['after-build', '--exit-code', lastExitCode.toString()],
execOpts
);
debug('✅ CC Reporter after-build checkin completed!');
return resolve();
} catch (err) {
Expand Down