-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
tools.ts
179 lines (164 loc) · 6.93 KB
/
tools.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import fs, {PathLike} from 'fs';
import {Config} from './config/app';
import {ComposerJson} from './config/composer';
import parseJsonFile from './json';
import {CONTAINER_DEFAULT_PHP_VERSION} from './config/php';
export enum ToolExecutionType {
/**
* @description Executed on every supported PHP version with lowest & latest dependencies.
* In case, a lock-file is present, the minimum supported PHP version will also run with LOCKED
* dependencies.
*/
MATRIX = 'matrix',
/**
* @description Executed on the minimum PHP version with either LOCKED or LATEST dependencies.
*/
STATIC = 'static',
}
enum ToolType {
LINTER = 'linter',
CODE_CHECK = 'code_check',
}
export type Tool = {
executionType: ToolExecutionType,
toolType: ToolType,
name: string;
command: string;
filesToCheck: PathLike[],
lintConfigCommand?: string,
}
export type ToolRunningContainerDefaultPhpVersion = Tool & {
php: typeof CONTAINER_DEFAULT_PHP_VERSION,
}
function detectInfectionCommand(): string {
const composerJson: ComposerJson = parseJsonFile('composer.json', true) as ComposerJson;
if (composerJson['require-dev']?.['roave/infection-static-analysis-plugin'] !== undefined) {
return 'phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin';
}
return 'phpdbg -qrr ./vendor/bin/infection';
}
function backwardCompatibilityCheckTool(config: Config): ToolRunningContainerDefaultPhpVersion | null {
if (!config.backwardCompatibilityCheck) {
return null;
}
if (config.baseReference === null) {
return null;
}
return {
executionType : ToolExecutionType.STATIC,
name : 'Backward Compatibility Check',
command : `roave-backward-compatibility-check --from=${ config.baseReference } --install-development-dependencies`,
filesToCheck : [ 'composer.json' ],
toolType : ToolType.CODE_CHECK,
php : CONTAINER_DEFAULT_PHP_VERSION,
} as ToolRunningContainerDefaultPhpVersion;
}
export default function createTools(config: Config): Array<Tool> {
const tools = [
{
executionType : ToolExecutionType.STATIC,
name : 'Documentation Linting',
command : 'markdownlint doc/book/**/*.md',
filesToCheck : [ 'doc/book/' ],
toolType : ToolType.LINTER,
},
{
executionType : ToolExecutionType.STATIC,
name : 'Documentation Linting',
command : 'markdownlint docs/book/**/*.md',
filesToCheck : [ 'docs/book/' ],
toolType : ToolType.LINTER,
},
{
executionType : ToolExecutionType.STATIC,
name : 'MkDocs Linting',
command : 'yamllint -d relaxed --no-warnings mkdocs.yml',
filesToCheck : [ 'mkdocs.yml' ],
toolType : ToolType.LINTER,
},
{
executionType : ToolExecutionType.STATIC,
name : 'README Linting',
command : 'markdownlint README.md',
filesToCheck : [ 'README.md' ],
toolType : ToolType.LINTER,
},
{
executionType : ToolExecutionType.MATRIX,
name : 'PHPUnit',
command : './vendor/bin/phpunit',
filesToCheck : [ 'phpunit.xml.dist', 'phpunit.xml' ],
toolType : ToolType.CODE_CHECK,
lintConfigCommand : 'xmllint --schema vendor/phpunit/phpunit/phpunit.xsd',
},
{
executionType : ToolExecutionType.STATIC,
name : 'Infection',
command : detectInfectionCommand(),
filesToCheck : [ 'infection.json', 'infection.json.dist' ],
toolType : ToolType.CODE_CHECK,
},
{
executionType : ToolExecutionType.STATIC,
name : 'PHPCodeSniffer',
command : './vendor/bin/phpcs -q --report=checkstyle | cs2pr',
filesToCheck : [ 'phpcs.xml', 'phpcs.xml.dist' ],
toolType : ToolType.CODE_CHECK,
lintConfigCommand : 'xmllint --schema vendor/squizlabs/php_codesniffer/phpcs.xsd',
},
{
executionType : ToolExecutionType.STATIC,
name : 'Psalm',
command : './vendor/bin/psalm --shepherd --stats --output-format=github --no-cache',
filesToCheck : [ 'psalm.xml.dist', 'psalm.xml' ],
toolType : ToolType.CODE_CHECK,
lintConfigCommand : 'xmllint --schema vendor/vimeo/psalm/config.xsd',
},
{
executionType : ToolExecutionType.STATIC,
name : 'Composer Require Checker',
command : './vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json',
filesToCheck : [ 'composer-require-checker.json' ],
toolType : ToolType.CODE_CHECK,
},
{
executionType : ToolExecutionType.STATIC,
name : 'PHPBench',
command : './vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate',
filesToCheck : [ 'phpbench.json' ],
toolType : ToolType.CODE_CHECK,
},
{
executionType : ToolExecutionType.STATIC,
name : 'Codeception',
command : './vendor/bin/codecept run',
filesToCheck : [ 'codeception.yml.dist', 'codeception.yml' ],
toolType : ToolType.CODE_CHECK,
},
{
executionType : ToolExecutionType.STATIC,
name : 'PHP CS Fixer',
command : './vendor/bin/php-cs-fixer fix -v --diff --dry-run',
filesToCheck : [ '.php-cs-fixer.php', '.php-cs-fixer.dist.php' ],
toolType : ToolType.CODE_CHECK,
},
backwardCompatibilityCheckTool(config),
].filter((tool) => tool !== null) as Tool[];
return tools
// Remove all tools which do not need to run
.filter((tool) =>
(config.docLinting && tool.toolType === ToolType.LINTER)
|| (config.codeChecks && tool.toolType === ToolType.CODE_CHECK))
// Remove all tools which are not used by the project
.map((tool) => removeNonExistentFilesToCheck(tool))
.filter((tool) => tool.filesToCheck.length > 0);
}
export function removeNonExistentFilesToCheck(tool: Tool): Tool {
return {
...tool,
filesToCheck : tool.filesToCheck.filter((file) => fs.existsSync(file))
};
}
export function isToolRunningContainerDefaultPhpVersion(tool: Tool): tool is ToolRunningContainerDefaultPhpVersion {
return (tool as ToolRunningContainerDefaultPhpVersion).php === CONTAINER_DEFAULT_PHP_VERSION;
}