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

Reduce isHeaderPngAccessible() timeout #235

Merged
merged 9 commits into from
Dec 26, 2024
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
21 changes: 18 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,21 +826,34 @@ class Utils {
static getUsageBadge() {
return `![](${process.env.JF_URL}/ui/api/v1/u?s=1&m=1&job_id=${process.env.GITHUB_JOB}&run_id=${process.env.GITHUB_RUN_ID}&git_repo=${process.env.GITHUB_REPOSITORY})`;
}
/**
* Checks if the header image is accessible via the internet.
* Saves the result in a static variable to avoid multiple checks.
* @private
*/
static isHeaderPngAccessible() {
return __awaiter(this, void 0, void 0, function* () {
if (this.isSummaryHeaderAccessible != undefined) {
return this.isSummaryHeaderAccessible;
}
const url = this.MARKDOWN_HEADER_PNG_URL;
const httpClient = new http_client_1.HttpClient();
try {
const response = yield httpClient.head(url);
return response.message.statusCode === 200;
// Set timeout to 5 seconds
const requestOptions = {
socketTimeout: 5000,
};
const response = yield httpClient.head(url, requestOptions);
this.isSummaryHeaderAccessible = response.message.statusCode === 200;
}
catch (error) {
core.warning('No internet access to the header image, using the text header instead.');
return false;
this.isSummaryHeaderAccessible = false;
}
finally {
httpClient.dispose();
}
return this.isSummaryHeaderAccessible;
});
}
static getTempDirectory() {
Expand Down Expand Up @@ -917,3 +930,5 @@ Utils.CUSTOM_SERVER_ID = 'custom-server-id';
// It cannot be linked to the repository, as GitHub serves the image from a CDN,
// which gets blocked by the browser, resulting in an empty image.
Utils.MARKDOWN_HEADER_PNG_URL = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg';
// Flag to indicate if the summary header is accessible, can be undefined if not checked yet.
Utils.isSummaryHeaderAccessible = undefined;
22 changes: 18 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export class Utils {
// It cannot be linked to the repository, as GitHub serves the image from a CDN,
// which gets blocked by the browser, resulting in an empty image.
private static MARKDOWN_HEADER_PNG_URL: string = 'https://media.jfrog.com/wp-content/uploads/2024/09/02161430/jfrog-job-summary.svg';
private static isSummaryHeaderAccessible: boolean;
// Flag to indicate if the summary header is accessible, can be undefined if not checked yet.
private static isSummaryHeaderAccessible: boolean | undefined = undefined;

/**
* Retrieves server credentials for accessing JFrog's server
Expand Down Expand Up @@ -913,18 +914,31 @@ export class Utils {
return `![](${process.env.JF_URL}/ui/api/v1/u?s=1&m=1&job_id=${process.env.GITHUB_JOB}&run_id=${process.env.GITHUB_RUN_ID}&git_repo=${process.env.GITHUB_REPOSITORY})`;
}

/**
* Checks if the header image is accessible via the internet.
* Saves the result in a static variable to avoid multiple checks.
* @private
*/
private static async isHeaderPngAccessible(): Promise<boolean> {
if (this.isSummaryHeaderAccessible != undefined) {
return this.isSummaryHeaderAccessible;
}
const url: string = this.MARKDOWN_HEADER_PNG_URL;
const httpClient: HttpClient = new HttpClient();
try {
const response: HttpClientResponse = await httpClient.head(url);
return response.message.statusCode === 200;
// Set timeout to 5 seconds
const requestOptions: OutgoingHttpHeaders = {
socketTimeout: 5000,
};
const response: HttpClientResponse = await httpClient.head(url, requestOptions);
this.isSummaryHeaderAccessible = response.message.statusCode === 200;
} catch (error) {
core.warning('No internet access to the header image, using the text header instead.');
return false;
this.isSummaryHeaderAccessible = false;
} finally {
httpClient.dispose();
}
return this.isSummaryHeaderAccessible;
}

private static getTempDirectory(): string {
Expand Down
Loading