Skip to content

Commit b033830

Browse files
committed
Call pmd.bat under win32
Fixes #21
1 parent de644d4 commit b033830

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

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/util.js

Lines changed: 6 additions & 2 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 os = require('os');
56

67
const downloadPmd = async function(version) {
78
try {
@@ -25,9 +26,12 @@ const downloadPmd = async function(version) {
2526

2627
const executePmd = async function(pmdPath, sourcePath, ruleset, reportFormat, reportFile) {
2728
try {
28-
const { exitCode, stdout, stderr } = await exec.getExecOutput(`${pmdPath}/bin/run.sh`,
29+
let pmdExecutable = '/bin/run.sh pmd';
30+
if (os.platform() === 'win32') {
31+
pmdExecutable = '\\bin\\pmd.bat';
32+
}
33+
const { exitCode, stdout, stderr } = await exec.getExecOutput(`${pmdPath}${pmdExecutable}`,
2934
[
30-
'pmd',
3135
'-no-cache',
3236
'-d', sourcePath,
3337
'-f', reportFormat,

tests/util.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const nock = require('nock');
44
const io = require('@actions/io');
55
const os = require('os');
66
const fs = require('fs');
7+
const exec = require('@actions/exec');
78
const util = require('../lib/util');
89

910
const cachePath = path.join(__dirname, 'CACHE')
@@ -13,19 +14,26 @@ process.env['RUNNER_TEMP'] = tempPath
1314
process.env['RUNNER_TOOL_CACHE'] = cachePath
1415

1516
describe('pmd-github-action-util', function() {
17+
let platformMock;
18+
let execMock;
19+
1620
beforeAll(function() {
1721
setGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 0)
1822
setGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 0)
1923
})
2024

2125
beforeEach(async function() {
26+
platformMock = jest.spyOn(os, 'platform');
27+
execMock = jest.spyOn(exec, 'getExecOutput');
2228
await io.rmRF(cachePath)
2329
await io.rmRF(tempPath)
2430
await io.mkdirP(cachePath)
2531
await io.mkdirP(tempPath)
2632
})
2733

2834
afterEach(function() {
35+
platformMock.mockRestore();
36+
execMock.mockRestore();
2937
})
3038

3139
afterAll(async function() {
@@ -86,6 +94,33 @@ describe('pmd-github-action-util', function() {
8694
expect(report.runs[0].tool.driver.version).toBe('6.40.0');
8795
await io.rmRF(reportFile)
8896
})
97+
98+
it('can execute PMD win32', async () => {
99+
platformMock.mockReturnValueOnce('win32');
100+
execMock.mockReturnValueOnce({ exitCode: 0, stdout: '', stderr: '' });
101+
nock('https://api.github.com')
102+
.get('/repos/pmd/pmd/releases/latest')
103+
.replyWithFile(200, __dirname + '/data/releases-latest.json', {
104+
'Content-Type': 'application/json',
105+
})
106+
nock('https://github.com')
107+
.get('/pmd/pmd/releases/download/pmd_releases/6.40.0/pmd-bin-6.40.0.zip')
108+
.replyWithFile(200, __dirname + '/data/pmd-bin-6.40.0.zip')
109+
110+
const cachedPmdPath = await util.downloadPmd('latest');
111+
await util.executePmd(cachedPmdPath, '.', 'ruleset.xml', 'sarif', 'pmd-report.sarif');
112+
113+
expect(execMock).toBeCalledWith(`${cachedPmdPath}\\bin\\pmd.bat`, [
114+
'-no-cache',
115+
'-d', '.',
116+
'-f', 'sarif',
117+
'-R', 'ruleset.xml',
118+
'-r', 'pmd-report.sarif',
119+
],
120+
{
121+
ignoreReturnCode: true
122+
});
123+
})
89124
});
90125

91126
function setGlobal(key, value) {

0 commit comments

Comments
 (0)