Skip to content

Commit

Permalink
Merge pull request #617 from Thels/cli-integration-tests
Browse files Browse the repository at this point in the history
CLI Fixes
  • Loading branch information
Thels authored Nov 27, 2024
2 parents c1842ab + ff8944c commit 017ee32
Show file tree
Hide file tree
Showing 49 changed files with 4,376 additions and 17,338 deletions.
2 changes: 0 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

/shared/ @aidanm3341 @lbulanti-ms @willosborne @grahampacker-ms @jpgough-ms @rocketstack-matt @Thels

/spectral/ @willosborne @lbulanti-ms @grahampacker-ms @jpgough-ms @rocketstack-matt

/translator/ @Budlee @matthewgardner @jpgough-ms @rocketstack-matt
2 changes: 1 addition & 1 deletion .github/workflows/cli-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
run: npm run build

- name: Run tests for CLI
run: npm run test --workspace=cli
run: npm run test --workspace=cli
18 changes: 14 additions & 4 deletions .github/workflows/spectral-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:
- "calm/draft/**"
- "calm/pattern/**"
- "calm/samples/**"
- "spectral/**"
- "shared/src/spectral/**"
push:
branches:
- "main"
paths:
- "calm/draft/**"
- "calm/pattern/**"
- "calm/samples/**"
- "spectral/**"
- "shared/src/spectral/**"

jobs:
spectrals:
Expand All @@ -30,6 +30,16 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: v20
- run: npm install @stoplight/spectral-cli
- run: npx spectral lint --ruleset spectral/instantiation/validation-rules.yaml 'calm/samples/api-gateway-instantiation(*.json|*.yaml)'

- name: Install workspace
run: npm ci

- name: Build workspace
run: npm run build

- name: Install Spectral-CLI
run: npm install @stoplight/spectral-cli

- name: Run Example Spectral Linting
run: npx spectral lint --ruleset ./shared/dist/spectral/rules-instantiation.js 'calm/samples/api-gateway-instantiation(*.json|*.yaml)'

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ node_modules/
**/.vscode-test/
**/out/
**/dependency-check-report/

