From 671bf1ebd55da086e8dd1d842d2f75142a24df24 Mon Sep 17 00:00:00 2001 From: Bethany Date: Tue, 22 Aug 2023 11:44:38 -0700 Subject: [PATCH] use GITHUB_WORKSPACE as default download dir --- .../artifact/src/internal/download/download-artifact.ts | 3 ++- packages/artifact/src/internal/shared/config.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index afd80d9b..9f9b47a6 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -9,6 +9,7 @@ import { DownloadArtifactResponse } from '../shared/interfaces' import {getUserAgentString} from '../shared/user-agent' +import { getGitHubWorkspaceDir } from '../shared/config' const scrubQueryParameters = (url: string): string => { const parsed = new URL(url) @@ -54,7 +55,7 @@ export async function downloadArtifact( token: string, options?: DownloadArtifactOptions ): Promise { - let downloadPath = options?.path || process.cwd() // TODO: make this align with GITHUB_WORKSPACE + let downloadPath = options?.path || getGitHubWorkspaceDir() if (options?.createArtifactFolder) { downloadPath = path.join(downloadPath, 'my-artifact') // TODO: need to pass artifact name } diff --git a/packages/artifact/src/internal/shared/config.ts b/packages/artifact/src/internal/shared/config.ts index dabb853b..8d8a1668 100644 --- a/packages/artifact/src/internal/shared/config.ts +++ b/packages/artifact/src/internal/shared/config.ts @@ -26,3 +26,11 @@ export function isGhes(): boolean { ) return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM' } + +export function getGitHubWorkspaceDir(): string { + const ghWorkspaceDir = process.env['GITHUB_WORKSPACE'] + if (!ghWorkspaceDir) { + throw new Error('Unable to get the GITHUB_WORKSPACE env variable') + } + return ghWorkspaceDir +}