From e201376f68a9c3d2052fe810d21bd86e052e372b Mon Sep 17 00:00:00 2001 From: azlam-abdulsalam Date: Tue, 13 Feb 2024 09:24:01 +1100 Subject: [PATCH] fix(markdown): ensure markdown files have config name when multiple releases are handled When multiple release defn is provided, the markdown file should not overwrite, it should provide the data for both the release defns --- packages/sfp-cli/src/commands/changelog/generate.ts | 2 ++ packages/sfp-cli/src/impl/changelog/ChangelogImpl.ts | 6 +++++- .../src/impl/changelog/ChangelogMarkdownGenerator.ts | 4 ++-- packages/sfp-cli/src/impl/deploy/DeployImpl.ts | 2 +- packages/sfp-cli/src/impl/release/ReleaseImpl.ts | 7 +++++++ packages/sfp-cli/src/outputs/FileOutputHandler.ts | 6 ++++++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/sfp-cli/src/commands/changelog/generate.ts b/packages/sfp-cli/src/commands/changelog/generate.ts index 09c568d00..8258a363d 100644 --- a/packages/sfp-cli/src/commands/changelog/generate.ts +++ b/packages/sfp-cli/src/commands/changelog/generate.ts @@ -89,6 +89,8 @@ export default class GenerateChangelog extends SfpCommand { this.flags.forcepush, this.flags.branchname, this.flags.nopush, + false, + undefined, null ); diff --git a/packages/sfp-cli/src/impl/changelog/ChangelogImpl.ts b/packages/sfp-cli/src/impl/changelog/ChangelogImpl.ts index 1326bec90..63b8e6be7 100644 --- a/packages/sfp-cli/src/impl/changelog/ChangelogImpl.ts +++ b/packages/sfp-cli/src/impl/changelog/ChangelogImpl.ts @@ -35,6 +35,7 @@ export default class ChangelogImpl { private branch: string, private nopush:boolean, private isDryRun: boolean, + private releaseConfigName:string, private org?: string ) { this.org = org?.toLowerCase(); @@ -145,7 +146,10 @@ export default class ChangelogImpl { if(this.isDryRun) { const outputHandler:FileOutputHandler = FileOutputHandler.getInstance(); - outputHandler.writeOutput('release-changelog.md',marked(new ChangelogMarkdownGenerator(releaseChangelog, this.workItemUrl, 1, false,true).generate())); + if(this.releaseConfigName){ + outputHandler.appendOutput('release-changelog.md',`# ReleaseConfig: ${this.releaseConfigName}`); + } + outputHandler.appendOutput('release-changelog.md',new ChangelogMarkdownGenerator(releaseChangelog, this.workItemUrl, 1, false,false).generate()); } diff --git a/packages/sfp-cli/src/impl/changelog/ChangelogMarkdownGenerator.ts b/packages/sfp-cli/src/impl/changelog/ChangelogMarkdownGenerator.ts index e5c795b25..c308794c3 100644 --- a/packages/sfp-cli/src/impl/changelog/ChangelogMarkdownGenerator.ts +++ b/packages/sfp-cli/src/impl/changelog/ChangelogMarkdownGenerator.ts @@ -40,10 +40,10 @@ export default class ChangelogMarkdownGenerator { if (!release.names) { payload += `\n\n `; // Create anchor from release hash Id - payload += `# ${release['name']}\n`; + payload += `## ${release['name']}\n`; } else { payload += `\n\n`; // Create anchor from release hash Id - payload += `# ${release.names.join(`/`)}\n `; + payload += `## ${release.names.join(`/`)}\n `; payload += `Cumulative Release Number: ${release.buildNumber} \n\n`; if(release.date && !this.isForWorkItemOnlyOutput) payload += `Matching defintion first created or deployed to an org on: ${release.date}\n ` diff --git a/packages/sfp-cli/src/impl/deploy/DeployImpl.ts b/packages/sfp-cli/src/impl/deploy/DeployImpl.ts index f5340c0ce..6d335d9a6 100644 --- a/packages/sfp-cli/src/impl/deploy/DeployImpl.ts +++ b/packages/sfp-cli/src/impl/deploy/DeployImpl.ts @@ -524,7 +524,7 @@ export default class DeployImpl { } const table = getMarkdownTable(tableData); const outputHandler:FileOutputHandler = FileOutputHandler.getInstance(); - outputHandler.writeOutput('deployment-breakdown.md',table) ; + outputHandler.appendOutput('deployment-breakdown.md',table) ; } function processColoursForAllPackages(pkg) { diff --git a/packages/sfp-cli/src/impl/release/ReleaseImpl.ts b/packages/sfp-cli/src/impl/release/ReleaseImpl.ts index 99eabbf67..076fb8552 100644 --- a/packages/sfp-cli/src/impl/release/ReleaseImpl.ts +++ b/packages/sfp-cli/src/impl/release/ReleaseImpl.ts @@ -18,6 +18,7 @@ import SfpPackage from '../../core/package/SfpPackage'; import SfpPackageBuilder from '../../core/package/SfpPackageBuilder'; import SfpPackageInquirer from '../../core/package/SfpPackageInquirer'; import ReleaseDefinitionSorter from './ReleaseDefinitionSorter'; +import FileOutputHandler from '../../outputs/FileOutputHandler'; export interface ReleaseProps { releaseDefinitions: ReleaseDefinition[]; @@ -72,6 +73,10 @@ export default class ReleaseImpl { this.props.waitTime ); + //Clear up the deployment output + SFPLogger.log(`Clearing deployment output`, LoggerLevel.TRACE, this.logger); + FileOutputHandler.getInstance().deleteOutputFile(`deployment-breakdown.md`); + FileOutputHandler.getInstance().deleteOutputFile(`release-changelog.md`); let deploymentResults = await this.deployArtifacts(sortedReleaseDefns); @@ -126,6 +131,7 @@ export default class ReleaseImpl { this.props.branch, false, this.props.isDryRun, + releaseDefinition.releaseConfigName, this.props.targetOrg ); @@ -254,6 +260,7 @@ export default class ReleaseImpl { devhubUserName: this.props.devhubUserName, }; + FileOutputHandler.getInstance().appendOutput(`deployment-breakdown.md`,`## ReleaseConfig: ${releaseDefinition.releaseConfigName?releaseDefinition.releaseConfigName:""}\n`); let deployImpl: DeployImpl = new DeployImpl(deployProps); let deploymentResult = await deployImpl.exec(); diff --git a/packages/sfp-cli/src/outputs/FileOutputHandler.ts b/packages/sfp-cli/src/outputs/FileOutputHandler.ts index cba026c60..a9436b092 100644 --- a/packages/sfp-cli/src/outputs/FileOutputHandler.ts +++ b/packages/sfp-cli/src/outputs/FileOutputHandler.ts @@ -32,4 +32,10 @@ export default class FileOutputHandler { fs.appendFileSync(path.join(this.containerFolder, fileName), output); } + public deleteOutputFile(fileName: string) { + if (fs.existsSync(path.join(this.containerFolder, fileName))) { + fs.unlinkSync(path.join(this.containerFolder, fileName)); + } + } + } \ No newline at end of file