@apidiff/action 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action.yml +20 -0
- package/dist/index.js +34961 -0
- package/package.json +13 -0
- package/src/index.ts +53 -0
- package/tsconfig.json +11 -0
- package/tsup.config.ts +10 -0
package/package.json
ADDED
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as core from '@actions/core';
|
|
2
|
+
import { run as runApidiff, formatOutput } from '@apidiff/core';
|
|
3
|
+
|
|
4
|
+
async function run(): Promise<void> {
|
|
5
|
+
try {
|
|
6
|
+
let baseSpecInput = core.getInput('base-spec', { required: true });
|
|
7
|
+
let headSpecInput = core.getInput('head-spec', { required: true });
|
|
8
|
+
const failOnBreaking = core.getInput('fail-on-breaking') !== 'false';
|
|
9
|
+
const format = core.getInput('format') as 'markdown' | 'json' | 'terminal' | 'html' || 'markdown';
|
|
10
|
+
|
|
11
|
+
// Handle inputs like `main:openapi.yaml`
|
|
12
|
+
if (!baseSpecInput.startsWith('git:') && !baseSpecInput.startsWith('http') && baseSpecInput.includes(':') && !baseSpecInput.match(/^[a-zA-Z]:[/\\]/)) {
|
|
13
|
+
baseSpecInput = 'git:' + baseSpecInput;
|
|
14
|
+
}
|
|
15
|
+
if (!headSpecInput.startsWith('git:') && !headSpecInput.startsWith('http') && headSpecInput.includes(':') && !headSpecInput.match(/^[a-zA-Z]:[/\\]/)) {
|
|
16
|
+
headSpecInput = 'git:' + headSpecInput;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
core.info(`Comparing base: ${baseSpecInput} vs head: ${headSpecInput}`);
|
|
20
|
+
|
|
21
|
+
const config = {
|
|
22
|
+
output: { format }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
core.info('Computing semantic diff...');
|
|
26
|
+
const result = await runApidiff(baseSpecInput, headSpecInput, config);
|
|
27
|
+
|
|
28
|
+
const outputStr = formatOutput(result.changes, format);
|
|
29
|
+
|
|
30
|
+
if (format === 'markdown') {
|
|
31
|
+
core.summary.addRaw(outputStr);
|
|
32
|
+
await core.summary.write();
|
|
33
|
+
} else {
|
|
34
|
+
core.info(outputStr);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const breaking = result.changes.filter(c => c.severity === 'breaking');
|
|
38
|
+
if (breaking.length > 0) {
|
|
39
|
+
const msg = `Found ${breaking.length} breaking changes.`;
|
|
40
|
+
if (failOnBreaking) {
|
|
41
|
+
core.setFailed(msg);
|
|
42
|
+
} else {
|
|
43
|
+
core.warning(msg);
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
core.info('No breaking changes found.');
|
|
47
|
+
}
|
|
48
|
+
} catch (error: any) {
|
|
49
|
+
core.setFailed(error.message || String(error));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
run();
|
package/tsconfig.json
ADDED