Skip to content

Commit

Permalink
feat(markdown): add additional markdown outptus in deploy build and v…
Browse files Browse the repository at this point in the history
…alidate

This feature adds markdown output in .sfpowerscripts/output folder where pipelines could then
consume it to add it to the PR or issue
  • Loading branch information
azlam-abdulsalam committed Aug 16, 2023
1 parent 9194f97 commit b8f327d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 22 deletions.
44 changes: 36 additions & 8 deletions packages/sfpowerscripts-cli/src/impl/deploy/DeployImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,8 @@ export default class DeployImpl {

//Insane Hack
//TODO: Export the value to the caller
if(this.props.isDryRun)
{
printDeploymentBreakDownInMarkdown();
}


printDeploymentBreakDownInMarkdown();

groupSection.end();

groupSection = new GroupConsoleLogs(`Packages to be deployed`, this.props.logger).begin();
Expand Down Expand Up @@ -513,7 +509,8 @@ export default class DeployImpl {
tableData.table.body.push(getRowForMarkdownTable(pkg));
}
const table = getMarkdownTable(tableData);
const pathToDeploymentBreakDownFile = `.sfpowerscripts/logs/deployment-breakdown.md`;
const pathToDeploymentBreakDownFile = `.sfpowerscripts/outputs/deployment-breakdown.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToDeploymentBreakDownFile);
fs.writeFileSync(pathToDeploymentBreakDownFile, table);
}
Expand Down Expand Up @@ -542,7 +539,7 @@ export default class DeployImpl {
}

return [packageName, versionNumber, versionInstalledInOrg, isPackageInstalled];
}
}


function getRowForMarkdownTable(pkg) {
Expand Down Expand Up @@ -576,6 +573,37 @@ export default class DeployImpl {
});
SFPLogger.log(table.toString(), LoggerLevel.INFO, this.props.logger);
groupSection.end();

printDeploymentBreakDownInMarkdown();


function printDeploymentBreakDownInMarkdown() {
let tableData = {
table: {
head: [
'Package',
'Version to be installed'
],
body: []
},
alignment: [Align.Left, Align.Left, Align.Left,Align.Right],
};
for (const pkg of queue) {
tableData.table.body.push(getRowForMarkdownTable(pkg));
}

const pathToDeploymentBreakDownFile = `.sfpowerscripts/outputs/deployment-breakdown.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.appendFileSync(pathToDeploymentBreakDownFile, `Please find the packages that will be deployed below`);
fs.createFileSync(pathToDeploymentBreakDownFile);
fs.appendFileSync(pathToDeploymentBreakDownFile, `\n\n${getMarkdownTable(tableData)}`);
}

function getRowForMarkdownTable(pkg) {
let packageName = pkg.packageName;
let versionNumber = pkg.versionNumber;
return [packageName, versionNumber];
}
}