**/tsconfig.tsbuildinfo
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ your project.
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Common Architecture Language Model](./calm) | [@rocketstack-matt](https://github.com/rocketstack-matt), [@jpgough-ms](https://github.com/jpgough-ms) | [![Validation of CALM Samples](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml) |
| [Docs](./docs) | [@rocketstack-matt](https://github.com/rocketstack-matt) | [![Sync Docs to S3](https://github.com/finos/architecture-as-code/actions/workflows/s3-docs-sync.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/s3-docs-sync.yml) |
| [CLI](./cli) & [Shared](./shared) | [@aidanm3341](https://github.com/aidanm3341), [@lbulanti-ms](https://github.com/lbulanti-ms), [@willosborne](https://github.com/willosborne), [@grahampacker-ms](https://github.com/grahampacker-ms) [@Thels](https://github.com/Thels) | [![Build CLI](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml) [![Build Shared Module](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml/badge.svg?branch=main)](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml) |
| [Spectral](./spectral) | [@willosborne](https://github.com/willosborne), [@lbulanti-ms](https://github.com/lbulanti-ms), [@grahampacker-ms](https://github.com/grahampacker-ms) | [![Validation of CALM Samples](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml) |
| [CLI](./cli) & [Shared](./shared) | [@aidanm3341](https://github.com/aidanm3341), [@lbulanti-ms](https://github.com/lbulanti-ms), [@willosborne](https://github.com/willosborne), [@grahampacker-ms](https://github.com/grahampacker-ms) [@Thels](https://github.com/Thels) | [![Build CLI](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml) [![Build Shared Module](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml/badge.svg?branch=main)](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml) | |
| [Translators](./translator) | [@Budlee](https://github.com/Budlee) [@matthewgardner](https://github.com/matthewgardner) [@jpgough-ms](https://github.com/jpgough-ms) | [![Build Translators](https://github.com/finos/architecture-as-code/actions/workflows/translator.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/translator.yml) |

## Getting Involved
Expand Down Expand Up @@ -59,6 +58,13 @@ We accept contributions via Pull Request, to make a contribution:
6. Push to the branch (`git push origin feature/fooBar`)
7. Create a new Pull Request

## Language Dependencies

### TypeScript Packages

Currently we have three typescript packages - two of which are managed via `npm workspaces` and one which is just raw `npm`.


## License

Copyright 2024 FINOS
Expand Down
7 changes: 3 additions & 4 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@ npm install
npm run build
# Step 3: Link the workspace locally for testing
npm link:cli
# Step 4: Start the watch process for live development
npm run watch
npm run link:cli
```
*Currently `watch` based development isn't working - this is in progress and will be resolved seperately.*
### CLI Tests
Expand Down
6 changes: 3 additions & 3 deletions cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['./**/*.spec.ts'],
testMatch: ['**/*.spec.ts'],
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!calm-shared)",
"<rootDir>/node_modules/(?!@finos/calm-shared)",
'^.+\\.js$'
],
rootDir: '.',
Expand Down
20 changes: 13 additions & 7 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finos/calm-cli",
"version": "0.2.6",
"version": "0.2.7",
"description": "A set of tools for interacting with the Common Architecture Language Model (CALM)",
"main": "dist/index.js",
"files": [
Expand All @@ -10,10 +10,9 @@
"calm": "dist/index.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -watch -p ./",
"clean": "rimraf dist",
"test": "jest --verbose",
"build": "tsup src/index.ts --format cjs --shims && npm run copy-calm-schema",
"copy-calm-schema": "copyfiles \"../calm/draft/2024-04/meta/*\" dist/calm/",
"test": "jest",
"lint": "eslint src",
"lint-fix": "eslint src --fix",
"dependency-check": "dependency-check --project 'calm-cli' --scan . --out ./dependency-check-report --format ALL --suppression ../.github/node-cve-ignore-list.xml"
Expand All @@ -28,21 +27,28 @@
"author": "",
"license": "ISC",
"dependencies": {
"canvas": "^2.11.2",
"commander": "^12.0.0",
"copyfiles": "^2.4.1",
"mkdirp": "^3.0.1"
"mkdirp": "^3.0.1",
"ts-jest": "^29.2.5"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"@types/json-pointer": "^1.0.34",
"@types/junit-report-builder": "^3.0.2",
"@types/lodash": "^4.17.0",
"@types/node": "^22.10.0",
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^9.13.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-node": "10.9.2",
"tsup": "^8.0.0",
"typescript": "^5.4.3",
"xml2js": "^0.6.2"
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('CLI Integration Tests', () => {

beforeAll(async () => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), integrationTestPrefix));
await callNpmFunctionSync(`${projectRoot}`, 'link');
await callNpmFunction(`${projectRoot}`, 'link');
}, millisPerSecond * 20);

afterAll(async () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('CLI Integration Tests', () => {
});
});

test('example validate command - no format or schema input - outputting JUNIT to stdout', (done) => {
test('example validate command - outputting JUNIT to stdout', (done) => {
const exampleValidateCommand = 'calm validate -p ../calm/pattern/api-gateway.json -i ../calm/samples/api-gateway-instantiation.json -f junit';
exec(exampleValidateCommand, async (_error, stdout, _stderr) => {
const parsedOutput = await parseStringPromise(stdout);
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('CLI Integration Tests', () => {
});


async function callNpmFunctionSync(projectRoot: string, command: string) {
async function callNpmFunction(projectRoot: string, command: string) {
await execPromise(`npm ${command}`, { cwd: projectRoot });
}

9 changes: 2 additions & 7 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#! /usr/bin/env node

import { CALM_META_SCHEMA_DIRECTORY, CALM_SPECTRAL_RULES_DIRECTORY, getFormattedOutput, runGenerate, validate, visualizeInstantiation, visualizePattern } from '@finos/calm-shared';
import { CALM_META_SCHEMA_DIRECTORY, getFormattedOutput, runGenerate, validate, visualizeInstantiation, visualizePattern, exitBasedOffOfValidationOutcome } from '@finos/calm-shared';
import { Option, program } from 'commander';
import path from 'path';
import { mkdirp } from 'mkdirp';
import { writeFileSync } from 'fs';
import { exitBasedOffOfValidationOutcome } from '@finos/calm-shared/dist/commands/validate/validate';

const FORMAT_OPTION = '-f, --format <format>';
const INSTANTIATION_OPTION = '-i, --instantiation <file>';
Expand Down Expand Up @@ -66,11 +65,7 @@ program
.option(VERBOSE_OPTION, 'Enable verbose logging.', false)
.action(async (options) => {
const outcome = await validate(options.instantiation, options.pattern, options.schemaDirectory, options.verbose);

const spectralRulesetForInstantiation = CALM_SPECTRAL_RULES_DIRECTORY + '/instantiation/validation-rules.yaml';
const spectralRulesetForPattern = CALM_SPECTRAL_RULES_DIRECTORY + '/pattern/validation-rules.yaml';

const content = getFormattedOutput(outcome, options.format,spectralRulesetForInstantiation, spectralRulesetForPattern);
const content = getFormattedOutput(outcome, options.format);
writeOutputFile(options.output, content);
exitBasedOffOfValidationOutcome(outcome, options.strict);
}
Expand Down
18 changes: 15 additions & 3 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"module": "CommonJS",
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"types": ["node", "jest"]
"moduleResolution": "node",
"types": [
"node",
"jest"
],
"typeRoots": [
"node_modules/@types",
"../node_modules/@types"
]
},
"references": [
{
"path": "../shared"
}
],
"include": [
"src/**/*"
]
Expand Down
18 changes: 18 additions & 0 deletions cli/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
sourcemap: false,
clean: true,
external: ['canvas', 'fsevents', /node_modules/],
noExternal: ['@finos/calm-shared', /tsup/],
bundle: true,
splitting: false,
minify: false,
shims: true,
target: 'es2021',
treeshake: true
});
Loading

0 comments on commit 017ee32

Please sign in to comment.