1
0
Fork 0

add logic to fetch retention time

bethanyj28/get-retention-time
Bethany 2023-08-03 10:33:29 -07:00
parent f236b725b0
commit f705f1456b
3 changed files with 24 additions and 6 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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")