Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
schneidermic0 authored Apr 10, 2024
2 parents 6e9e7d4 + d797c42 commit 2b0aaf6
Show file tree
Hide file tree
Showing 55 changed files with 442 additions and 168 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/json-compability.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Compatability Check

on:
pull_request:

jobs:
compatible:
name: Is change compatible
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- name: Run script
run: |
cd compatibility-check
npm ci
npm run check
1 change: 1 addition & 0 deletions compatibility-check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
61 changes: 61 additions & 0 deletions compatibility-check/json-schema-diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const jsonSchemaDiff = require('json-schema-diff')
const exec = require('@actions/exec');
const core = require('@actions/core');
const {readFileSync} = require('node:fs');





async function run() {

let stdout = '';
const options = {
listeners: {
stdout: (data) => {
stdout += data.toString();
},
stderr: (data) => {
core.error(data.toString());
}
}
};

await exec.exec('git diff --name-only remotes/origin/main..HEAD', [], options);

const pattern = new RegExp('file-formats/[a-z]{4}/[a-z]+-v[0-9]+\.json$', 'i');
const lines = stdout.split("\n");

const changedSchema = lines.filter(line => pattern.test(line));


for (const schema of changedSchema) {

const dataNew = readFileSync(`../${schema}`, 'utf8');
const schemaNew = JSON.parse(dataNew);

try {
await exec.exec(`git checkout remotes/origin/main -- `, [schema], { cwd: `../`} );
} catch (error) {
core.info(`File ${schema} is not known to main branch.`);
continue;
}

const dataOld = readFileSync(`../${schema}`, 'utf8');
const schemaOld = JSON.parse(dataOld);

delete schemaOld['$schema'];
delete schemaNew['$schema'];

const result = await jsonSchemaDiff.diffSchemas( {sourceSchema: schemaOld, destinationSchema: schemaNew});
if (result.removalsFound) {
core.setFailed('Something was removed');
}

if (result.additionsFound) {
core.setFailed('Something was added');
};
}
}

run();
284 changes: 284 additions & 0 deletions compatibility-check/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions compatibility-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "json-schema-compatible",
"version": "1.0.0",
"description": "checks for incompatible changes in JSON Schema",
"main": "json-schema-diff.js",
"scripts": {
"check": "node json-schema-diff"
},
"author": "",
"license": "ISC",
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/exec": "^1.1.1",
"json-schema-diff": "^0.18.1"
}
}
4 changes: 1 addition & 3 deletions file-formats/aobj/aobj-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
"title": "Original Language",
"description": "Original language of the ABAP object",
"type": "string",
"minLength": 2,
"maxLength": 2,
"pattern": "^[a-z]+$"
"minLength": 2
},
"abapLanguageVersion": {
"title": "ABAP Language Version",
Expand Down
Loading

0 comments on commit 2b0aaf6

Please sign in to comment.