Skip to content

Commit 9f13b7c

Browse files
authored
ci: Enable schema build for monorepo (#1206)
JIRA: CPOUI5FOUNDATION-1162 + Schema build script moved to `internal/documentation/scripts/` - allows a parameter to set if schema should be based on local state or latest published npm state + npm scripts for this regard moved to `internal/documentation/` + Deployment CI jobs adjusted (but still disabled till final v5 release) + Changes in local workspace will be reflected in local build of schema - CI will generate schemas based on latest published npm version
1 parent 38d475e commit 9f13b7c

File tree

8 files changed

+78
-68
lines changed

8 files changed

+78
-68
lines changed

.github/workflows/deploy-vitepress-docs.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ jobs:
5959
- name: Build jsdoc
6060
working-directory: internal/documentation
6161
run: npm run jsdoc-generate
62-
# TODO: Skip for now deployment of the schema until we do a Schema Version 5 release
63-
# - name: Build Sch3 |
64-
# npm run schema-generate
65-
# npm run schema-workspace-generate
62+
- name: Build Schema
63+
working-directory: internal/documentation
64+
run: npm run schema-generate
6665
- name: Checkout gh-pages
6766
uses: actions/checkout@v5
6867
with:
@@ -72,7 +71,7 @@ jobs:
7271
run: |
7372
# TODO: Skip for now deployment of the schema until we do a Schema Version 5 release
7473
# rm -rf ./gh-pages/schema
75-
# cp -R ./site/schema ./gh-pages/
74+
# cp -R internal/documentation/schema ./gh-pages/schema/
7675
rm -rf ./gh-pages/${DOC_VERSION}
7776
rm -rf ./gh-pages/${DOC_ALIAS}
7877

.github/workflows/github-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
run: npm run jsdoc-generate
4545

4646
- name: Generate merged JSON schema
47+
working-directory: internal/documentation
4748
run: npm run schema-generate
4849

4950
- name: Generate CLI documentation

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ internal/documentation/docs/pages/CLI.md
6767
internal/documentation/.vitepress/dist
6868
internal/documentation/.vitepress/cache
6969
internal/documentation/dist
70+
internal/documentation/schema/*

internal/documentation/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"jsdoc": "npm run jsdoc-generate && open-cli dist/api/index.html",
3333
"jsdoc-generate": "jsdoc -c jsdoc/jsdoc.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
3434
"jsdoc-generate-workspace": "jsdoc -c jsdoc/jsdoc-workspace.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
35-
"generate-cli-doc": "node ./scripts/generateCliDoc.js"
35+
"generate-cli-doc": "node ./scripts/generateCliDoc.js",
36+
"schema-generate": "node ./scripts/buildSchema.js @ui5/project-npm",
37+
"schema-generate-workspace": "node ./scripts/buildSchema.js @ui5/project"
3638
},
3739
"dependencies": {
3840
"@types/node": "^22.5.1",
@@ -46,15 +48,17 @@
4648
"vue": "^3.4.38"
4749
},
4850
"devDependencies": {
51+
"@apidevtools/json-schema-ref-parser": "^14.2.1",
4952
"@ui5/builder-npm": "npm:@ui5/builder@^4.0.11",
5053
"@ui5/cli-npm": "npm:@ui5/cli@^4.0.26",
5154
"@ui5/fs-npm": "npm:@ui5/fs@^4.0.2",
5255
"@ui5/logger-npm": "npm:@ui5/logger@^4.0.2",
5356
"@ui5/project-npm": "npm:@ui5/project@^4.0.6",
5457
"@ui5/server-npm": "npm:@ui5/server@^4.0.7",
5558
"docdash": "^2.0.2",
59+
"handlebars": "^4.7.8",
5660
"jsdoc": "^4.0.4",
5761
"open-cli": "^8.0.0",
58-
"handlebars": "^4.7.8"
62+
"traverse": "^0.6.11"
5963
}
6064
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import path from "node:path";
2+
import {fileURLToPath} from "node:url";
3+
import {writeFile, mkdir} from "node:fs/promises";
4+
import {$RefParser} from "@apidevtools/json-schema-ref-parser";
5+
import traverse from "traverse";
6+
7+
// Read the given CLI parameter to set which UI5/project version to use.
8+
// Default to "@ui5/project-npm" to use the latest published version (for Github Pages).
9+
// For testing, the local version can be used by providing "@ui5/project".
10+
// Example: node buildSchema.js @ui5/project-npm
11+
// Example: node buildSchema.js @ui5/project
12+
const UI5_PROJECT_VERSION = process.argv[2] || "@ui5/project-npm";
13+
14+
try {
15+
// Use ui5.yaml.json and ui5-workspace.yaml.json
16+
const schemaNames = ["ui5", "ui5-workspace"];
17+
18+
schemaNames.forEach(async (schemaName) => {
19+
const SOURCE_SCHEMA_PATH = fileURLToPath(
20+
new URL(`./lib/validation/schema/${schemaName}.json`,
21+
import.meta.resolve(`${UI5_PROJECT_VERSION}/package.json`))
22+
);
23+
const TARGET_SCHEMA_PATH = fileURLToPath(
24+
new URL(`../schema/${schemaName}.yaml.json`, import.meta.url)
25+
);
26+
27+
const parser = new $RefParser();
28+
const schema = await parser.bundle(SOURCE_SCHEMA_PATH);
29+
30+
// Remove $id from all nodes and $schema / $comment from all except the root node.
31+
// Defining $id on the root is not required and as the URL will be a different one it might even cause issues.
32+
// $schema only needs to be defined once per file.
33+
traverse(schema).forEach(function(v) {
34+
// eslint-disable-next-line no-invalid-this
35+
const traverseContext = this;
36+
if (v && typeof v === "object" && !Array.isArray(v)) {
37+
if (v.$id) {
38+
delete v.$id;
39+
}
40+
if (!traverseContext.isRoot) {
41+
if (v.$schema) {
42+
delete v.$schema;
43+
}
44+
if (v.$comment) {
45+
delete v.$comment;
46+
}
47+
}
48+
traverseContext.update(v);
49+
}
50+
});
51+
52+
await mkdir(path.dirname(TARGET_SCHEMA_PATH), {recursive: true});
53+
await writeFile(TARGET_SCHEMA_PATH, JSON.stringify(schema, null, 2));
54+
55+
console.log(`Wrote bundled ${schemaName}.yaml schema file to ${TARGET_SCHEMA_PATH}`);
56+
});
57+
} catch (error) {
58+
console.log(error);
59+
process.exit(1);
60+
}
61+

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
"lint:commit": "commitlint",
2929
"unit": "npm run unit --workspaces --if-present",
3030
"coverage": "npm run coverage --workspaces --if-present",
31-
"schema-generate": "node ./scripts/buildSchema.js ui5",
32-
"schema-workspace-generate": "node ./scripts/buildSchema.js ui5-workspace",
3331
"depcheck": "depcheck --ignores @ui5/builder,@ui5/cli,@ui5/fs,@ui5/logger,@ui5/project,@ui5/server,local-web-server,@commitlint/config-conventional,husky && npm run depcheck --workspaces --if-present",
3432
"check-licenses": "licensee --errors-only",
3533
"generate-cli-doc": "npm run generate-cli-doc --workspace=@ui5/documentation"
@@ -43,7 +41,6 @@
4341
"@ui5/project": "^4.0.6"
4442
},
4543
"devDependencies": {
46-
"@apidevtools/json-schema-ref-parser": "^14.2.1",
4744
"@commitlint/cli": "^20.1.0",
4845
"@commitlint/config-conventional": "^20.0.0",
4946
"@eslint/js": "^9.8.0",
@@ -55,8 +52,7 @@
5552
"globals": "^16.4.0",
5653
"husky": "^9.1.7",
5754
"licensee": "^11.1.1",
58-
"local-web-server": "^5.4.0",
59-
"traverse": "^0.6.11"
55+
"local-web-server": "^5.4.0"
6056
},
6157
"workspaces": [
6258
"packages/*",

scripts/buildSchema.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)