diff --git a/packages/artifact/src/internal/artifact-http-client.ts b/packages/artifact/src/internal/artifact-http-client.ts index bab4d7bb..933f5000 100644 --- a/packages/artifact/src/internal/artifact-http-client.ts +++ b/packages/artifact/src/internal/artifact-http-client.ts @@ -56,7 +56,7 @@ export class ArtifactHttpClient implements Rpc { isRetryable = this.isRetryableStatusCode(statusCode) errorMessage = `Artifact service responded with ${statusCode}` - } catch (error: any) { + } catch (error) { isRetryable = true errorMessage = error.message } diff --git a/packages/artifact/src/internal/config.ts b/packages/artifact/src/internal/config.ts index cd95e34d..bffaf15d 100644 --- a/packages/artifact/src/internal/config.ts +++ b/packages/artifact/src/internal/config.ts @@ -30,8 +30,13 @@ export function getWorkSpaceDirectory(): string { return workspaceDirectory } -export function getRetentionDays(): string | undefined { - return process.env['GITHUB_RETENTION_DAYS'] +export function getRetentionDays(): number | undefined { + //const retentionDays = process.env['GITHUB_RETENTION_DAYS'] + const retentionDays = "30" + if (!retentionDays) { + return undefined + } + return parseInt(retentionDays) } export function getInitialRetryIntervalInMilliseconds(): number { diff --git a/packages/artifact/src/internal/upload/tmp/twirp_testing.ts b/packages/artifact/src/internal/upload/tmp/twirp_testing.ts index 8c721833..f9c08858 100644 --- a/packages/artifact/src/internal/upload/tmp/twirp_testing.ts +++ b/packages/artifact/src/internal/upload/tmp/twirp_testing.ts @@ -1,12 +1,25 @@ import { ArtifactHttpClient } from '../../artifact-http-client' -import { ArtifactServiceClientJSON } from '../../../generated/results/api/v1/artifact.twirp' +import { ArtifactServiceClientJSON, CreateArtifactRequest, Timestamp } from '../../../generated' +import { getBackendIds, BackendIds } from '../../util' +import { getRetentionDays } from '../../config' export async function twirpTest(){ + const name = Math.random().toString() + const backendIDs: BackendIds = getBackendIds() + const createReq: CreateArtifactRequest = {workflowRunBackendId: backendIDs.workflowRunBackendId, workflowJobRunBackendId: backendIDs.workflowJobRunBackendId, name: name, version: 4} + const retentionDays = getRetentionDays() + if (retentionDays) { + const expirationDate = new Date() + expirationDate.setDate(expirationDate.getDate() + retentionDays) + createReq.expiresAt = Timestamp.fromDate(expirationDate) + } + + console.log("CreateArtifact request: " + JSON.stringify(createReq)) const artifactClient = new ArtifactHttpClient('@actions/artifact-upload') const jsonClient = new ArtifactServiceClientJSON(artifactClient) try { - const createResp = await jsonClient.CreateArtifact({workflowRunBackendId: "ce7f54c7-61c7-4aae-887f-30da475f5f1a", workflowJobRunBackendId: "ca395085-040a-526b-2ce8-bdc85f692774", name: Math.random().toString(), version: 4}) + const createResp = await jsonClient.CreateArtifact(createReq) if (!createResp.ok) { console.log("CreateArtifact failed") @@ -15,7 +28,7 @@ export async function twirpTest(){ console.log(createResp.signedUploadUrl) - const finalizeResp = await jsonClient.FinalizeArtifact({workflowRunBackendId: "ce7f54c7-61c7-4aae-887f-30da475f5f1a", workflowJobRunBackendId: "ca395085-040a-526b-2ce8-bdc85f692774", name: Math.random().toString(), size: BigInt(5)}) + const finalizeResp = await jsonClient.FinalizeArtifact({workflowRunBackendId: "ce7f54c7-61c7-4aae-887f-30da475f5f1a", workflowJobRunBackendId: "ca395085-040a-526b-2ce8-bdc85f692774", name: name, size: BigInt(5)}) if (!finalizeResp.ok) { console.log("FinalizeArtifact failed")