forked from tinovyatkin/action-php-codesniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
40 lines (36 loc) · 1.3 KB
/
main.ts
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
38
39
40
import * as path from 'path';
import * as core from '@actions/core';
import { getChangedFiles } from './get-changed-file';
import { runOnCompleteFiles } from './run-on-files';
import { runOnBlame } from './run-on-blame';
async function run(): Promise<void> {
try {
const files = await getChangedFiles();
core.info(JSON.stringify(files, null, 2));
if (!files.added.length && !files.modified.length) {
core.warning('No files to check, exiting...');
return;
}
/**
* Adding problem matcher to annotate files without token
* @see {@link https://github.com/actions/setup-node/blob/a47b2f66c61e623b503818d97a63ce0fe087f700/src/setup-node.ts#L36}
*/
const matchersPath = path.join(__dirname, '..', '.github');
console.log(
`##[add-matcher]${path.join(matchersPath, 'phpcs-matcher.json')}`
);
// run on complete files when they added or scope=files
const scope = core.getInput('scope', { required: true });
if (files.added.length || scope === 'files')
runOnCompleteFiles(
scope === 'files' ? [...files.added, ...files.modified] : files.added
);
else if (files.modified.length && scope === 'blame') {
// run on blame
await runOnBlame(files.modified);
}
} catch (error) {
// core.setFailed(error);
}
}
void run();