-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make generated JSON Schema available in PR (#574)
Co-authored-by: Lars Hvam <[email protected]>
- Loading branch information
1 parent
7937dfe
commit 466f958
Showing
6 changed files
with
114 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,70 @@ | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import * as child_process from 'node:child_process'; | ||
import {initializeABAP} from "./output/init.mjs"; | ||
import { initializeABAP } from "./output/init.mjs"; | ||
await initializeABAP(); | ||
import * as core from '@actions/core'; | ||
|
||
async function run() { | ||
if (fs.existsSync("generated") === false) { | ||
fs.mkdirSync("generated"); | ||
} | ||
|
||
function createAnnotations(diff, file) { | ||
let lines = diff.split('\n'); | ||
|
||
let lineNumber; | ||
const regExp = /^[0-9]/; | ||
|
||
lines.forEach(line => { | ||
|
||
if (line.startsWith('>')) { | ||
let text = line.split(' ').slice(1).join(' '); | ||
console.log(`::error file=${file},line=${lineNumber}::${text}`); | ||
++lineNumber; | ||
} else if (regExp.test(line)) { | ||
lineNumber = parseInt(line.split("c")[0].split(",")[0]); // 16 | ||
} | ||
}); | ||
|
||
} | ||
|
||
|
||
const types = []; | ||
for (const f of fs.readdirSync("../file-formats/")) { | ||
if (f.length === 4) { | ||
types.push(f.toUpperCase()); | ||
} | ||
} | ||
types.sort(); | ||
|
||
|
||
let error = false; | ||
for (const type of types) { | ||
console.log(type); | ||
if (type === "ENHO") { | ||
console.log("\tskip, https://github.com/SAP/abap-file-formats/issues/409"); | ||
core.notice(type + " skipped, https://github.com/SAP/abap-file-formats/issues/409"); | ||
continue; | ||
} | ||
|
||
const result = await abap.Classes["CL_RUN"].run({object_type: new abap.types.String().set(type)}); | ||
const result = await abap.Classes["CL_RUN"].run({ object_type: new abap.types.String().set(type) }); | ||
const filename = "generated" + path.sep + type.toLowerCase() + "-v1.json"; | ||
const filename_aff = `../file-formats/${type.toLowerCase()}/${type.toLowerCase()}-v1.json`; | ||
fs.writeFileSync(filename, result.get()); | ||
|
||
const command = `diff --strip-trailing-cr generated/${type.toLowerCase()}-v1.json ../file-formats/${type.toLowerCase()}/${type.toLowerCase()}-v1.json`; | ||
|
||
const command = `diff ${filename_aff} ${filename}`; | ||
const output = child_process.execSync(`${command} || true`); | ||
if (output.toString().length > 0) { | ||
console.log(command); | ||
console.log(output.toString()); | ||
error = true; | ||
core.setFailed(type + ": Provided and generated JSON Schema differ") | ||
createAnnotations(output.toString(), path.resolve(filename_aff)); | ||
//core.info(command); | ||
//core.info(output.toString()); | ||
} else { | ||
console.log("\tOK\n"); | ||
core.notice(type + " success"); | ||
} | ||
} | ||
|
||
if (error === true) { | ||
exit(1); | ||
} | ||
|
||
} | ||
|
||
run(); |
Oops, something went wrong.