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

Fix #852 - Add cache path to node CI and remove examples hydration pipeline #861

Merged
merged 3 commits into from
May 29, 2024
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
1 change: 0 additions & 1 deletion .ci/examples-readme-hydration/.gitignore

This file was deleted.

39 changes: 0 additions & 39 deletions .ci/examples-readme-hydration/index.js

This file was deleted.

24 changes: 0 additions & 24 deletions .ci/examples-readme-hydration/package-lock.json

This file was deleted.

15 changes: 0 additions & 15 deletions .ci/examples-readme-hydration/package.json

This file was deleted.

56 changes: 40 additions & 16 deletions .ci/validation/package-lock.json

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

11 changes: 9 additions & 2 deletions .ci/validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
"start": "ts-node ./src/index.ts",
"test": "jest"
},
"keywords": ["cncf", "serverless", "workflow", "specification"],
"keywords": [
"cncf",
"serverless",
"workflow",
"specification"
],
"author": "CNCF Serverless Workflow Specification",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.9",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
},
"dependencies": {
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1"
"ajv-formats": "^2.1.1",
"js-yaml": "^4.1.0"
}
}
46 changes: 27 additions & 19 deletions .ci/validation/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,34 @@
* limitations under the License.
*/

import { SWSchemaValidator } from './index'
import fs from 'fs'
import { join } from 'path'
import { SWSchemaValidator } from "./index";
import fs from "fs";
import { join } from "path";

SWSchemaValidator.prepareSchemas()
SWSchemaValidator.prepareSchemas();

const examplePath = "../../../examples"
const examplePath = "../../../examples";

describe(`Verify every example in the repository`, () => {
fs.readdirSync(join(__dirname, examplePath), { encoding: SWSchemaValidator.defaultEncoding, recursive: false, withFileTypes: true })
.forEach(file => {
if (file.isFile() && file.name.endsWith(".json")) {
test(`Example ${file.name}`, () => {
const workflow = JSON.parse(fs.readFileSync(join(__dirname, `${examplePath}/${file.name}`), SWSchemaValidator.defaultEncoding))
const results = SWSchemaValidator.validateSchema(workflow)
if (results?.errors != null) {
console.warn(`Schema validation on ${file.name} failed with: `, JSON.stringify(results.errors, null, 2))
}
expect(results?.valid).toBeTruthy()
});
}
})
})
fs.readdirSync(join(__dirname, examplePath), {
encoding: SWSchemaValidator.defaultEncoding,
recursive: false,
withFileTypes: true,
}).forEach((file) => {
if (file.isFile() && file.name.endsWith(".yaml")) {
test(`Example ${file.name}`, () => {
const workflow = SWSchemaValidator.toJSON(
join(__dirname, `${examplePath}/${file.name}`)
);
const results = SWSchemaValidator.validateSchema(workflow);
if (results?.errors != null) {
console.warn(
`Schema validation on ${file.name} failed with: `,
JSON.stringify(results.errors, null, 2)
);
}
expect(results?.valid).toBeTruthy();
});
}
});
});
74 changes: 42 additions & 32 deletions .ci/validation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,55 @@
* limitations under the License.
*/

import fs from 'fs'
import Ajv from "ajv"
import addFormats from "ajv-formats"
import { join } from 'path'

import fs from "fs";
import Ajv from "ajv";
import addFormats from "ajv-formats";
import { join } from "path";
import yaml = require("js-yaml");

export module SWSchemaValidator {
const ajv = new Ajv({ strict: false, allowUnionTypes: true })
addFormats(ajv)
const ajv = new Ajv({ strict: false, allowUnionTypes: true });
addFormats(ajv);

const workflowSchemaId =
"https://serverlessworkflow.io/schemas/1.0.0-alpha1/workflow.json";
const schemaPath = "../../../schema";
export const defaultEncoding = "utf-8";

const workflowSchemaId = 'https://serverlessworkflow.io/schemas/0.9/workflow.json'
const schemaPath = '../../../schema'
export const defaultEncoding = 'utf-8'
export function prepareSchemas() {
fs.readdirSync(join(__dirname, schemaPath), {
encoding: defaultEncoding,
recursive: false,
withFileTypes: true,
}).forEach((file) => {
if (file.isFile()) {
ajv.addSchema(syncReadSchema(file.name));
}
});
}

export function prepareSchemas() {
fs.readdirSync(join(__dirname, schemaPath), { encoding: defaultEncoding, recursive: false, withFileTypes: true })
.forEach(file => {
if (file.isFile()) {
ajv.addSchema(syncReadSchema(file.name))
}
})
}
function syncReadSchema(filename: string) {
return toJSON(join(__dirname, `${schemaPath}/${filename}`));
}

function syncReadSchema(filename: string) {
return JSON.parse(fs.readFileSync(join(__dirname, `${schemaPath}/${filename}`), defaultEncoding));
}
export function toJSON(filename: string) {
const yamlObj = yaml.load(fs.readFileSync(filename, defaultEncoding), {
json: true,
});
return JSON.parse(JSON.stringify(yamlObj, null, 2));
}

export function validateSchema(workflow: JSON) {
const validate = ajv.getSchema(workflowSchemaId)
if (validate != undefined) {
const isValid = validate(workflow)
return {
valid: isValid,
errors: validate.errors
}
}
// throw error
export function validateSchema(workflow: JSON) {
const validate = ajv.getSchema(workflowSchemaId);
if (validate != undefined) {
const isValid = validate(workflow);
return {
valid: isValid,
errors: validate.errors,
};
}
throw new Error(`Failed to validate schema on workflow`);
}
}

console.log("To use this application see the test file index.test.ts")
console.log("To use this application see the test file index.test.ts");
9 changes: 2 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@ Enhancements or bugs in a specification are not always easy to describe at first
We kindly ask you to consider opening a discussion or an issue using the Github tab menu above. The community will be more than happy to discuss your proposals there.
-->

**Many thanks for submitting your Pull Request :heart:!**

**Please specify parts of this PR update:**

- [ ] Specification
- [ ] Schema
- [ ] Examples
- [ ] Extensions
- [ ] Roadmap
- [ ] Use Cases
- [ ] Community
- [ ] TCK
- [ ] CTK
- [ ] Other

**Discussion or Issue link**:
<!-- Please consider opening a dicussion or issue for bugs or enhancements. You can ignore this field if this is a typo or spelling fix. -->

**What this PR does / why we need it**:
**What this PR does**:
<!-- Brief description of your PR / Short summary of the discussion or issue -->

**Special notes for reviewers**:

**Additional information:**
<!-- Optional -->
Loading
Loading