Skip to content

Commit

Permalink
Enabled coverage, added info step.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslaw-zan committed Sep 18, 2024
1 parent 8b2cd89 commit 528a641
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .circleci/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
at: .out
- run:
name: Merge the code coverage of the framework and features
command: cat .out/combined_framework.info .out/combined_features.info > .out/combined_lcov.info
command: cat .out/combined_framework.info .out/combined_features_batch_n.info > .out/combined_lcov.info
- run:
name: Preparing the environment variables
command: |
Expand Down
48 changes: 42 additions & 6 deletions scripts/ci/generate-circleci-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const IS_COMMUNITY_PR = require( './is-community-pr' );
const CKEDITOR5_ROOT_DIRECTORY = upath.join( __dirname, '..', '..' );
const CIRCLECI_CONFIGURATION_DIRECTORY = upath.join( CKEDITOR5_ROOT_DIRECTORY, '.circleci' );

const FEATURE_BATCH_NAME_PLACEHOLDER = 'cke5_tests_features_batch_n';
const FEATURE_TEST_BATCH_NAME_PLACEHOLDER = 'cke5_tests_features_batch_n';
const FEATURE_COVERAGE_BATCH_FILENAME_PLACEHOLDER = '.out/combined_features_batch_n.info';

/**
* This variable determines amount and size of feature test batches.
Expand Down Expand Up @@ -55,6 +56,21 @@ const prepareCodeCoverageDirectories = () => ( {
}
} );

const listBatchPackages = packageNames => {
const text = [
`A total of ${ packageNames.length } packages will be ran in this test batch:`,
packageNames.map( packageName => ` - ${ packageName }` ).join( '\\n' )
].join( '\\n\\n' );

return {
run: {
when: 'always',
name: 'List of packages running in this test batch',
command: `printf "${ text }"`
}
};
};

const persistToWorkspace = fileName => ( {
persist_to_workspace: {
root: '.out',
Expand Down Expand Up @@ -99,7 +115,10 @@ const persistToWorkspace = fileName => ( {
}, [] );

const featureTestBatchNames = featureTestBatches.map( ( batch, batchIndex ) => {
return FEATURE_BATCH_NAME_PLACEHOLDER.replace( /(?<=_)n$/, batchIndex + 1 );
return FEATURE_TEST_BATCH_NAME_PLACEHOLDER.replace( /(?<=_)n$/, batchIndex + 1 );
} );
const featureCoverageBatchFilenames = featureTestBatches.map( ( batch, batchIndex ) => {
return FEATURE_COVERAGE_BATCH_FILENAME_PLACEHOLDER.replace( /(?<=_)n(?=\.info$)/, batchIndex + 1 );
} );

config.jobs.cke5_tests_framework = {
Expand All @@ -123,9 +142,10 @@ const persistToWorkspace = fileName => ( {
steps: [
...bootstrapCommands(),
prepareCodeCoverageDirectories(),
listBatchPackages( batch ),
...generateTestSteps( batch, {
checkCoverage: true,
coverageFile: '.out/combined_features.info'
coverageFile: featureCoverageBatchFilenames[ batchIndex ]
} ),
'community_verification_command',
persistToWorkspace( 'combined_features.info' )
Expand Down Expand Up @@ -155,13 +175,13 @@ const persistToWorkspace = fileName => ( {
replacePlaceholderBatchNameInArray( workflow.jobs, featureTestBatchNames );

// Replacing the placeholder batch objects in `jobs` arrays in `workflows`.
const placeholderJobIndex = workflow.jobs.findIndex( job => job[ FEATURE_BATCH_NAME_PLACEHOLDER ] );
const placeholderJobIndex = workflow.jobs.findIndex( job => job[ FEATURE_TEST_BATCH_NAME_PLACEHOLDER ] );

if ( placeholderJobIndex === -1 ) {
return;
}

const placeholderJobContent = workflow.jobs[ placeholderJobIndex ][ FEATURE_BATCH_NAME_PLACEHOLDER ];
const placeholderJobContent = workflow.jobs[ placeholderJobIndex ][ FEATURE_TEST_BATCH_NAME_PLACEHOLDER ];
const newBatchJobs = featureTestBatchNames.map( featureTestBatchName => {
return {
[ featureTestBatchName ]: placeholderJobContent
Expand All @@ -171,6 +191,22 @@ const persistToWorkspace = fileName => ( {
workflow.jobs.splice( placeholderJobIndex, 1, ...newBatchJobs );
} );

// Replacing the coverage filename placeholder in coverage steps.
Object.values( config.jobs.cke5_coverage.steps ).forEach( step => {
if ( !( step instanceof Object ) ) {
return;
}

if ( !step.run || !step.run.command ) {
return;
}

step.run.command = step.run.command.replace(
FEATURE_COVERAGE_BATCH_FILENAME_PLACEHOLDER,
featureCoverageBatchFilenames.join( ' ' )
);
} );

if ( IS_COMMUNITY_PR ) {
// CircleCI does not understand custom cloning when a PR comes from the community.
// In such a case, the goal to use the built-in command.
Expand Down Expand Up @@ -235,7 +271,7 @@ function replaceShortCheckout( config, jobName ) {
}

function replacePlaceholderBatchNameInArray( array, featureTestBatchNames ) {
const placeholderIndex = array.findIndex( item => item === FEATURE_BATCH_NAME_PLACEHOLDER );
const placeholderIndex = array.findIndex( item => item === FEATURE_TEST_BATCH_NAME_PLACEHOLDER );

if ( placeholderIndex === -1 ) {
return;
Expand Down

0 comments on commit 528a641

Please sign in to comment.