private async filterByPackagesInstalledInTheOrg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,16 @@ export default class BuildImpl {
try {
// Append error to log file
fs.appendFileSync(`.sfpowerscripts/logs/${pkg}`, reason.message, "utf8");

let data = fs.readFileSync(`.sfpowerscripts/logs/${pkg}`, "utf8");

const pathToMarkDownFile = `.sfpowerscripts/outputs/build-error-info.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToMarkDownFile);
fs.appendFileSync(pathToMarkDownFile, `Please find the errors observed during build\n\n`);
fs.appendFileSync(pathToMarkDownFile, `## ${pkg}\n\n`);
fs.appendFileSync(pathToMarkDownFile, data);


SFPLogger.log(data);
} catch (e) {
SFPLogger.log(`Unable to display logs for pkg ${pkg}`);
Expand Down
9 changes: 7 additions & 2 deletions packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook {

//Print Org Info for validateAgainstOrg modes
//TODO: Not ideal need to unify sfpOrg and scratchOrg and then make this a global method
if (this.props.orgInfo && this.props.validateAgainst === ValidateAgainst.PROVIDED_ORG)
if (this.props.orgInfo && this.props.validateAgainst === ValidateAgainst.PROVIDED_ORG){
OrgInfoDisplayer.printOrgInfo(this.orgAsSFPOrg);
OrgInfoDisplayer.writeOrgInfoToMarkDown(this.orgAsSFPOrg);
}


//Fetch Artifacts in the org
Expand Down Expand Up @@ -610,7 +612,10 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook {
this.logger,
);

if (displayOrgInfo) OrgInfoDisplayer.printScratchOrgInfo(scratchOrg);
if (displayOrgInfo) {
OrgInfoDisplayer.printScratchOrgInfo(scratchOrg);
OrgInfoDisplayer.writeScratchOrgInfoToMarkDown(scratchOrg);
}

this.getCurrentRemainingNumberOfOrgsInPoolAndReport(scratchOrg.tag);
break;
Expand Down
78 changes: 67 additions & 11 deletions packages/sfpowerscripts-cli/src/ui/OrgInfoDisplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { LoggerLevel } from "@salesforce/core";
import GroupConsoleLogs from "./GroupConsoleLogs";
import { COLON_MIDDLE_BORDER_TABLE } from "./TableConstants";
import ScratchOrg from "@dxatscale/sfpowerscripts.core/lib/scratchorg/ScratchOrg";
import { Align, getMarkdownTable } from "markdown-table-ts";
import fs from "fs-extra";

export default class OrgInfoDisplayer
{
export default class OrgInfoDisplayer {

public static printScratchOrgInfo(scratchOrg:ScratchOrg): void {
public static printScratchOrgInfo(scratchOrg: ScratchOrg): void {
let groupSection = new GroupConsoleLogs(`Display Org Info`).begin();

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.printHeaderLine('', COLOR_HEADER, LoggerLevel.INFO);
SFPLogger.log(COLOR_KEY_VALUE(`-- Org Details:--`));
const table = new Table({
chars: COLON_MIDDLE_BORDER_TABLE,
Expand Down Expand Up @@ -60,16 +61,49 @@ export default class OrgInfoDisplayer
LoggerLevel.INFO,
);

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.printHeaderLine('', COLOR_HEADER, LoggerLevel.INFO);




groupSection.end();
}
}

public static writeScratchOrgInfoToMarkDown(scratchOrg: ScratchOrg): void {
const pathToMarkDownFile = `.sfpowerscripts/outputs/org-info.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToMarkDownFile);
fs.appendFileSync(pathToMarkDownFile, `Please find the validation org details below`);
let tableData = {
table: {
head: [
'Org Details',
'Incoming Version',
],
body: []
},
alignment: [Align.Left, Align.Left, Align.Left,Align.Right],
};
tableData.table.body.push([`Org Id`,scratchOrg.orgId]);
tableData.table.body.push([`Instance URL`,scratchOrg.instanceURL]);
tableData.table.body.push([`Username`,scratchOrg.username]);
tableData.table.body.push([`Password`,scratchOrg.password]);
tableData.table.body.push([`Auth URL`,scratchOrg.sfdxAuthUrl]);
tableData.table.body.push([`Expiry`,scratchOrg.expiryDate]);
fs.appendFileSync(pathToMarkDownFile, `\n\n${getMarkdownTable(tableData)}`);

fs.appendFileSync(pathToMarkDownFile,
`You may use the following commands to authenticate to the org`,);
fs.appendFileSync(pathToMarkDownFile,`cat ${scratchOrg.sfdxAuthUrl} > ./authfile`);
fs.appendFileSync(pathToMarkDownFile,`sfdx auth sfdxurl store --sfdxurlfile authfile`);
fs.appendFileSync(pathToMarkDownFile,`sfdx force org open --u ${scratchOrg.username}`);

}

public static printOrgInfo(org:SFPOrg): void {
public static printOrgInfo(org: SFPOrg): void {
let groupSection = new GroupConsoleLogs(`Display Org Info`).begin();

SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);
SFPLogger.printHeaderLine('', COLOR_HEADER, LoggerLevel.INFO);
SFPLogger.log(COLOR_KEY_VALUE(`-- Org Details:--`));
const table = new Table({
chars: COLON_MIDDLE_BORDER_TABLE,
Expand All @@ -90,11 +124,33 @@ export default class OrgInfoDisplayer
]);
SFPLogger.log(table.toString(), LoggerLevel.INFO);



SFPLogger.printHeaderLine('',COLOR_HEADER,LoggerLevel.INFO);

SFPLogger.printHeaderLine('', COLOR_HEADER, LoggerLevel.INFO);

groupSection.end();
}
}

public static writeOrgInfoToMarkDown(org: SFPOrg): void {
const pathToMarkDownFile = `.sfpowerscripts/outputs/org-info.md`;
fs.mkdirpSync(".sfpowerscripts/outputs");
fs.createFileSync(pathToMarkDownFile);
fs.appendFileSync(pathToMarkDownFile, `Please find the validation org details below`);
let tableData = {
table: {
head: [
'Org Details',
'Incoming Version',
],
body: []
},
alignment: [Align.Left, Align.Left, Align.Left,Align.Right],
};
tableData.table.body.push([`Org Id`,org.getOrgId()]);
tableData.table.body.push([`Username`,org.getUsername()]);
tableData.table.body.push([`Login to the org`, `[Click Here](${org.getConnection().getAuthInfo().getOrgFrontDoorUrl()})`]);
fs.appendFileSync(pathToMarkDownFile, `\n\n${getMarkdownTable(tableData)}`);

}

}

0 comments on commit b8f327d

Please sign in to comment.