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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new builders for metadata migration check #1732

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/it-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ jobs:
npx --yes verdaccio --config $GITHUB_WORKSPACE\\.verdaccio\\conf\\config-without-docker.yaml --listen http://127.0.0.1:4873 &
npx --yes wait-on http://127.0.0.1:4873 -t 180000
fi
yarn verdaccio:login
shell: bash
- name: verdaccio login # needed because metadata-check builders have to publish
shell: bash
run: yarn verdaccio:login
- name: Test
id: it-tests
run: yarn test-int
Expand Down
2 changes: 1 addition & 1 deletion .verdaccio/conf/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
registry=http://127.0.0.1:4873
registry=http://127.0.0.1:4873/
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@
},
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": false,
"otter.extract.styling.prefix": "o3r"
"otter.extract.styling.prefix": "o3r",
"typescript.tsserver.experimental.useVsCodeWatcher": false
}
5 changes: 5 additions & 0 deletions packages/@o3r/components/builders.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"implementation": "./builders/component-extractor/",
"schema": "./builders/component-extractor/schema.json",
"description": "Extract the component metadata (configuration and class) from an Otter project"
},
"check-config-migration-metadata": {
"implementation": "./builders/metadata-check/",
"schema": "./builders/metadata-check/schema.json",
"description": "Check for component metadata breaking changes"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { ComponentConfigOutput } from '@o3r/components';
import type { MetadataComparator } from '@o3r/extractors';

/**
* Interface describing a config migration element
*/
export interface MigrationConfigData {
/** Library name */
libraryName: string;
matthieu-crouzet marked this conversation as resolved.
Show resolved Hide resolved
/**
* Configuration name
*/
configName?: string;
/**
* Configuration property name
*/
propertyName?: string;
}

/**
* Returns an array of config metadata from a metadata file.
* To be easily parseable, the properties will be split in separate items of the array.
* e.g. : [{ library: '@o3r/demo', properties: [{name : 'property1', type: 'string'}, {name : 'property2', type: 'number'}] }]
* will become :
* [{ library: '@o3r/demo', properties: [{name : 'property1', type: 'string'}] }, { library: '@o3r/demo', properties: [{name : 'property2', type: 'number'}] }]
*
* @param content Content of a migration metadata files
*/
const getConfigurationArray = (content: ComponentConfigOutput[]): ComponentConfigOutput[] => content.flatMap((config) =>
config.properties.length
? config.properties.map((prop) => ({...config, properties: [prop]}))
: [config]
);

const getConfigurationPropertyName = (config: ComponentConfigOutput) => `${config.library}#${config.name}` + (config.properties.length ? ` ${config.properties[0].name}` : '');

const isMigrationConfigurationDataMatch = (config: ComponentConfigOutput, migrationData: MigrationConfigData) =>
migrationData.configName === config.name
&& migrationData.libraryName === config.library
&& (!migrationData.propertyName || config.properties[0]?.name === migrationData.propertyName);

/**
* Comparator used to compare one version of config metadata with another
*/
export const configMetadataComparator: MetadataComparator<ComponentConfigOutput, MigrationConfigData, ComponentConfigOutput[]> = {
getArray: getConfigurationArray,
getIdentifier: getConfigurationPropertyName,
isMigrationDataMatch: isMigrationConfigurationDataMatch
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './config-metadata-comparison.helper';