From ccb1df45d159adde17d61acb0300bc025626372a Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Fri, 19 Apr 2024 14:03:47 +0000 Subject: [PATCH 1/2] artifact client: retry on non-JSON response --- .../__tests__/artifact-http-client.test.ts | 48 +++++++++++++++++++ .../internal/shared/artifact-twirp-client.ts | 1 - 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/artifact/__tests__/artifact-http-client.test.ts b/packages/artifact/__tests__/artifact-http-client.test.ts index e676834636..feb2b04a02 100644 --- a/packages/artifact/__tests__/artifact-http-client.test.ts +++ b/packages/artifact/__tests__/artifact-http-client.test.ts @@ -116,6 +116,54 @@ describe('artifact-http-client', () => { expect(mockPost).toHaveBeenCalledTimes(2) }) + it('should retry if invalid body response', async () => { + const mockPost = jest + .fn(() => { + const msgSucceeded = new http.IncomingMessage(new net.Socket()) + msgSucceeded.statusCode = 200 + return { + message: msgSucceeded, + readBody: async () => { + return Promise.resolve( + `{"ok": true, "signedUploadUrl": "http://localhost:8080/upload"}` + ) + } + } + }) + .mockImplementationOnce(() => { + const msgFailed = new http.IncomingMessage(new net.Socket()) + msgFailed.statusCode = 502 + msgFailed.statusMessage = 'Bad Gateway' + return { + message: msgFailed, + readBody: async () => { + return Promise.resolve('💥') + } + } + }) + const mockHttpClient = ( + HttpClient as unknown as jest.Mock + ).mockImplementation(() => { + return { + post: mockPost + } + }) + + const client = internalArtifactTwirpClient(clientOptions) + const artifact = await client.CreateArtifact({ + workflowRunBackendId: '1234', + workflowJobRunBackendId: '5678', + name: 'artifact', + version: 4 + }) + + expect(mockHttpClient).toHaveBeenCalledTimes(1) + expect(artifact).toBeDefined() + expect(artifact.ok).toBe(true) + expect(artifact.signedUploadUrl).toBe('http://localhost:8080/upload') + expect(mockPost).toHaveBeenCalledTimes(2) + }) + it('should fail if the request fails 5 times', async () => { const mockPost = jest.fn(() => { const msgFailed = new http.IncomingMessage(new net.Socket()) diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index 1f987a1a35..00c65bc71b 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -102,7 +102,6 @@ class ArtifactHttpClient implements Rpc { } catch (error) { if (error instanceof SyntaxError) { debug(`Raw Body: ${rawBody}`) - throw error } if (error instanceof UsageError) { From b384fe17ba3eaae4a3ba0b3c839f328f69ac2e4c Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Fri, 19 Apr 2024 15:08:30 +0000 Subject: [PATCH 2/2] bump pkg version + release notes --- packages/artifact/RELEASES.md | 12 ++++++++++-- packages/artifact/package.json | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/artifact/RELEASES.md b/packages/artifact/RELEASES.md index ca32b7eb68..75d76f3e8f 100644 --- a/packages/artifact/RELEASES.md +++ b/packages/artifact/RELEASES.md @@ -1,5 +1,13 @@ # @actions/artifact Releases +### 2.1.6 + +- Will retry on invalid request responses. + +### 2.1.5 + +- Bumped `archiver` dependency to 7.0.1 + ### 2.1.4 - Adds info-level logging for zip extraction @@ -11,9 +19,9 @@ ### 2.1.2 - Updated the stream extract functionality to use `unzip.Parse()` instead of `unzip.Extract()` for greater control of unzipping artifacts - + ### 2.1.1 - + - Updated `isGhes` check to include `.ghe.com` and `.ghe.localhost` as accepted hosts ### 2.1.0 diff --git a/packages/artifact/package.json b/packages/artifact/package.json index ab60a27100..83d56a8359 100644 --- a/packages/artifact/package.json +++ b/packages/artifact/package.json @@ -1,6 +1,6 @@ { "name": "@actions/artifact", - "version": "2.1.5", + "version": "2.1.6", "preview": true, "description": "Actions artifact lib", "keywords": [ @@ -62,4 +62,4 @@ "typedoc-plugin-markdown": "^3.17.1", "typescript": "^5.2.2" } -} \ No newline at end of file +}