Skip to content

Commit

Permalink
Merge pull request #45 from paambaati/ccc-debug-support
Browse files Browse the repository at this point in the history
Debug support for the reporter
  • Loading branch information
paambaati authored Oct 31, 2019
2 parents 578f402 + 3a7d860 commit 488aa2d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ A GitHub action that publishes your code coverage to [Code Climate](http://codec
## Usage
This action requires that you set the [`CC_TEST_REPORTER_ID`](https://docs.codeclimate.com/docs/configuring-test-coverage) environment variable. You can find it under Repo Settings in your Code Climate project.

The default coverage command is `yarn coverage`. You can change it by setting the `coverageCommand` input value.
### Inputs

### Example
| Input | Default | Description |
|-------------------|-----------------|------------------------------------------------------------------------------------|
| `coverageCommand` | `yarn coverage` | The actual command that should be executed to run your tests and capture coverage. |
| `debug` | `false` | Enable Code Coverage debug output when set to `true`. |

#### Example

```yaml
steps:
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v2.2.6
uses: paambaati/codeclimate-action@v2.3.0
env:
CC_TEST_REPORTER_ID: <code_climate_reporter_id>
with:
coverageCommand: npm run coverage
debug: false
```
Example project — [paambaati/websight](https://github.com/paambaati/websight/blob/663bd4245b3c2dbd768aff9bfc197103ee77973e/.github/workflows/ci.yml#L33-L49)
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codeclimate-action",
"version": "2.2.6",
"version": "2.3.0",
"private": true,
"description": "Publish code coverage to Code Climate",
"main": "lib/main.js",
Expand Down
19 changes: 11 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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';
const DEFAULT_COVERAGE_COMMAND = 'yarn coverage';
const DEFAULT_CODECLIMATE_DEBUG = 'false';

export function downloadToFile(
url: string,
Expand Down Expand Up @@ -36,14 +37,16 @@ function prepareEnv() {
if (process.env.GITHUB_REF !== undefined)
env.GIT_BRANCH = process.env.GITHUB_REF;

env.GIT_BRANCH = env.GIT_BRANCH.replace(/^refs\/head\//, ''); // Remove 'refs/head/' prefix (See https://github.com/paambaati/codeclimate-action/issues/42)
if (env.GIT_BRANCH)
env.GIT_BRANCH = env.GIT_BRANCH.replace(/^refs\/head\//, ''); // Remove 'refs/head/' prefix (See https://github.com/paambaati/codeclimate-action/issues/42)
return env;
}

export function run(
downloadUrl: string = DOWNLOAD_URL,
executable: string = EXECUTABLE,
coverageCommand: string = DEFAULT_COVERAGE_COMMAND
coverageCommand: string = DEFAULT_COVERAGE_COMMAND,
codeClimateDebug: string = DEFAULT_CODECLIMATE_DEBUG
): Promise<void> {
return new Promise(async (resolve, reject) => {
let lastExitCode = 1;
Expand Down Expand Up @@ -79,11 +82,9 @@ export function run(
return reject(err);
}
try {
await exec(
executable,
['after-build', '--exit-code', lastExitCode.toString()],
execOpts
);
const commands = ['after-build', '--exit-code', lastExitCode.toString()];
if (codeClimateDebug === 'true') commands.push('--debug');
await exec(executable, commands, execOpts);
debug('✅ CC Reporter after-build checkin completed!');
return resolve();
} catch (err) {
Expand All @@ -97,5 +98,7 @@ export function run(
if (!module.parent) {
let coverageCommand = getInput('coverageCommand', { required: false });
if (!coverageCommand.length) coverageCommand = DEFAULT_COVERAGE_COMMAND;
run(DOWNLOAD_URL, EXECUTABLE, coverageCommand);
let codeClimateDebug = getInput('codeClimateDebug', { required: false });
if (!coverageCommand.length) codeClimateDebug = DEFAULT_CODECLIMATE_DEBUG;
run(DOWNLOAD_URL, EXECUTABLE, coverageCommand, codeClimateDebug);
}

0 comments on commit 488aa2d

Please sign in to comment.