Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make generated JSON Schema available in PR #574

Merged
merged 22 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Validate JSON schema
name: Generate JSON Schema

on:
pull_request:

jobs:
validate:
name: Compare generated against provided
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -19,3 +20,11 @@ jobs:
run: |
cd generate
npm run generate
- name: Upload generated schemas
if: always()
uses: actions/upload-artifact@v3
with:
name: schemas
path: |
generate/generated/*.json

5 changes: 3 additions & 2 deletions .github/workflows/markdown-link-check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Markdown links
name: Check Markdown Links

on:
pull_request:
Expand All @@ -7,7 +7,8 @@ permissions:
contents: read

jobs:
markdown-link-check:
check-links:
name: Check links
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/py-validation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Validate JSON examples
name: Validate JSON Examples

on:
pull_request:
Expand All @@ -9,7 +9,7 @@ permissions:
jobs:
build:
# Name the Job
name: Validate JSON examples against their schema
name: Validate examples against schema

runs-on: ubuntu-latest

Expand Down
47 changes: 35 additions & 12 deletions generate/aff.mjs
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();
Loading
Loading