Skip to content

Commit

Permalink
[cascading] from release/11.2.0-rc to main (#2139)
Browse files Browse the repository at this point in the history
<!--
{"currentBranch":"release/11.2.0-rc","targetBranch":"main","bypassReviewers":true,"isConflicting":false}
-->

## Cascading from release/11.2.0-rc to main

The configuration requests the cascading to bypass reviewer in case of
CI success.
To not bypass the reviewing process, please check the following
checkbox:

- [ ] <!-- !cancel bypass! --> 🚫 stop reviewing process
bypass for this Pull Request

---

<small>This Pull Request has been generated with ❤️ by the
[Otter](https://github.com/AmadeusITGroup/otter) cascading tool.</small>
  • Loading branch information
fpaul-1A authored Sep 6, 2024
2 parents 07f774e + cc7e8a6 commit 9c654c1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Update Styling imports', () => {
const runner = new SchematicTestRunner('migrations', collectionPath);
const tree = await lastValueFrom(runner.callRule(updateSassImports('o3r'), initialTree));

expect(tree.read('/packages/@o3r/styling/schematics/ng-add/updates-of-old-otter-scope/imports/mocks/old.scss')!.toString('utf8'))
expect(tree.read('/packages/@o3r/styling/schematics/ng-add/updates-of-old-otter-scope/imports/mocks/old.scss').toString('utf8'))
.toBe(fs.readFileSync(path.resolve(__dirname, 'mocks', 'new.scss.result'), {encoding: 'utf8'}));
});

Expand Down
36 changes: 33 additions & 3 deletions packages/@o3r/workspace/schematics/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,68 @@ import { existsSync, promises as fs } from 'node:fs';
import * as path from 'node:path';
import type { PackageJson } from 'type-fest';

const mocksFolder = path.join(__dirname, '..', 'testing', 'mocks');

describe('new otter workspace', () => {
test('should add sdk to an existing workspace', () => {
const { workspacePath, isInWorkspace, untouchedProjectsPaths } = o3rEnvironment.testEnvironment;
const execAppOptions = {...getDefaultExecSyncOptions(), cwd: workspacePath};
packageManagerExec({script: 'ng', args: ['g', 'sdk', 'my-sdk']}, execAppOptions);
expect(() =>
packageManagerExec({script: 'ng', args: ['g', 'sdk', 'my-sdk']}, execAppOptions)
).not.toThrow();

const diff = getGitDiff(execAppOptions.cwd);
untouchedProjectsPaths.forEach(untouchedProject => {
expect(diff.all.some(file => file.startsWith(path.posix.relative(workspacePath, untouchedProject)))).toBe(false);
});

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRunOnProject('@my-sdk/sdk', isInWorkspace, {script: 'build'}, execAppOptions)).not.toThrow();
});

test('should add sdk to an existing workspace with local spec', async () => {
const { workspacePath, isInWorkspace, untouchedProjectsPaths } = o3rEnvironment.testEnvironment;
const sdkPath = path.posix.join('libs', 'my-sdk-sdk');
const execAppOptions = {...getDefaultExecSyncOptions(), cwd: workspacePath};
await fs.copyFile(path.join(mocksFolder, 'easy-spec.yaml'), path.join(workspacePath, 'local-spec.yaml'));
expect(() => packageManagerExec({script: 'ng', args: [
'g',
'sdk',
'@my-sdk/sdk',
'--spec-path', './local-spec.yaml'
]}, execAppOptions)).not.toThrow();

const diff = getGitDiff(execAppOptions.cwd);
untouchedProjectsPaths.forEach(untouchedProject => {
expect(diff.all.some(file => file.startsWith(path.posix.relative(workspacePath, untouchedProject)))).toBe(false);
});
expect(diff.added).toContain(path.posix.join(sdkPath, 'open-api.yaml'));
expect(diff.added).toContain(path.posix.join(sdkPath, 'src', 'models', 'base', 'category', 'category.ts'));

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRunOnProject('@my-sdk/sdk', isInWorkspace, {script: 'build'}, execAppOptions)).not.toThrow();
});

test('should add sdk to an existing workspace with spec package name', () => {
const { workspacePath, isInWorkspace, untouchedProjectsPaths, o3rVersion, registry } = o3rEnvironment.testEnvironment;
const sdkPath = path.posix.join('libs', 'my-sdk-sdk');
const execAppOptions = {...getDefaultExecSyncOptions(), cwd: workspacePath};
packageManagerExec({script: 'ng', args: [
expect(() => packageManagerExec({script: 'ng', args: [
'g',
'sdk',
'@my-sdk/sdk',
'--spec-package-name', '@ama-sdk/showcase-sdk',
'--spec-package-path', './openapi.yml',
'--spec-package-registry', registry,
'--spec-package-version', o3rVersion
]}, execAppOptions);
]}, execAppOptions)).not.toThrow();

const diff = getGitDiff(execAppOptions.cwd);
untouchedProjectsPaths.forEach(untouchedProject => {
expect(diff.all.some(file => file.startsWith(path.posix.relative(workspacePath, untouchedProject)))).toBe(false);
});
expect(diff.added).toContain(path.posix.join(sdkPath, 'open-api.yaml'));
expect(diff.added).toContain(path.posix.join(sdkPath, 'src', 'models', 'base', 'category', 'category.ts'));

expect(() => packageManagerInstall(execAppOptions)).not.toThrow();
expect(() => packageManagerRunOnProject('@my-sdk/sdk', isInWorkspace, {script: 'build'}, execAppOptions)).not.toThrow();
Expand Down
2 changes: 1 addition & 1 deletion packages/@o3r/workspace/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
}
},

// Schematics advertizing
// Schematics advertising
(t, c) => {
const workspaceConfig = getWorkspaceConfig(t);
c.logger.info('Your project is now ready, you can start to generate your first packages with one of the following commands:');
Expand Down
8 changes: 8 additions & 0 deletions packages/@o3r/workspace/schematics/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { nxRegisterProjectTasks } from './rules/rules.nx';
import { updateTsConfig } from './rules/update-ts-paths.rule';
import { cleanStandaloneFiles } from './rules/clean-standalone.rule';
import { NodePackageInstallTask, RunSchematicTask } from '@angular-devkit/schematics/tasks';
import {existsSync} from 'node:fs';

/**
* Add an Otter compatible SDK to a monorepo
Expand Down Expand Up @@ -48,6 +49,13 @@ function generateSdkFn(options: NgGenerateSdkSchema): Rule {

const packageManager = getPackageManager({ workspaceConfig });
const specExtension = options.specPackagePath ? path.extname(options.specPackagePath) : '.yaml';
// If spec path is relative to process.cwd, we need to make it relative to the project root
if (options.specPath && !path.isAbsolute(options.specPath)) {
const resolvedPath = path.resolve(process.cwd(), options.specPath);
if (existsSync(resolvedPath)) {
options.specPath = path.relative(path.resolve(targetPath), resolvedPath);
}
}
const specPath = options.specPackageName ? `openapi${specExtension}` : options.specPath;
return chain([
externalSchematic('@ama-sdk/schematics', 'typescript-shell', {
Expand Down
27 changes: 27 additions & 0 deletions packages/@o3r/workspace/testing/mocks/easy-spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
openapi: 3.0.2
info:
description: test
title: test
version: 0.0.0
paths:
/test:
get:
responses:
'200':
description: test
content:
application/json:
schema:
$ref: '#/components/schemas/Category'
components:
schemas:
Category:
type: object
properties:
id:
type: integer
format: int64
example: 10
name:
type: string
example: "test"

0 comments on commit 9c654c1

Please sign in to comment.