Skip to content

Commit

Permalink
feat(core): add support for batch-size
Browse files Browse the repository at this point in the history
  • Loading branch information
paambaati committed Aug 21, 2024
2 parents 8a09d38 + 38a417d commit 3c144ec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ This action requires that you set the [`CC_TEST_REPORTER_ID`](https://docs.codec

### Inputs

| Input | Default | Description |
| ------------------- | --------------- | ---------------------------------------------------------------------------------- |
| `coverageCommand` | | The actual command that should be executed to run your tests and capture coverage. |
| `workingDirectory` | | Specify a custom working directory where the coverage command should be executed. |
| `debug` | `false` | Enable Code Coverage debug output when set to `true`. |
| `coverageLocations` | | Locations to find code coverage as a multiline string.<br>Each line should be of the form `<location>:<type>`.<br>`type` can be any one of `clover, cobertura, coverage.py, excoveralls, gcov, gocov, jacoco, lcov, lcov-json, simplecov, xccov`. See examples below. |
| `prefix` | `undefined` | See [`--prefix`](https://docs.codeclimate.com/docs/configuring-test-coverage) |
| `verifyDownload` | `true` | Verifies the downloaded Code Climate reporter binary's checksum and GPG signature. See [Verifying binaries](https://github.com/codeclimate/test-reporter#verifying-binaries) |
| `verifyEnvironment` | `true` | Verifies the current runtime environment (operating system and CPU architecture) is supported by the Code Climate reporter. See [list of supported platforms](https://github.com/codeclimate/test-reporter#binaries) |
| Input | Default | Description |
|---------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `coverageCommand` | | The actual command that should be executed to run your tests and capture coverage. |
| `workingDirectory` | | Specify a custom working directory where the coverage command should be executed. |
| `debug` | `false` | Enable Code Coverage debug output when set to `true`. |
| `coverageLocations` | | Locations to find code coverage as a multiline string.<br>Each line should be of the form `<location>:<type>`.<br>`type` can be any one of `clover, cobertura, coverage.py, excoveralls, gcov, gocov, jacoco, lcov, lcov-json, simplecov, xccov`. See examples below. |
| `prefix` | `undefined` | See [`--prefix`](https://docs.codeclimate.com/docs/configuring-test-coverage) |
| `verifyDownload` | `true` | Verifies the downloaded Code Climate reporter binary's checksum and GPG signature. See [Verifying binaries](https://github.com/codeclimate/test-reporter#verifying-binaries) |
| `verifyEnvironment` | `true` | Verifies the current runtime environment (operating system and CPU architecture) is supported by the Code Climate reporter. See [list of supported platforms](https://github.com/codeclimate/test-reporter#binaries) |
| `batchSize` | | Batch size for source files (cc-test-reporter upload-coverage uses 500 by default) |

> **Note**
> If you are a Ruby developer using [SimpleCov](https://github.com/simplecov-ruby/simplecov), other users have recommended installing an additional gem – `gem "simplecov_json_formatter"` – this gem fixes `json` error from the default `coverage/.resultset.json` output from SimpleCov.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ inputs:
required: false
description: 'Verify that the Action environment (OS and CPU architecture) is supported by Code Climate test reporter'
default: 'true'
batchSize:
required: false
description: 'Batch size for source files (cc-test-reporter upload-coverage uses 500 by default)'
default: ''
runs:
using: 'node20'
main: 'lib/main.mjs'
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface ActionArguments {
verifyDownload?: string;
/** Verifies if the current OS and CPU architecture is supported by CodeClimate test reporter. */
verifyEnvironment?: string;
/** Batch size for source files used by upload-coverage command (default 500) */
batchSize?: string;
}

const CURRENT_ENVIRONMENT = getSupportedEnvironmentInfo();
Expand Down Expand Up @@ -209,6 +211,7 @@ export async function run({
coveragePrefix,
verifyDownload = DEFAULT_VERIFY_DOWNLOAD,
verifyEnvironment = DEFAULT_VERIFY_ENVIRONMENT,
batchSize,
}: ActionArguments = {}): Promise<void> {
let lastExitCode = 1;
if (verifyEnvironment === 'true') {
Expand Down Expand Up @@ -368,6 +371,9 @@ export async function run({
// Upload to Code Climate.
const uploadCommands = ['upload-coverage', '-i', 'coverage.total.json'];
if (codeClimateDebug === 'true') uploadCommands.push('--debug');
if (batchSize) {
uploadCommands.push('--batch-size', batchSize);
}
try {
lastExitCode = await exec(executable, uploadCommands, execOpts);
if (lastExitCode !== 0) {
Expand Down Expand Up @@ -432,6 +438,7 @@ if (isThisFileBeingRunViaCLI) {
'verifyEnvironment',
DEFAULT_VERIFY_ENVIRONMENT,
);
const batchSize = getOptionalString('batchSize');

try {
run({
Expand All @@ -444,6 +451,7 @@ if (isThisFileBeingRunViaCLI) {
coveragePrefix,
verifyDownload,
verifyEnvironment,
batchSize,
});
} finally {
// Finally clean up all artifacts that we downloaded.
Expand Down
1 change: 1 addition & 0 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ t.test('🧪 run() should run the CC reporter (happy path).', async (t) => {
coverageCommand: `${ECHO_CMD} 'coverage ok'`,
verifyDownload: 'false',
verifyEnvironment: 'false',
batchSize: '200',
});
stdHook.unhook();
} catch (err) {
Expand Down

0 comments on commit 3c144ec

Please sign in to comment.