From e386446c2afee9e7049e12b07f8fa4ae3ed22f3b Mon Sep 17 00:00:00 2001 From: Jess Bees Date: Fri, 22 Dec 2023 10:25:57 -0500 Subject: [PATCH] Catch artifact-client errors differently from octokit errors --- src/__tests__/internal/deployment.test.js | 10 ++++----- src/internal/deployment.js | 25 ++++++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/__tests__/internal/deployment.test.js b/src/__tests__/internal/deployment.test.js index 2111130..5fadfab 100644 --- a/src/__tests__/internal/deployment.test.js +++ b/src/__tests__/internal/deployment.test.js @@ -186,13 +186,13 @@ describe('Deployment', () => { const twirpScope = nock(process.env.ACTIONS_RESULTS_URL) .post(LIST_ARTIFACTS_TWIRP_PATH) - .reply(400, { message: 'Bad request' }, { headers: { 'content-type': 'application/json' } }) + .reply(400, { msg: 'yikes!' }, { 'content-type': 'application/json' }) // Create the deployment const deployment = new Deployment() await expect(deployment.create()).rejects.toEqual( new Error( - `Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request` + `Failed to create deployment: Failed to ListArtifacts: Received non-retryable error: Failed request: (400) null: yikes!` ) ) twirpScope.done() @@ -407,16 +407,16 @@ describe('Deployment', () => { twirpScope.done() }) - it('fails with error message if list artifact endpoint returns 500', async () => { + it('fails with error message if list artifact endpoint returns 501', async () => { process.env.GITHUB_SHA = 'valid-build-version' const twirpScope = nock(process.env.ACTIONS_RESULTS_URL) .post(LIST_ARTIFACTS_TWIRP_PATH) - .reply(500, { message: 'oh no' }, { headers: { 'content-type': 'application/json' } }) + .reply(501, { msg: 'oh no' }, { headers: { 'content-type': 'application/json' } }) const deployment = new Deployment() await expect(deployment.create(fakeJwt)).rejects.toThrow( - `Failed to create deployment (status: 500) with build version valid-build-version. Server error, is githubstatus.com reporting a Pages outage? Please re-run the deployment at a later time.` + `Failed to create deployment: Failed to ListArtifacts: Received non-retryable error: Failed request: (501) null: oh no` ) twirpScope.done() }) diff --git a/src/internal/deployment.js b/src/internal/deployment.js index fcd39cc..eae23bb 100644 --- a/src/internal/deployment.js +++ b/src/internal/deployment.js @@ -58,19 +58,24 @@ class Deployment { const timeoutInput = Number(core.getInput('timeout')) this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT) + core.debug(`Actor: ${this.buildActor}`) + core.debug(`Action ID: ${this.actionsId}`) + core.debug(`Actions Workflow Run ID: ${this.workflowRun}`) + + let artifactData try { - core.debug(`Actor: ${this.buildActor}`) - core.debug(`Action ID: ${this.actionsId}`) - core.debug(`Actions Workflow Run ID: ${this.workflowRun}`) + artifactData = await getArtifactMetadata({ artifactName: this.artifactName }) + } catch (error) { + throw new Error(`Failed to create deployment: ${error.message}`) + } - const artifactData = await getArtifactMetadata({ artifactName: this.artifactName }) - - if (artifactData?.size > ONE_GIGABYTE) { - core.warning( - `Uploaded artifact size of ${artifactData?.size} bytes exceeds the allowed size of ${SIZE_LIMIT_DESCRIPTION}. Deployment might fail.` - ) - } + if (artifactData?.size > ONE_GIGABYTE) { + core.warning( + `Uploaded artifact size of ${artifactData?.size} bytes exceeds the allowed size of ${SIZE_LIMIT_DESCRIPTION}. Deployment might fail.` + ) + } + try { const deployment = await createPagesDeployment({ githubToken: this.githubToken, artifactId: artifactData.id,