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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement JobSummaryService #261

Closed
Ginxo opened this issue Jun 9, 2022 · 0 comments
Closed

implement JobSummaryService #261

Ginxo opened this issue Jun 9, 2022 · 0 comments

Comments

@Ginxo
Copy link
Contributor

Ginxo commented Jun 9, 2022

To generate markdown summary for build-chain
actions/toolkit#1014
A message should be posted on PR (in case it comes from a PR and execution is Github Event) linking the summary

async function generateGithubActionJobSummary(
  buildInfo = {
    definitionFile: "",
    url: "",
    projectStartingJob: "",
    projectTriggeringJob: "",
    projectExecutionSummary: [],
    preExecution: [],
    overwrite: false
  }
) {
  await core.markdownSummary
    .addHeading("Build Chain Execution Summary")
    .addRaw(
      "Summary automatically generated by the [build-chain tool](https://github.com/kiegroup/github-action-build-chain).",
      true
    )
    .addHeading("Local Execution", 1)
    .addRaw(
      "You can copy paste the following commands to locally execute build chain tool.",
      true
    )
    .addCodeBlock(
      `npm i ${pkg.name}@${pkg.version} -g
build-chain-action -df ${buildInfo.definitionFile} build pr -url ${buildInfo.url}`
    )
    .addRaw("", true)
    .addRaw(`**Git Version**: \`${await getGitVersion()}\``, true)
    .addRaw(
      "> **_Notice_**: The `GITHUB_TOKEN` should be set in the environment.",
      true
    )
    .addHeading("Job Information", 1)
    .addRaw("", true)
    .addRaw(
      `* **Project Starting the Job:** [${buildInfo.projectStartingJob}](https://github.com/${buildInfo.projectStartingJob})`,
      true
    )
    .addRaw(
      `* **Project Triggering the Job:** [${buildInfo.projectTriggeringJob}](https://github.com/${buildInfo.projectTriggeringJob})`,
      true
    )
    .addTable([
      [
        { data: "Project", header: true },
        { data: "Base Branch", header: true },
        { data: "Source Branch", header: true },
        { data: "Execution Result", header: true },
        { data: ":timer_clock: Time", header: true }
      ],
      ...buildInfo.projectExecutionSummary.map(pe => [
        pe.project,
        pe.baseBranch,
        `${pe.sourceProject}:${pe.sourceBranch}`,
        pe.executionResult == true
          ? ":heavy_check_mark:"
          : pe.executionResult == false
          ? ":x:"
          : ":no_entry:",
        pe.time ? pe.time : "-"
      ])
    ])
    .addHeading("Execution Diagram", 2)
    .addRaw("", true)
    .addRaw(
      `\`\`\`mermaid
      flowchart LR;
          ${buildInfo.projectExecutionSummary
            .map(
              e =>
                `${e.project}:::${
                  e.executionResult == true
                    ? "okClass"
                    : e.executionResult == false
                    ? "errorClass"
                    : "noEntry"
                }`
            )
            .join("-->")}
          ${buildInfo.projectExecutionSummary
            .map(e => `click ${e.project} 'https://github.com/${e.project}'`)
            .join("\n\t\t\t\t\t")}
          classDef okClass fill:#218838,stroke:#1e7e34,color: #fff,border-radius: 4px
          classDef errorClass fill:#dc3545,stroke:#dc3545,color: #fff,border-radius: 4px
          classDef noEntry fill:#6c757d,stroke:#6c757d,color: #fff,border-radius: 4px
  \`\`\``
    )
    .addEOL();

  if (buildInfo.preExecution && buildInfo.preExecution.length) {
    await core.markdownSummary.addHeading("Preeliminary Execution", 2);
    for await (let e of buildInfo.preExecution) {
      await markdownSummaryCommand(e);
    }
  }

  for await (let pe of buildInfo.projectExecutionSummary) {
    await core.markdownSummary.addHeading(pe.project, 2);
    await core.markdownSummary.addRaw(pe.projectDescription, true);
    await core.markdownSummary.addHeading("Checkout Information", 3);
    await core.markdownSummary.addRaw("", true);
    // TODO: to properly set branch and merged branch values
    await core.markdownSummary.addRaw(
      `* **branch**: [${pe.sourceProject}:${pe.sourceBranch}](https://github.com/${pe.sourceProject})`,
      true
    );
    await core.markdownSummary.addRaw(
      `* **merged branch**: [${pe.project}:${pe.baseBranch}](https://github.com/${pe.project})`,
      true
    );
    if (pe.executions && pe.executions.length) {
      await core.markdownSummary.addHeading("Execution Summary", 3);
      for await (let e of pe.executions) {
        await markdownSummaryCommand(e);
      }
    }
  }
  await core.markdownSummary.write({ overwrite: buildInfo.overwrite });
}
@Ginxo Ginxo created this issue from a note in Build Chain typescript refactoring (To do) Jun 9, 2022
@shubhbapna shubhbapna moved this from To do to In progress in Build Chain typescript refactoring Aug 19, 2022
@shubhbapna shubhbapna self-assigned this Aug 19, 2022
Build Chain typescript refactoring automation moved this from In progress to Done Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants