-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #983 - Add CTK workflow features to CI/CD validation
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
- Loading branch information
1 parent
581ba09
commit 896b7e2
Showing
13 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2023-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { SWSchemaValidator } from "./index"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
SWSchemaValidator.prepareSchemas(); | ||
|
||
const ctkDir = path.join(__dirname, "..", "..", "..", "ctk", "features"); | ||
|
||
function extractYamlBlocks(content: string): string[] { | ||
const yamlBlockRegex = /"""yaml\s([\s\S]*?)\s"""/gm; // Match YAML blocks | ||
let match; | ||
const yamlBlocks: string[] = []; | ||
|
||
while ((match = yamlBlockRegex.exec(content)) !== null) { | ||
yamlBlocks.push(match[1]); | ||
} | ||
|
||
return yamlBlocks; | ||
} | ||
|
||
const workflows = fs.readdirSync(ctkDir) | ||
.filter((file) => file.endsWith(".feature")) | ||
.flatMap((file) => { | ||
const filePath = path.join(ctkDir, file); | ||
const fileContent = fs.readFileSync(filePath, SWSchemaValidator.defaultEncoding); | ||
|
||
const yamlBlocks = extractYamlBlocks(fileContent); | ||
|
||
return yamlBlocks | ||
.map((yamlText) => SWSchemaValidator.yamlToJSON(yamlText)) | ||
.filter((workflow) => typeof workflow === "object") | ||
.filter((workflow) => "document" in workflow) | ||
.filter((workflow) => "dsl" in workflow.document) | ||
.map((workflow) => ({ workflow, file })); | ||
}); | ||
|
||
describe(`Validate workflows from .feature files`, () => { | ||
test.each(workflows)('$workflow.document.name (from $file)', ({ workflow, file }) => { | ||
const results = SWSchemaValidator.validateSchema(workflow); | ||
|
||
if (results?.errors) { | ||
console.warn( | ||
`Schema validation failed for workflow "${workflow.document.name}" in file "${file}" with:`, | ||
JSON.stringify(results.errors, null, 2) | ||
); | ||
} | ||
|
||
expect(results?.valid).toBeTruthy(); | ||
}); | ||
}); |
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
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ Feature: For Task | |
dsl: '1.0.0' | ||
namespace: default | ||
name: for | ||
version: '1.0.0' | ||
do: | ||
- loopColors: | ||
for: | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ Feature: Set Task | |
dsl: '1.0.0' | ||
namespace: default | ||
name: set | ||
version: '1.0.0' | ||
do: | ||
- setShape: | ||
set: | ||
|
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