Skip to content

Commit

Permalink
Azure blob service support
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 10, 2024
1 parent 444ed44 commit 606bb16
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 39 deletions.
6 changes: 6 additions & 0 deletions src/models/BlobService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface BlobService {
azure?: {
azureStorageUrl?: string;
azureStorageSAS?: string;
};
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./BlobService";
export * from "./DisplayLevel";
export * from "./GitHubActionOptions";
33 changes: 31 additions & 2 deletions src/utils/getHtmlTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { getTestTitle } from "./getTestTitle";
import { getTestTags } from "./getTestTags";
import { getTestAnnotations } from "./getTestAnnotations";
import { getTestDuration } from "./getTestDuration";
import { DisplayLevel } from "../models";
import { BlobService, DisplayLevel } from "../models";
import { processAttachments } from "./processAttachments";

export const getHtmlTable = async (
tests: TestCase[],
showAnnotations: boolean,
showTags: boolean,
showError: boolean,
displayLevel: DisplayLevel[]
displayLevel: DisplayLevel[],
blobService?: BlobService
): Promise<string | undefined> => {
const convert = new Convert();
const hasBlobService = blobService && blobService.azure;

const content: string[] = [];

Expand All @@ -32,6 +35,10 @@ export const getHtmlTable = async (
}
if (showError) {
content.push(`<th>Error</th>`);

if (hasBlobService) {
content.push(`<th>Attachments</th>`);
}
}
content.push(`</tr>`);
content.push(`</thead>`);
Expand All @@ -53,6 +60,10 @@ export const getHtmlTable = async (
}
if (showError) {
colLength++;

if (hasBlobService) {
colLength++;
}
}

const annotations = await getTestAnnotations(test);
Expand Down Expand Up @@ -81,6 +92,24 @@ export const getHtmlTable = async (
if (showError) {
const error = result?.error?.message || "";
testRows.push(`<td>${convert.toHtml(error)}</td>`);

if (hasBlobService) {
const mediaFiles = await processAttachments(
blobService,
result.attachments
);

if (mediaFiles) {
const mediaLinks = mediaFiles
.map(
(m) =>
`<p align="center"><img src="${m.url}" alt="${m.name}" width="250"></p>
<p align="center"><b>${m.name}</b></p>`
)
.join(", ");
testRows.push(`<td>${mediaLinks}</td>`);
}
}
}
testRows.push(`</tr>`);
}
Expand Down
60 changes: 31 additions & 29 deletions src/utils/getTableRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getTestTags } from "./getTestTags";
import { getTestAnnotations } from "./getTestAnnotations";
import { getTestDuration } from "./getTestDuration";
import { getTestStatusIcon } from "./getTestStatusIcon";
import { DisplayLevel } from "../models";
import { BlobService, DisplayLevel } from "../models";
import { processAttachments } from "./processAttachments";

export const getTableRows = async (
Expand All @@ -16,12 +16,10 @@ export const getTableRows = async (
showTags: boolean,
showError: boolean,
displayLevel: DisplayLevel[],
azure?: {
azureStorageUrl?: string;
azureStorageSAS?: string;
}
blobService?: BlobService
): Promise<SummaryTableRow[]> => {
const convert = new Convert();
const hasBlobService = blobService && blobService.azure;

const tableHeaders = [
{
Expand Down Expand Up @@ -54,10 +52,13 @@ export const getTableRows = async (
data: "Error",
header: true,
});
tableHeaders.push({
data: "Attachments",
header: true,
});

if (hasBlobService) {
tableHeaders.push({
data: "Attachments",
header: true,
});
}
}

const tableRows: SummaryTableRow[] = [];
Expand All @@ -79,7 +80,10 @@ export const getTableRows = async (
}
if (showError) {
colLength++;
colLength++;

if (hasBlobService) {
colLength++;
}
}

const annotations = await getTestAnnotations(test);
Expand Down Expand Up @@ -127,26 +131,24 @@ export const getTableRows = async (
header: false,
});

const mediaFiles =
(azure &&
(await processAttachments(
azure?.azureStorageUrl,
azure?.azureStorageSAS,
result.attachments
))) ||
[];

tableRow.push({
data: (mediaFiles || [])
.map(
(
m
) => `<p align="center"><img src="${m.url}" alt="${m.name}" width="250"></p>
if (hasBlobService) {
const mediaFiles = await processAttachments(
blobService,
result.attachments
);

tableRow.push({
data: (mediaFiles || [])
.map(
(
m
) => `<p align="center"><img src="${m.url}" alt="${m.name}" width="250"></p>
<p align="center"><b>${m.name}</b></p>`
)
.join("\n\n"),
header: false,
});
)
.join("\n\n"),
header: false,
});
}
}

tableRows.push(tableRow);
Expand Down
7 changes: 5 additions & 2 deletions src/utils/processAttachments.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { parse } from "path";
import { readFile } from "fs/promises";
import { BlobService } from "../models";

export const processAttachments = async (
azureContainerUrl?: string,
azureContainerSas?: string,
blobService: BlobService,
attachments?: { name: string; path?: string; contentType: string }[]
) => {
const azureContainerUrl = blobService.azure?.azureStorageUrl;
const azureContainerSas = blobService.azure?.azureStorageSAS;

if (
!attachments ||
attachments.length === 0 ||
Expand Down
18 changes: 12 additions & 6 deletions src/utils/processResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getSummaryTitle } from "./getSummaryTitle";
import { getSummaryDetails } from "./getSummaryDetails";
import { getTestsPerFile } from "./getTestsPerFile";
import { getTestHeading } from "./getTestHeading";
import { DisplayLevel, GitHubActionOptions } from "../models";
import { BlobService, DisplayLevel, GitHubActionOptions } from "../models";

export const processResults = async (
suite: Suite | undefined,
Expand All @@ -30,6 +30,14 @@ export const processResults = async (
const os = process.platform;
const summary = core.summary;

let blobService: BlobService | undefined = undefined;
if (options.azureStorageSAS && options.azureStorageUrl) {
blobService = {};
blobService.azure = {};
blobService.azure.azureStorageSAS = options.azureStorageSAS;
blobService.azure.azureStorageUrl = options.azureStorageUrl;
}

const summaryTitle = getSummaryTitle(options.title);
if (summaryTitle) {
summary.addHeading(summaryTitle, 1);
Expand All @@ -56,7 +64,8 @@ export const processResults = async (
options.showAnnotations,
options.showTags,
!!options.showError,
options.includeResults as DisplayLevel[]
options.includeResults as DisplayLevel[],
blobService
);

if (!content) {
Expand All @@ -77,10 +86,7 @@ export const processResults = async (
options.showTags,
!!options.showError,
options.includeResults as DisplayLevel[],
{
azureStorageSAS: options.azureStorageSAS,
azureStorageUrl: options.azureStorageUrl,
}
blobService
);

if (tableRows.length !== 0) {
Expand Down

0 comments on commit 606bb16

Please sign in to comment.