Skip to content

Commit 255364f

Browse files
committed
Avoid using deprecated CLI options for PMD >= 6.41.0
With PMD 6.41.0 GNU style long options (`--`) have been introduced for all parameters. In this action, we currently use `-no-cache` which leads to unnecessary deprecation warnings. This PR add semver and uses this also to validate the version (validator.js).
1 parent 946ac27 commit 255364f

File tree

12 files changed

+141
-47
lines changed

12 files changed

+141
-47
lines changed

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
734734
THE SOFTWARE.
735735

736736

737+
lru-cache
738+
ISC
739+
The ISC License
740+
741+
Copyright (c) Isaac Z. Schlueter and Contributors
742+
743+
Permission to use, copy, modify, and/or distribute this software for any
744+
purpose with or without fee is hereby granted, provided that the above
745+
copyright notice and this permission notice appear in all copies.
746+
747+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
748+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
749+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
750+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
751+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
752+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
753+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
754+
755+
737756
minimatch
738757
ISC
739758
The ISC License
@@ -1011,3 +1030,22 @@ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
10111030
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
10121031
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
10131032
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1033+
1034+
1035+
yallist
1036+
ISC
1037+
The ISC License
1038+
1039+
Copyright (c) Isaac Z. Schlueter and Contributors
1040+
1041+
Permission to use, copy, modify, and/or distribute this software for any
1042+
purpose with or without fee is hereby granted, provided that the above
1043+
copyright notice and this permission notice appear in all copies.
1044+
1045+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1046+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1047+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1048+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1049+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1050+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1051+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

lib/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ const validator = require('../lib/validator');
77
const reportFormat = 'sarif';
88
const reportFile = 'pmd-report.sarif'
99

10-
let pmdPath, exitCode, violations;
11-
1210
async function run() {
11+
let pmdInfo, execOutput, violations;
1312
try {
14-
pmdPath = await util.downloadPmd(validator.validateVersion(core.getInput('version'), { required: true }));
15-
exitCode = await util.executePmd(pmdPath,
13+
pmdInfo = await util.downloadPmd(validator.validateVersion(core.getInput('version'), { required: true }));
14+
execOutput = await util.executePmd(pmdInfo,
1615
validator.validateSourcePath(core.getInput('sourcePath', { required: true })),
1716
validator.validateRulesets(core.getInput('rulesets', { required: true })),
1817
reportFormat, reportFile)
1918

20-
core.info(`PMD exited with ${exitCode}`);
19+
core.info(`PMD exited with ${execOutput.exitCode}`);
2120

2221
violations = sarif.countViolations(reportFile);
2322
core.setOutput('violations', violations);

lib/util.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const core = require('@actions/core');
22
const { Octokit } = require("@octokit/rest");
33
const tc = require('@actions/tool-cache');
44
const exec = require('@actions/exec');
5+
const semver = require('semver');
56

67
const downloadPmd = async function(version) {
78
try {
@@ -17,18 +18,21 @@ const downloadPmd = async function(version) {
1718
}
1819

1920
core.info(`Using PMD ${pmdVersion} from cached path ${cachedPmdPath}`);
20-
return `${cachedPmdPath}/pmd-bin-${pmdVersion}`;
21+
return {
22+
version: pmdVersion,
23+
path: `${cachedPmdPath}/pmd-bin-${pmdVersion}`
24+
};
2125
} catch (error) {
2226
core.setFailed(error.message || error);
2327
}
2428
}
2529

26-
const executePmd = async function(pmdPath, sourcePath, ruleset, reportFormat, reportFile) {
30+
const executePmd = async function(pmdInfo, sourcePath, ruleset, reportFormat, reportFile) {
2731
try {
28-
const { exitCode, stdout, stderr } = await exec.getExecOutput(`${pmdPath}/bin/run.sh`,
32+
const execOutput = await exec.getExecOutput(`${pmdInfo.path}/bin/run.sh`,
2933
[
3034
'pmd',
31-
'-no-cache',
35+
useNewArgsFormat(pmdInfo.version) ? '--no-cache' : '-no-cache',
3236
'-d', sourcePath,
3337
'-f', reportFormat,
3438
'-R', ruleset,
@@ -37,15 +41,19 @@ const executePmd = async function(pmdPath, sourcePath, ruleset, reportFormat, re
3741
{
3842
ignoreReturnCode: true
3943
});
40-
core.debug(`stdout: ${stdout}`);
41-
core.debug(`stderr: ${stderr}`);
42-
core.debug(`exitCode: ${exitCode}`);
43-
return exitCode;
44+
core.debug(`stdout: ${execOutput.stdout}`);
45+
core.debug(`stderr: ${execOutput.stderr}`);
46+
core.debug(`exitCode: ${execOutput.exitCode}`);
47+
return execOutput;
4448
} catch (error) {
4549
core.setFailed(error.message || error);
4650
}
4751
}
4852

53+
function useNewArgsFormat(pmdVersion) {
54+
return semver.gte(pmdVersion, '6.41.0');
55+
}
56+
4957
async function determinePmdRelease(pmdVersion) {
5058
core.debug(`determine release info for ${pmdVersion}`);
5159
const octokit = new Octokit({baseUrl: getGithubBaseUrl()});

lib/validator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const path = require('path');
2+
const semver = require('semver');
23

34
const validateVersion = function(version) {
45
if (typeof(version) === 'string'
5-
&& (version === 'latest' || version.match(/^\d+\.\d+\.\d+$/))) {
6+
&& (version === 'latest' || semver.valid(version) === version)) {
67
// valid
78
return version;
89
}

package-lock.json

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"@actions/core": "^1.6.0",
2929
"@actions/exec": "^1.1.0",
3030
"@actions/tool-cache": "^1.7.1",
31-
"@octokit/rest": "^18.12.0"
31+
"@octokit/rest": "^18.12.0",
32+
"semver": "^7.3.5"
3233
},
3334
"devDependencies": {
3435
"@actions/io": "^1.1.1",

tests/data/create-zips.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
zip -r pmd-bin-6.39.0.zip pmd-bin-6.39.0
44
zip -r pmd-bin-6.40.0.zip pmd-bin-6.40.0
5+
zip -r pmd-bin-6.41.0.zip pmd-bin-6.41.0

tests/data/pmd-bin-6.41.0.zip

677 Bytes
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Running PMD 6.41.0 with: $@"
4+
5+
echo '{
6+
"runs": [
7+
{
8+
"tool": {
9+
"driver": {
10+
"name": "PMD",
11+
"version": "6.41.0"
12+
}
13+
}
14+
}
15+
]
16+
}' > pmd-report.sarif
17+

0 commit comments

Comments
 (0)