Skip to content

Commit

Permalink
Merge pull request #250 from adangel/fix-artifact-upload
Browse files Browse the repository at this point in the history
Fix artifact upload, new parameter `uploadSarifReport`
  • Loading branch information
adangel authored Jan 18, 2024
2 parents 5361338 + 7d6d68f commit 318128d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ See also [Uploading a SARIF file to GitHub](https://docs.github.com/en/code-secu
|`rulesets` |yes| |Comma separated list of ruleset names to use.|
|`analyzeModifiedFilesOnly`|no|"true"|Instead of analyze all files under "sourcePath", only the files that have been touched in a pull request or push will be analyzed. This makes the analysis faster and helps especially bigger projects which gradually want to introduce PMD. This helps in enforcing that no new code violation is introduced.<br>Depending on the analyzed language, the results might be less accurate results. At the moment, this is not a problem, as PMD mostly analyzes each file individually, but that might change in the future.<br>If the change is very big, not all files might be analyzed. Currently the maximum number of modified files is 300.<br>Note: When using PMD as a code scanner in order to create "Code scanning alerts" on GitHub, all files should be analyzed in order to produce a complete picture of the project. Otherwise alerts might get closed too soon.|
|`createGitHubAnnotations`|no|"true"|By default, all detected violations are added as annotations to the pull request. You can disable this by setting FALSE. This can be useful if you are using another tool for this purpose.|
|`uploadSarifReport`|no|"true"|By default, the generated SARIF report will be uploaded as an artifact named "PMD Report". This can be disabled, e.g. if there are multiple executions on multiple os of this action.|

## Outputs

Expand Down
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ inputs:
are using another tool for this purpose.
required: false
default: 'true'
uploadSarifReport:
description: >-
By default, the generated SARIF report will be uploaded as an artifact
named "PMD Report". This can be disabled, e.g. if there are multiple
executions on multiple os of this action.
required: false
default: 'true'
outputs:
violations:
description: Number of violations found
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const core = require('@actions/core');
const artifact = require('@actions/artifact');
const {DefaultArtifactClient} = require('@actions/artifact');
const util = require('./util');
const sarif = require('./sarif');
const validator = require('./validator');
Expand Down Expand Up @@ -43,15 +43,17 @@ async function main() {
core.setOutput('violations', violations);
core.info(`PMD detected ${violations} violations.`);

if (core.getInput('createGitHubAnnotations', { required: true}) === 'true') {
if (core.getInput('createGitHubAnnotations', { required: false }) === 'true') {
const report = sarif.loadReport(reportFile);
annotations.processSarifReport(report);
}

const artifactClient = artifact.create();
await artifactClient.uploadArtifact('PMD Report', [reportFile], '.', {
continueOnError: false
});
if (core.getInput('uploadSarifReport', { required: false }) === 'true' ) {
const artifactName = 'PMD Report';
const artifactClient = new DefaultArtifactClient();
const {id, size} = await artifactClient.uploadArtifact('PMD Report', [reportFile], '.');
core.info(`Created artifact ${artifactName} with id: ${id} (bytes: ${size})`)
}
} catch (error) {
core.setFailed(error.message || error);
}
Expand Down

0 comments on commit 318128d

Please sign in to comment.