forked from sfdx-actions/setup-pmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (33 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const core = require("@actions/core");
const exec = require("child_process").exec;
const PMD_VERSION = "7.1.0";
try {
installPMD();
} catch (error) {
core.setFailed(error.message);
}
function installPMD() {
const distName = `pmd-dist-${PMD_VERSION}-bin`;
const download = `wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/${distName}.zip -P /tmp`;
const unzip = `unzip /tmp/${distName}.zip -d /tmp`;
const mk = "mkdir $HOME/pmd";
const mv = `mv /tmp/pmd-bin-${PMD_VERSION}/* $HOME/pmd`;
exec(
download + " && " + unzip + " && " + mk + " && " + mv,
function (error, stdout, stderr) {
if (error) core.setFailed(stderr);
core.debug(stdout);
referencePMD();
}
);
}
function referencePMD() {
const mk = "sudo mkdir -p /snap/bin && sudo chmod -R 757 /snap/bin";
const cmd = `sudo echo '#! /bin/bash
$HOME/pmd/bin/pmd "$@"' > /snap/bin/pmd`;
const cm = "chmod +x /snap/bin/pmd";
exec(mk + " && " + cmd + " && " + cm, function (error, stdout, stderr) {
if (error) core.setFailed(stderr);
core.debug(stdout);
});
}