diff --git a/ApiClient.ts b/ApiClient.ts index c523855..1331226 100644 --- a/ApiClient.ts +++ b/ApiClient.ts @@ -35,9 +35,18 @@ export class UploadStatusError { constructor(public status: number, public text: string) { } } +export enum CancellationReason { + BENCHMARK_DEPENDENCY_FAILED = 'BENCHMARK_DEPENDENCY_FAILED', + INFRA_ERROR = 'INFRA_ERROR', + OVERLAPPING_BENCHMARK = 'OVERLAPPING_BENCHMARK', + TIMEOUT = 'TIMEOUT', +} + export type Flow = { name: string, - status: BenchmarkStatus + status: BenchmarkStatus, + errors?: string[], + cancellationReason?: CancellationReason } export type UploadStatusResponse = { @@ -99,7 +108,7 @@ export default class ApiClient { async getUploadStatus( uploadId: string, ): Promise { - const res = await fetch(`${this.apiUrl}/v2/upload/${uploadId}/status`, { + const res = await fetch(`${this.apiUrl}/v2/upload/${uploadId}/status?includeErrors=true`, { method: 'GET', headers: { 'Authorization': `Bearer ${this.apiKey}`, diff --git a/StatusPoller.ts b/StatusPoller.ts index 2fb3937..5a047f0 100644 --- a/StatusPoller.ts +++ b/StatusPoller.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import ApiClient, { BenchmarkStatus, Flow, UploadStatusError } from "./ApiClient"; +import ApiClient, { BenchmarkStatus, CancellationReason, Flow, UploadStatusError } from "./ApiClient"; import { canceled, err, info, success, warning } from './log'; const WAIT_TIMEOUT_MS = 1000 * 60 * 30 // 30 minutes @@ -8,15 +8,36 @@ const TERMINAL_STATUSES = new Set([BenchmarkStatus.SUCCESS, BenchmarkStatus.ERRO const isCompleted = (flow: Flow): boolean => TERMINAL_STATUSES.has(flow.status) +const getCanceledStatusMessage = (reason?: CancellationReason): string => { + switch (reason) { + case CancellationReason.BENCHMARK_DEPENDENCY_FAILED: + case CancellationReason.OVERLAPPING_BENCHMARK: + return 'Skipped'; + + case CancellationReason.TIMEOUT: + return 'Timeout'; + + case CancellationReason.INFRA_ERROR: + default: + return 'Canceled'; + } +} + +const renderError = (errors?: string[]): string => { + if (!errors || errors.length === 0) return ''; + + return ` (${errors[0]})`; +} + const printFlowResult = (flow: Flow): void => { if (flow.status === BenchmarkStatus.SUCCESS) { success(`[Passed] ${flow.name}`) } else if (flow.status === BenchmarkStatus.ERROR) { - err(`[Failed] ${flow.name}`) + err(`[Failed] ${flow.name}${renderError(flow.errors)}`) } else if (flow.status === BenchmarkStatus.WARNING) { warning(`[Warning] ${flow.name}`) } else if (flow.status === BenchmarkStatus.CANCELED) { - canceled(`[Canceled] ${flow.name}`) + canceled(`[${getCanceledStatusMessage(flow.cancellationReason)}] ${flow.name}`) } }