Skip to content

Commit 318128d

Browse files
authored
Merge pull request #250 from adangel/fix-artifact-upload
Fix artifact upload, new parameter `uploadSarifReport`
2 parents 5361338 + 7d6d68f commit 318128d

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ See also [Uploading a SARIF file to GitHub](https://docs.github.com/en/code-secu
8383
|`rulesets` |yes| |Comma separated list of ruleset names to use.|
8484
|`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.|
8585
|`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.|
86+
|`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.|
8687

8788
## Outputs
8889

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ inputs:
8282
are using another tool for this purpose.
8383
required: false
8484
default: 'true'
85+
uploadSarifReport:
86+
description: >-
87+
By default, the generated SARIF report will be uploaded as an artifact
88+
named "PMD Report". This can be disabled, e.g. if there are multiple
89+
executions on multiple os of this action.
90+
required: false
91+
default: 'true'
8592
outputs:
8693
violations:
8794
description: Number of violations found

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const core = require('@actions/core');
2-
const artifact = require('@actions/artifact');
2+
const {DefaultArtifactClient} = require('@actions/artifact');
33
const util = require('./util');
44
const sarif = require('./sarif');
55
const validator = require('./validator');
@@ -43,15 +43,17 @@ async function main() {
4343
core.setOutput('violations', violations);
4444
core.info(`PMD detected ${violations} violations.`);
4545

46-
if (core.getInput('createGitHubAnnotations', { required: true}) === 'true') {
46+
if (core.getInput('createGitHubAnnotations', { required: false }) === 'true') {
4747
const report = sarif.loadReport(reportFile);
4848
annotations.processSarifReport(report);
4949
}
5050

51-
const artifactClient = artifact.create();
52-
await artifactClient.uploadArtifact('PMD Report', [reportFile], '.', {
53-
continueOnError: false
54-
});
51+
if (core.getInput('uploadSarifReport', { required: false }) === 'true' ) {
52+
const artifactName = 'PMD Report';
53+
const artifactClient = new DefaultArtifactClient();
54+
const {id, size} = await artifactClient.uploadArtifact('PMD Report', [reportFile], '.');
55+
core.info(`Created artifact ${artifactName} with id: ${id} (bytes: ${size})`)
56+
}
5557
} catch (error) {
5658
core.setFailed(error.message || error);
5759
}

0 commit comments

Comments
 (0)