-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cascading] from release/11.1.0-rc to main (#2084)
<!-- {"currentBranch":"release/11.1.0-rc","targetBranch":"main","bypassReviewers":true,"isConflicting":false} --> ## Cascading from release/11.1.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
Showing
41 changed files
with
861 additions
and
143 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -12,20 +12,19 @@ import { | |
getLatestPackageVersion, | ||
packageManagerAdd, | ||
packageManagerExec, | ||
packageManagerPublish, | ||
packageManagerVersion | ||
packageManagerVersion, | ||
publishToVerdaccio | ||
} from '@o3r/test-helpers'; | ||
import { execFileSync } from 'node:child_process'; | ||
import { promises, readFileSync } from 'node:fs'; | ||
import { join } from 'node:path'; | ||
import { existsSync, promises, readFileSync } from 'node:fs'; | ||
import { dirname, join } from 'node:path'; | ||
import { inc } from 'semver'; | ||
import type { ComponentConfigOutput, ConfigProperty } from '@o3r/components'; | ||
import type { MigrationConfigData } from './helpers/config-metadata-comparison.helper'; | ||
import { getExternalDependenciesVersionRange } from '@o3r/schematics'; | ||
|
||
const baseVersion = '1.2.0'; | ||
const version = '1.3.0'; | ||
const migrationDataFileName = `MIGRATION-${version}.json`; | ||
const migrationDataFileName = `migration-scripts/MIGRATION-${version}.json`; | ||
const metadataFileName = 'component.config.metadata.json'; | ||
|
||
const defaultMigrationData: MigrationFile<MigrationConfigData> = { | ||
|
@@ -184,8 +183,11 @@ const newConfigurationMetadata: ComponentConfigOutput[] = [ | |
createConfig('@new/lib9', 'MyConfig9', ['prop9']) | ||
]; | ||
|
||
function writeFileAsJSON(path: string, content: object) { | ||
return promises.writeFile(path, JSON.stringify(content), { encoding: 'utf8' }); | ||
async function writeFileAsJSON(path: string, content: object) { | ||
if (!existsSync(dirname(path))) { | ||
await promises.mkdir(dirname(path), {recursive: true}); | ||
} | ||
await promises.writeFile(path, JSON.stringify(content), { encoding: 'utf8' }); | ||
} | ||
|
||
const initTest = async ( | ||
|
@@ -197,8 +199,8 @@ const initTest = async ( | |
const { workspacePath, appName, applicationPath, o3rVersion, isYarnTest } = o3rEnvironment.testEnvironment; | ||
const execAppOptions = { ...getDefaultExecSyncOptions(), cwd: applicationPath }; | ||
const execAppOptionsWorkspace = { ...getDefaultExecSyncOptions(), cwd: workspacePath }; | ||
packageManagerAdd(`@o3r/components@${o3rVersion}`, execAppOptionsWorkspace); | ||
packageManagerAdd(`@o3r/extractors@${o3rVersion}`, execAppOptionsWorkspace); | ||
packageManagerExec({script: 'ng', args: ['add', `@o3r/extractors@${o3rVersion}`, '--skip-confirmation', '--project-name', appName]}, execAppOptionsWorkspace); | ||
packageManagerExec({script: 'ng', args: ['add', `@o3r/components@${o3rVersion}`, '--skip-confirmation', '--project-name', appName]}, execAppOptionsWorkspace); | ||
const versions = getExternalDependenciesVersionRange([ | ||
'semver', | ||
...(isYarnTest ? [ | ||
|
@@ -212,6 +214,7 @@ const initTest = async ( | |
warn: jest.fn() | ||
} as any); | ||
Object.entries(versions).forEach(([pkgName, pkgVersion]) => packageManagerAdd(`${pkgName}@${pkgVersion}`, execAppOptionsWorkspace)); | ||
const npmIgnorePath = join(applicationPath, '.npmignore'); | ||
const packageJsonPath = join(applicationPath, 'package.json'); | ||
const angularJsonPath = join(workspacePath, 'angular.json'); | ||
const metadataPath = join(applicationPath, metadataFileName); | ||
|
@@ -223,7 +226,7 @@ const initTest = async ( | |
builder: '@o3r/components:check-config-migration-metadata', | ||
options: { | ||
allowBreakingChanges, | ||
migrationDataPath: `**/MIGRATION-*.json` | ||
migrationDataPath: `apps/test-app/migration-scripts/MIGRATION-*.json` | ||
} | ||
}; | ||
angularJson.projects[appName].architect['check-metadata'] = builderConfig; | ||
|
@@ -238,6 +241,7 @@ const initTest = async ( | |
private: false | ||
}; | ||
await writeFileAsJSON(packageJsonPath, packageJson); | ||
await promises.writeFile(npmIgnorePath, ''); | ||
|
||
// Set old metadata and publish to registry | ||
await writeFileAsJSON(metadataPath, previousConfigurationMetadata); | ||
|
@@ -254,7 +258,7 @@ const initTest = async ( | |
const args = getPackageManager() === 'yarn' ? [] : ['--no-git-tag-version', '-f']; | ||
packageManagerVersion(bumpedVersion, args, execAppOptions); | ||
|
||
packageManagerPublish([], execAppOptions); | ||
await publishToVerdaccio(execAppOptions); | ||
|
||
// Override with new metadata for comparison | ||
await writeFileAsJSON(metadataPath, newMetadata); | ||
|
@@ -264,27 +268,6 @@ const initTest = async ( | |
}; | ||
|
||
describe('check metadata migration', () => { | ||
beforeEach(async () => { | ||
const { applicationPath } = o3rEnvironment.testEnvironment; | ||
const execAppOptions = { ...getDefaultExecSyncOptions(), cwd: applicationPath, shell: true }; | ||
await promises.copyFile( | ||
join(__dirname, '..', '..', '..', '..', '..', '.verdaccio', 'conf', '.npmrc'), | ||
join(applicationPath, '.npmrc') | ||
); | ||
execFileSync('npx', [ | ||
'--yes', | ||
'npm-cli-login', | ||
'-u', | ||
'verdaccio', | ||
'-p', | ||
'verdaccio', | ||
'-e', | ||
'[email protected]', | ||
'-r', | ||
'http://127.0.0.1:4873' | ||
], execAppOptions); | ||
}); | ||
|
||
test('should not throw', async () => { | ||
await initTest( | ||
true, | ||
|
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/angular/angular-cli/master/packages/angular_devkit/architect/src/builders-schema.json", | ||
"builders": { | ||
"aggregate-migration-scripts": { | ||
"implementation": "./builders/aggregate-migration-scripts/", | ||
"schema": "./builders/aggregate-migration-scripts/schema.json", | ||
"description": "Aggregate migration scripts" | ||
} | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
packages/@o3r/extractors/builders/aggregate-migration-scripts/index.it.spec.ts
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,96 @@ | ||
/** | ||
* Test environment exported by O3rEnvironment, must be first line of the file | ||
* @jest-environment @o3r/test-helpers/jest-environment | ||
* @jest-environment-o3r-app-folder test-app-extractors-aggregate-migration-scripts | ||
*/ | ||
const o3rEnvironment = globalThis.o3rEnvironment; | ||
|
||
import { | ||
getDefaultExecSyncOptions, getLatestPackageVersion, | ||
packageManagerAdd, | ||
packageManagerExec, | ||
publishToVerdaccio | ||
} from '@o3r/test-helpers'; | ||
import { promises, readFileSync } from 'node:fs'; | ||
import { join, relative } from 'node:path'; | ||
import { inc } from 'semver'; | ||
|
||
const migrationDataMocksPath = join(__dirname, '..', '..', 'testing', 'mocks', 'migration-scripts'); | ||
|
||
function writeFileAsJSON(path: string, content: object) { | ||
return promises.writeFile(path, JSON.stringify(content), { encoding: 'utf8' }); | ||
} | ||
|
||
async function expectFileToMatchMock(realPath: string, mockPath: string) { | ||
expect(await promises.readFile(realPath, {encoding: 'utf8'})).toEqual(await promises.readFile(mockPath, {encoding: 'utf8'})); | ||
} | ||
|
||
async function publishLibrary(cwd: string) { | ||
const libraryPath = join(cwd, 'mylib'); | ||
const execAppOptions = {...getDefaultExecSyncOptions(), cwd: libraryPath}; | ||
const libMigrationDataPath = join(libraryPath, 'migration-scripts'); | ||
await promises.mkdir(libMigrationDataPath, {recursive: true}); | ||
|
||
let latestVersion; | ||
try { | ||
latestVersion = getLatestPackageVersion('@o3r/my-lib', { | ||
...execAppOptions, | ||
registry: o3rEnvironment.testEnvironment.registry | ||
}); | ||
} catch { | ||
latestVersion = '4.0.0'; | ||
} | ||
const bumpedVersion = inc(latestVersion, 'patch'); | ||
|
||
await promises.writeFile(join(libraryPath, 'package.json'), `{"name": "@o3r/my-lib", "version": "${bumpedVersion}"}`); | ||
await promises.copyFile(join(migrationDataMocksPath, 'lib', 'migration-2.0.json'), join(libMigrationDataPath, 'migration-2.0.json')); | ||
await promises.copyFile(join(migrationDataMocksPath, 'lib', 'migration-2.5.json'), join(libMigrationDataPath, 'migration-2.5.json')); | ||
await promises.copyFile(join(migrationDataMocksPath, 'lib', 'migration-4.0.json'), join(libMigrationDataPath, 'migration-4.0.json')); | ||
|
||
await publishToVerdaccio(execAppOptions); | ||
} | ||
|
||
describe('aggregate migration scripts', () => { | ||
let migrationDataSrcPath: string; | ||
let migrationDataDestPath: string; | ||
|
||
beforeEach(async () => { | ||
const { workspacePath, appName, applicationPath } = o3rEnvironment.testEnvironment; | ||
const angularJsonPath = join(workspacePath, 'angular.json'); | ||
migrationDataSrcPath = join(applicationPath, 'migration-scripts', 'src'); | ||
migrationDataDestPath = join(applicationPath, 'migration-scripts', 'dist'); | ||
// Add builder options | ||
const angularJson = JSON.parse(readFileSync(angularJsonPath, { encoding: 'utf8' }).toString()); | ||
const builderConfig = { | ||
builder: '@o3r/extractors:aggregate-migration-scripts', | ||
options: { | ||
migrationDataPath: relative(workspacePath, `${migrationDataSrcPath}/migration-*.json`).replace(/[\\/]/g, '/'), | ||
outputDirectory: relative(workspacePath, migrationDataDestPath).replace(/[\\/]/g, '/') | ||
} | ||
}; | ||
angularJson.projects[appName].architect['aggregate-migration-scripts'] = builderConfig; | ||
await writeFileAsJSON(angularJsonPath, angularJson); | ||
|
||
await publishLibrary(workspacePath); | ||
}); | ||
|
||
test('should create migration scripts including lib content', async () => { | ||
const { workspacePath, appName, applicationPath, o3rExactVersion } = o3rEnvironment.testEnvironment; | ||
const execAppOptions = { ...getDefaultExecSyncOptions(), cwd: applicationPath }; | ||
const execAppOptionsWorkspace = { ...getDefaultExecSyncOptions(), cwd: workspacePath }; | ||
|
||
packageManagerExec({script: 'ng', args: ['add', `@o3r/extractors@${o3rExactVersion}`, '--skip-confirmation', '--project-name', appName]}, execAppOptionsWorkspace); | ||
packageManagerAdd('@o3r/my-lib', execAppOptionsWorkspace); | ||
packageManagerAdd('@o3r/my-lib', execAppOptions); | ||
|
||
await promises.mkdir(migrationDataSrcPath, {recursive: true}); | ||
await promises.copyFile(join(migrationDataMocksPath, 'migration-1.0.json'), join(migrationDataSrcPath, 'migration-1.0.json')); | ||
await promises.copyFile(join(migrationDataMocksPath, 'migration-1.5.json'), join(migrationDataSrcPath, 'migration-1.5.json')); | ||
await promises.copyFile(join(migrationDataMocksPath, 'migration-2.0.json'), join(migrationDataSrcPath, 'migration-2.0.json')); | ||
|
||
expect(() => packageManagerExec({ script: 'ng', args: ['run', `${appName}:aggregate-migration-scripts`] }, execAppOptionsWorkspace)).not.toThrow(); | ||
await expectFileToMatchMock(`${migrationDataDestPath}/migration-1.0.json`, `${migrationDataMocksPath}/expected/migration-1.0.json`); | ||
await expectFileToMatchMock(`${migrationDataDestPath}/migration-1.5.json`, `${migrationDataMocksPath}/expected/migration-1.5.json`); | ||
await expectFileToMatchMock(`${migrationDataDestPath}/migration-2.0.json`, `${migrationDataMocksPath}/expected/migration-2.0.json`); | ||
}); | ||
}); |
Oops, something went wrong.