From 1c71f655eba41fe06eed6f0fc9520ac8e3480d99 Mon Sep 17 00:00:00 2001 From: Bethany Date: Tue, 5 Sep 2023 14:44:53 -0700 Subject: [PATCH] update 403 error message for ghes --- packages/artifact/__tests__/upload.test.ts | 14 +++++++++++ packages/artifact/package-lock.json | 24 +++++++++---------- .../internal/__mocks__/config-variables.ts | 4 ++++ .../artifact/src/internal/config-variables.ts | 7 ++++++ .../src/internal/upload-http-client.ts | 7 ++++-- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/packages/artifact/__tests__/upload.test.ts b/packages/artifact/__tests__/upload.test.ts index 75c228e1..c2d697b2 100644 --- a/packages/artifact/__tests__/upload.test.ts +++ b/packages/artifact/__tests__/upload.test.ts @@ -2,6 +2,7 @@ import * as http from 'http' import * as io from '../../io/src/io' import * as net from 'net' import * as path from 'path' +import * as config from '../src/internal/config-variables' import {mocked} from 'ts-jest/utils' import {exec, execSync} from 'child_process' import {createGunzip} from 'zlib' @@ -134,6 +135,19 @@ describe('Upload Tests', () => { ) }) + it('Create Artifact - Storage Quota Error on GHES', async () => { + jest.spyOn(config, 'isGhes').mockReturnValueOnce(true) + const artifactName = 'storage-quota-hit' + const uploadHttpClient = new UploadHttpClient() + expect( + uploadHttpClient.createArtifactInFileContainer(artifactName) + ).rejects.toEqual( + new Error( + 'Create Artifact Container failed: Please reference [Enabling GitHub Actions for GitHub Enterprise Server](https://docs.github.com/en/enterprise-server@3.8/admin/github-actions/enabling-github-actions-for-github-enterprise-server) to ensure Actions storage is configured correctly.' + ) + ) + }) + /** * Artifact Upload Tests */ diff --git a/packages/artifact/package-lock.json b/packages/artifact/package-lock.json index 27256cc1..a361cf18 100644 --- a/packages/artifact/package-lock.json +++ b/packages/artifact/package-lock.json @@ -20,18 +20,18 @@ } }, "node_modules/@actions/core": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz", - "integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", + "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", "dependencies": { "@actions/http-client": "^2.0.1", "uuid": "^8.3.2" } }, "node_modules/@actions/http-client": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", - "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.1.tgz", + "integrity": "sha512-qhrkRMB40bbbLo7gF+0vu+X+UawOvQQqNAA/5Unx774RS8poaOhThDOG6BGmxvAnxhQnDp2BG/ZUm65xZILTpw==", "dependencies": { "tunnel": "^0.0.6" } @@ -196,18 +196,18 @@ }, "dependencies": { "@actions/core": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz", - "integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz", + "integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==", "requires": { "@actions/http-client": "^2.0.1", "uuid": "^8.3.2" } }, "@actions/http-client": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", - "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.1.1.tgz", + "integrity": "sha512-qhrkRMB40bbbLo7gF+0vu+X+UawOvQQqNAA/5Unx774RS8poaOhThDOG6BGmxvAnxhQnDp2BG/ZUm65xZILTpw==", "requires": { "tunnel": "^0.0.6" } diff --git a/packages/artifact/src/internal/__mocks__/config-variables.ts b/packages/artifact/src/internal/__mocks__/config-variables.ts index 55aaf2e0..f4d6c7cc 100644 --- a/packages/artifact/src/internal/__mocks__/config-variables.ts +++ b/packages/artifact/src/internal/__mocks__/config-variables.ts @@ -49,3 +49,7 @@ export function getWorkFlowRunId(): string { export function getRetentionDays(): string | undefined { return '45' } + +export function isGhes(): boolean { + return false +} diff --git a/packages/artifact/src/internal/config-variables.ts b/packages/artifact/src/internal/config-variables.ts index 01243588..f6dc8620 100644 --- a/packages/artifact/src/internal/config-variables.ts +++ b/packages/artifact/src/internal/config-variables.ts @@ -65,3 +65,10 @@ export function getWorkSpaceDirectory(): string { export function getRetentionDays(): string | undefined { return process.env['GITHUB_RETENTION_DAYS'] } + +export function isGhes(): boolean { + const ghUrl = new URL( + process.env['GITHUB_SERVER_URL'] || 'https://github.com' + ) + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM' +} diff --git a/packages/artifact/src/internal/upload-http-client.ts b/packages/artifact/src/internal/upload-http-client.ts index 67b3bf6d..d27aa87f 100644 --- a/packages/artifact/src/internal/upload-http-client.ts +++ b/packages/artifact/src/internal/upload-http-client.ts @@ -26,7 +26,8 @@ import { getUploadChunkSize, getUploadFileConcurrency, getRetryLimit, - getRetentionDays + getRetentionDays, + isGhes } from './config-variables' import {promisify} from 'util' import {URL} from 'url' @@ -88,7 +89,9 @@ export class UploadHttpClient { const customErrorMessages: Map = new Map([ [ HttpCodes.Forbidden, - 'Artifact storage quota has been hit. Unable to upload any new artifacts' + isGhes() + ? 'Please reference [Enabling GitHub Actions for GitHub Enterprise Server](https://docs.github.com/en/enterprise-server@3.8/admin/github-actions/enabling-github-actions-for-github-enterprise-server) to ensure Actions storage is configured correctly.' + : 'Artifact storage quota has been hit. Unable to upload any new artifacts' ], [ HttpCodes.BadRequest,