Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions actions/preview-link-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ jobs:
- uses: dotnet/docs-tools/actions/preview-link-generator@main
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
max_wait_time_minutes: 20
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { WorkflowInput, workflowInput } from "../src/types/WorkflowInput";
const {
appendTable,
buildMarkdownPreviewTableFromExtractedLinks,
calculateMaxPollAttempts,
extractPreviewLinksFromBuildReport,
PREVIEW_TABLE_END,
PREVIEW_TABLE_START,
Expand Down Expand Up @@ -80,15 +81,22 @@ ${PREVIEW_TABLE_END}`;
it("options are correctly constructed with expected values from import", () => {
setInput("COLLAPSIBLE_AFTER", "7");
setInput("MAX_ROW_COUNT", "42");
setInput("MAX_WAIT_TIME_MINUTES", "15");
setInput("REPO_TOKEN", "test-token");

const opts: WorkflowInput = workflowInput;

expect(opts).toBeDefined();
expect(opts.collapsibleAfter).toBe(7);
expect(opts.maxRowCount).toBe(42);
expect(opts.maxWaitTimeMinutes).toBe(15);
expect(opts.repoToken).toBe("test-token");
});

it("calculates OPS poll attempts from the maximum wait time", () => {
expect(calculateMaxPollAttempts(15, 30_000)).toBe(30);
});
Comment thread
gewarren marked this conversation as resolved.

it("extractPreviewLinksFromBuildReport parses file to preview URL map", () => {
const html = `
<html>
Expand Down
3 changes: 3 additions & 0 deletions actions/preview-link-generator/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
max_row_count:
description: 'The maximum number of rows to display in the automated preview table.'
default: '30'
max_wait_time_minutes:
description: 'The maximum number of minutes to wait for the OpenPublishing.Build status check to complete.'
default: '20'
runs:
using: 'node16'
main: 'dist/index.js'
11 changes: 9 additions & 2 deletions actions/preview-link-generator/dist/index.js

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

2 changes: 1 addition & 1 deletion actions/preview-link-generator/dist/index.js.map

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions actions/preview-link-generator/src/pull-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { workflowInput } from "./types/WorkflowInput";
const PREVIEW_TABLE_START = "<!-- PREVIEW-TABLE-START -->";
const PREVIEW_TABLE_END = "<!-- PREVIEW-TABLE-END -->";
const OPS_CHECK_NAME = "OpenPublishing.Build";
const OPS_MAX_POLL_ATTEMPTS = 40;
const OPS_POLL_DELAY_MS = 30_000;

type StatusCheck = {
Expand Down Expand Up @@ -56,7 +55,10 @@ export async function tryUpdatePullRequestBody(token: string) {
token,
commitOid,
OPS_CHECK_NAME,
OPS_MAX_POLL_ATTEMPTS,
calculateMaxPollAttempts(
workflowInput.maxWaitTimeMinutes,
OPS_POLL_DELAY_MS
),
OPS_POLL_DELAY_MS
);

Expand Down Expand Up @@ -188,6 +190,13 @@ function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

function calculateMaxPollAttempts(
maxWaitTimeMinutes: number,
pollDelayMs: number
): number {
return Math.ceil((maxWaitTimeMinutes * 60_000) / pollDelayMs);
Comment thread
gewarren marked this conversation as resolved.
Outdated
}

async function downloadUrl(url: string): Promise<string> {
return await new Promise((resolve) => {
const request = https.get(url, (response) => {
Expand Down Expand Up @@ -392,6 +401,7 @@ function appendTable(body: string, table: string) {
export const exportedForTesting = {
appendTable,
buildMarkdownPreviewTableFromExtractedLinks,
calculateMaxPollAttempts,
extractPreviewLinksFromBuildReport,
PREVIEW_TABLE_END,
PREVIEW_TABLE_START,
Expand Down
5 changes: 5 additions & 0 deletions actions/preview-link-generator/src/types/WorkflowInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class WorkflowInput {
return parseInt(val || "30");
}

get maxWaitTimeMinutes(): number {
const val = parseInt(getInput("max_wait_time_minutes") || "20");
return val > 0 ? val : 20;
}

constructor() {}
}

Expand Down
Loading