Skip to content

Commit

Permalink
⚡ Add licenses preview to job output
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Apr 24, 2023
1 parent 9f2af3f commit 61b94e7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 13 deletions.
3 changes: 3 additions & 0 deletions common/qodana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export const FAIL_THRESHOLD_OUTPUT =
'The number of problems exceeds the failThreshold'
export const QODANA_SARIF_NAME = 'qodana.sarif.json'
export const QODANA_REPORT_URL_NAME = 'qodana.cloud'

export const QODANA_LICENSES_MD = 'thirdPartySoftwareList.md'
export const QODANA_LICENSES_JSON = 'thirdPartySoftwareList.json'
export const EXECUTABLE = 'qodana'
export const VERSION = version
export function getQodanaSha256(arch: string, platform: string): string {
Expand Down
3 changes: 3 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version: "1.0"
linter: jetbrains/qodana-js:latest
bootstrap: cd common && npm install && cd ../scan && npm install && cd ../vsts && npm install
plugins:
- id: com.intellij.grazie.pro
profile:
name: qodana.recommended
exclude:
Expand Down
32 changes: 28 additions & 4 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,8 @@ var qodana_exports = {};
__export(qodana_exports, {
EXECUTABLE: () => EXECUTABLE,
FAIL_THRESHOLD_OUTPUT: () => FAIL_THRESHOLD_OUTPUT,
QODANA_LICENSES_JSON: () => QODANA_LICENSES_JSON,
QODANA_LICENSES_MD: () => QODANA_LICENSES_MD,
QODANA_REPORT_URL_NAME: () => QODANA_REPORT_URL_NAME,
QODANA_SARIF_NAME: () => QODANA_SARIF_NAME,
QodanaExitCode: () => QodanaExitCode,
Expand Down Expand Up @@ -2890,7 +2892,7 @@ function sha256sum(file) {
function getQodanaSha256MismatchMessage(expected, actual) {
return `Downloaded Qodana CLI binary is corrupted. Expected SHA-256 checksum: ${expected}, actual checksum: ${actual}`;
}
var import_crypto, import_fs, SUPPORTED_PLATFORMS, SUPPORTED_ARCHS, FAIL_THRESHOLD_OUTPUT, QODANA_SARIF_NAME, QODANA_REPORT_URL_NAME, EXECUTABLE, VERSION, QodanaExitCode;
var import_crypto, import_fs, SUPPORTED_PLATFORMS, SUPPORTED_ARCHS, FAIL_THRESHOLD_OUTPUT, QODANA_SARIF_NAME, QODANA_REPORT_URL_NAME, QODANA_LICENSES_MD, QODANA_LICENSES_JSON, EXECUTABLE, VERSION, QodanaExitCode;
var init_qodana = __esm({
"../common/qodana.ts"() {
init_cli();
Expand All @@ -2901,6 +2903,8 @@ var init_qodana = __esm({
FAIL_THRESHOLD_OUTPUT = "The number of problems exceeds the failThreshold";
QODANA_SARIF_NAME = "qodana.sarif.json";
QODANA_REPORT_URL_NAME = "qodana.cloud";
QODANA_LICENSES_MD = "thirdPartySoftwareList.md";
QODANA_LICENSES_JSON = "thirdPartySoftwareList.json";
EXECUTABLE = "qodana";
VERSION = version;
__name(getQodanaSha256, "getQodanaSha256");
Expand Down Expand Up @@ -63347,8 +63351,12 @@ ${body}
return Array.from(problems.entries()).sort((a, b) => b[1] - a[1]).map(([title, count]) => `| ${title} | ${level} | ${count} |`).join("\n");
}
__name(getRowsByLevel, "getRowsByLevel");
function getSummary(annotations, reportUrl) {
function getSummary(annotations, licensesInfo, reportUrl) {
const contactBlock = wrapToToggleBlock("Contact Qodana team", SUMMARY_MISC);
let licensesBlock = "";
if (licensesInfo !== "") {
licensesBlock = wrapToToggleBlock("Dependencies licenses", licensesInfo);
}
if (annotations.length === 0) {
return [
`# ${QODANA_CHECK_NAME}`,
Expand All @@ -63357,6 +63365,7 @@ ${body}
"",
"No problems found according to the checks applied",
getViewReportText(reportUrl),
licensesBlock,
contactBlock
].join("\n");
}
Expand All @@ -63374,6 +63383,7 @@ ${body}
].filter((e) => e !== "").join("\n"),
"",
getViewReportText(reportUrl),
licensesBlock,
contactBlock
].join("\n");
}
Expand Down Expand Up @@ -63454,8 +63464,22 @@ ${body}
}
}
}
const reportUrl = fs.readFileSync(`${resultsDir}/${qodana_12.QODANA_REPORT_URL_NAME}`, { encoding: "utf8" });
yield core2.summary.addRaw(getSummary(problems, reportUrl)).write();
let reportUrl = "";
const reportUrlFile = `${resultsDir}/${qodana_12.QODANA_REPORT_URL_NAME}`;
if (fs.existsSync(reportUrlFile)) {
reportUrl = fs.readFileSync(`${resultsDir}/${qodana_12.QODANA_REPORT_URL_NAME}`, {
encoding: "utf8"
});
}
let licensesInfo = "";
const licensesJson = `${resultsDir}/projectStructure/${qodana_12.QODANA_LICENSES_JSON}`;
if (fs.existsSync(licensesJson)) {
const licenses = JSON.parse(fs.readFileSync(licensesJson, { encoding: "utf8" }));
if (licenses.length > 0) {
licensesInfo = fs.readFileSync(`${resultsDir}/projectStructure/${qodana_12.QODANA_LICENSES_MD}`, { encoding: "utf8" });
}
}
yield core2.summary.addRaw(getSummary(problems, licensesInfo, reportUrl)).write();
} catch (error) {
core2.warning(`Failed to publish annotations \u2013 ${error.message}`);
}
Expand Down
52 changes: 44 additions & 8 deletions scan/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import type {Log, Result, Tool} from 'sarif'
import {QODANA_REPORT_URL_NAME, QODANA_SARIF_NAME} from '../../common/qodana'
import {
QODANA_LICENSES_JSON,
QODANA_LICENSES_MD,
QODANA_REPORT_URL_NAME,
QODANA_SARIF_NAME
} from '../../common/qodana'
import {AnnotationProperties} from '@actions/core'

const QODANA_CHECK_NAME = 'Qodana'
Expand Down Expand Up @@ -67,11 +72,19 @@ function getRowsByLevel(annotations: Annotation[], level: string): string {
/**
* Generates action summary string of annotations.
* @param annotations The annotations to generate the summary from.
* @param licensesInfo The licenses Markdown text to generate the summary from.
* @param reportUrl The URL to the Qodana report.
*/
function getSummary(annotations: Annotation[], reportUrl: string): string {
function getSummary(
annotations: Annotation[],
licensesInfo: string,
reportUrl: string
): string {
const contactBlock = wrapToToggleBlock('Contact Qodana team', SUMMARY_MISC)

let licensesBlock = ''
if (licensesInfo !== '') {
licensesBlock = wrapToToggleBlock('Dependencies licenses', licensesInfo)
}
if (annotations.length === 0) {
return [
`# ${QODANA_CHECK_NAME}`,
Expand All @@ -80,6 +93,7 @@ function getSummary(annotations: Annotation[], reportUrl: string): string {
'',
'No problems found according to the checks applied',
getViewReportText(reportUrl),
licensesBlock,
contactBlock
].join('\n')
}
Expand Down Expand Up @@ -111,6 +125,7 @@ function getSummary(annotations: Annotation[], reportUrl: string): string {
.join('\n'),
'',
getViewReportText(reportUrl),
licensesBlock,
contactBlock
].join('\n')
}
Expand Down Expand Up @@ -221,11 +236,32 @@ export async function publishOutput(
}
}
}
const reportUrl = fs.readFileSync(
`${resultsDir}/${QODANA_REPORT_URL_NAME}`,
{encoding: 'utf8'}
)
await core.summary.addRaw(getSummary(problems, reportUrl)).write()

let reportUrl = ''
const reportUrlFile = `${resultsDir}/${QODANA_REPORT_URL_NAME}`
if (fs.existsSync(reportUrlFile)) {
reportUrl = fs.readFileSync(`${resultsDir}/${QODANA_REPORT_URL_NAME}`, {
encoding: 'utf8'
})
}

let licensesInfo = ''
const licensesJson = `${resultsDir}/projectStructure/${QODANA_LICENSES_JSON}`
if (fs.existsSync(licensesJson)) {
const licenses = JSON.parse(
fs.readFileSync(licensesJson, {encoding: 'utf8'})
)
if (licenses.length > 0) {
licensesInfo = fs.readFileSync(
`${resultsDir}/projectStructure/${QODANA_LICENSES_MD}`,
{encoding: 'utf8'}
)
}
}

await core.summary
.addRaw(getSummary(problems, licensesInfo, reportUrl))
.write()
} catch (error) {
core.warning(`Failed to publish annotations – ${(error as Error).message}`)
}
Expand Down
6 changes: 5 additions & 1 deletion vsts/QodanaScan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var qodana_exports = {};
__export(qodana_exports, {
EXECUTABLE: () => EXECUTABLE,
FAIL_THRESHOLD_OUTPUT: () => FAIL_THRESHOLD_OUTPUT,
QODANA_LICENSES_JSON: () => QODANA_LICENSES_JSON,
QODANA_LICENSES_MD: () => QODANA_LICENSES_MD,
QODANA_REPORT_URL_NAME: () => QODANA_REPORT_URL_NAME,
QODANA_SARIF_NAME: () => QODANA_SARIF_NAME,
QodanaExitCode: () => QodanaExitCode,
Expand Down Expand Up @@ -147,7 +149,7 @@ function sha256sum(file) {
function getQodanaSha256MismatchMessage(expected, actual) {
return `Downloaded Qodana CLI binary is corrupted. Expected SHA-256 checksum: ${expected}, actual checksum: ${actual}`;
}
var import_crypto, import_fs, SUPPORTED_PLATFORMS, SUPPORTED_ARCHS, FAIL_THRESHOLD_OUTPUT, QODANA_SARIF_NAME, QODANA_REPORT_URL_NAME, EXECUTABLE, VERSION, QodanaExitCode;
var import_crypto, import_fs, SUPPORTED_PLATFORMS, SUPPORTED_ARCHS, FAIL_THRESHOLD_OUTPUT, QODANA_SARIF_NAME, QODANA_REPORT_URL_NAME, QODANA_LICENSES_MD, QODANA_LICENSES_JSON, EXECUTABLE, VERSION, QodanaExitCode;
var init_qodana = __esm({
"../common/qodana.ts"() {
init_cli();
Expand All @@ -158,6 +160,8 @@ var init_qodana = __esm({
FAIL_THRESHOLD_OUTPUT = "The number of problems exceeds the failThreshold";
QODANA_SARIF_NAME = "qodana.sarif.json";
QODANA_REPORT_URL_NAME = "qodana.cloud";
QODANA_LICENSES_MD = "thirdPartySoftwareList.md";
QODANA_LICENSES_JSON = "thirdPartySoftwareList.json";
EXECUTABLE = "qodana";
VERSION = version;
QodanaExitCode = /* @__PURE__ */ ((QodanaExitCode2) => {
Expand Down

0 comments on commit 61b94e7

Please sign in to comment.