Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions actions/ops-build-reporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# OPS Build Reporter GitHub Action

This action updates a pull request body with preview links extracted from the OpenPublishing.Build report and a link to the build report itself. Optionally, it also annotates changed files with any build suggestions, warnings, or errors.

## Usage

```yml
on: [pull_request_target]

jobs:
ops_build_reporter_job:
permissions:
checks: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: dotnet/docs-tools/actions/ops-build-reporter@main
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
max_wait_time_minutes: 20
annotate_file_warnings: true
```

When `annotate_file_warnings` is enabled, the workflow token requires `checks: write` permissions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ${PREVIEW_TABLE_END}`;
);
});

it("extracts errors and warnings from validated file details", () => {
it("extracts errors, warnings, and suggestions from validated file details", () => {
const html = `
<table>
<tr>
Expand All @@ -150,7 +150,10 @@ ${PREVIEW_TABLE_END}`;
</tr>
<tr>
<td>articles/overview.md</td><td>Warning</td><td>View</td>
<td>Line 92: [Warning] Duplicate heading: 'Next step'.</td>
<td>
Line 92: [Warning] Duplicate heading: 'Next step'.<br />
Line 97: [Suggestion] Consider adding a description.
</td>
</tr>
</table>`;

Expand All @@ -175,6 +178,12 @@ ${PREVIEW_TABLE_END}`;
severity: "Warning",
message: "Duplicate heading: 'Next step'.",
},
{
path: "articles/overview.md",
line: 97,
severity: "Suggestion",
message: "Consider adding a description.",
},
]);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: 'Preview link generator'
description: 'Waits for OpenPublishing.Build to complete, then extracts preview links from the OPS build report and updates the pull request body.'
name: 'OPS Build Reporter'
description: 'Inserts preview links and the build report link into the pull request body. Optionally, annotates the changed files with any build suggestions, warnings, or errors.'
author: 'Genevieve Warren'
inputs:
repo_token:
description: 'The GITHUB_TOKEN secret. Requires pull-requests: write and, when annotate_file_warnings is true, checks: write.'
required: true
annotate_file_warnings:
description: 'Whether to annotate changed lines on the Files changed tab with errors and warnings from the build report.'
default: 'false'
collapsible_after:
description: 'The number at which the automated preview table defaults as collapsed but expandable, using the HTML summary and details elements.'
default: '12'
Expand All @@ -14,9 +17,6 @@ inputs:
max_wait_time_minutes:
description: 'The maximum number of minutes to wait for the OpenPublishing.Build status check to complete.'
default: '20'
annotate_file_warnings:
description: 'Whether to annotate changed lines on the Files changed tab with errors and warnings from the build report.'
default: 'false'
runs:
using: 'node16'
main: 'dist/index.js'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions actions/ops-build-reporter/dist/index.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "preview-link-generator-action",
"name": "ops-build-reporter-action",
"version": "3.0.0",
"private": true,
"description": "Preview link generator for Open Publishing Services (OPS)-enabled docs repos. Waits for OpenPublishing.Build to complete, then extracts preview links from the OPS build report and updates the pull request body.",
"description": "Helper for Open Publishing Services (OPS)-enabled docs repos. Waits for the OPS build to complete, then inserts preview links and the build report link into the pull request body. Optionally, annotates the changed files with any build suggestions, warnings, or errors.",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type StatusCheck = {
type BuildDiagnostic = {
path: string;
line: number;
severity: "Error" | "Warning";
severity: "Error" | "Warning" | "Suggestion";
message: string;
};

Expand Down Expand Up @@ -368,17 +368,20 @@ function extractDiagnosticsFromBuildReport(html: string): BuildDiagnostic[] {
}

const detailPattern =
/Line\s+(\d+)\s*:\s*\[(Error|Warning)\]\s*([\s\S]*?)(?=\s+Line\s+\d+\s*:\s*\[(?:Error|Warning)\]|$)/gi;
/Line\s+(\d+)\s*:\s*\[(Error|Warning|Suggestion)\]\s*([\s\S]*?)(?=\s+Line\s+\d+\s*:\s*\[(?:Error|Warning|Suggestion)\]|$)/gi;
for (const match of details.matchAll(detailPattern)) {
const line = Number(match[1]);
if (line > 0) {
const severity = match[2].toLowerCase();
diagnostics.push({
path,
line,
severity:
match[2].toLowerCase() === "error"
severity === "error"
? "Error"
: "Warning",
: severity === "warning"
? "Warning"
: "Suggestion",
message: match[3].trim(),
});
}
Expand Down Expand Up @@ -443,7 +446,7 @@ async function annotateChangedLines(
const diagnostics = extractDiagnosticsFromBuildReport(buildReportHtml);
if (diagnostics.length === 0) {
info(
"No errors or warnings with line numbers found in validated files."
"No suggestions, warnings, or errors with line numbers found in validated files."
);
return;
}
Expand All @@ -470,7 +473,7 @@ async function annotateChangedLines(
changedLinesByPath
);
if (filteredDiagnostics.length === 0) {
info("No build errors or warnings occur on changed PR lines.");
info("No build errors, warnings, or suggestions occur on changed PR lines.");
return;
}

Expand All @@ -480,7 +483,9 @@ async function annotateChangedLines(
end_line: diagnostic.line,
annotation_level: (diagnostic.severity === "Error"
? "failure"
: "warning") as "failure" | "warning",
: diagnostic.severity === "Warning"
? "warning"
: "notice") as "failure" | "warning" | "notice",
title: `OPS ${diagnostic.severity}`,
message: diagnostic.message,
}));
Expand All @@ -495,7 +500,7 @@ async function annotateChangedLines(
details_url: buildReportUrl,
output: {
title: "OpenPublishing.Build diagnostics",
summary: `${annotations.length} error(s) or warning(s) found on changed lines.`,
summary: `${annotations.length} error(s), warning(s), or suggestion(s) found on changed lines.`,
annotations: firstBatch,
},
});
Expand All @@ -511,7 +516,7 @@ async function annotateChangedLines(
check_run_id: response.data.id,
output: {
title: "OpenPublishing.Build diagnostics",
summary: `${annotations.length} error(s) or warning(s) found on changed lines.`,
summary: `${annotations.length} error(s), warning(s), or suggestion(s) found on changed lines.`,
annotations: annotations.slice(
index,
index + ANNOTATION_BATCH_SIZE
Expand Down Expand Up @@ -624,8 +629,7 @@ export const exportedForTesting = {
appendTable,
buildMarkdownPreviewTableFromExtractedLinks,
calculateMaxPollAttempts,
extractChangedLinesFromPatch,
extractDiagnosticsFromBuildReport,
extractChangedLinesFromPatch,extractDiagnosticsFromBuildReport,
extractPreviewLinksFromBuildReport,
filterDiagnosticsToChangedLines,
PREVIEW_TABLE_END,
Expand Down
24 changes: 0 additions & 24 deletions actions/preview-link-generator/README.md

This file was deleted.

1 change: 0 additions & 1 deletion actions/preview-link-generator/dist/index.js.map

This file was deleted.

Loading