diff --git a/packages/artifact/__tests__/delete-artifacts.test.ts b/packages/artifact/__tests__/delete-artifacts.test.ts index 70a3941249..d3bbe30995 100644 --- a/packages/artifact/__tests__/delete-artifacts.test.ts +++ b/packages/artifact/__tests__/delete-artifacts.test.ts @@ -7,7 +7,7 @@ import { } from '../src/internal/delete/delete-artifact' import * as config from '../src/internal/shared/config' import {ArtifactServiceClientJSON, Timestamp} from '../src/generated' -import * as util from '../src/internal/shared/util' +import * as util from '../src/internal/shared/utils' import {noopLogs} from './common' type MockedRequest = jest.MockedFunction> diff --git a/packages/artifact/__tests__/download-artifact.test.ts b/packages/artifact/__tests__/download-artifact.test.ts index 9c7d7136e2..88aacba22e 100644 --- a/packages/artifact/__tests__/download-artifact.test.ts +++ b/packages/artifact/__tests__/download-artifact.test.ts @@ -16,7 +16,7 @@ import {getUserAgentString} from '../src/internal/shared/user-agent' import {noopLogs} from './common' import * as config from '../src/internal/shared/config' import {ArtifactServiceClientJSON} from '../src/generated' -import * as util from '../src/internal/shared/util' +import * as util from '../src/internal/shared/utils' type MockedDownloadArtifact = jest.MockedFunction< RestEndpointMethods['actions']['downloadArtifact'] diff --git a/packages/artifact/__tests__/get-artifact.test.ts b/packages/artifact/__tests__/get-artifact.test.ts index 56ed0d34b5..1040d49056 100644 --- a/packages/artifact/__tests__/get-artifact.test.ts +++ b/packages/artifact/__tests__/get-artifact.test.ts @@ -6,7 +6,7 @@ import { } from '../src/internal/find/get-artifact' import * as config from '../src/internal/shared/config' import {ArtifactServiceClientJSON, Timestamp} from '../src/generated' -import * as util from '../src/internal/shared/util' +import * as util from '../src/internal/shared/utils' import {noopLogs} from './common' import { ArtifactNotFoundError, diff --git a/packages/artifact/__tests__/list-artifacts.test.ts b/packages/artifact/__tests__/list-artifacts.test.ts index bd70fa093e..17509547e0 100644 --- a/packages/artifact/__tests__/list-artifacts.test.ts +++ b/packages/artifact/__tests__/list-artifacts.test.ts @@ -6,7 +6,7 @@ import { } from '../src/internal/find/list-artifacts' import * as config from '../src/internal/shared/config' import {ArtifactServiceClientJSON, Timestamp} from '../src/generated' -import * as util from '../src/internal/shared/util' +import * as util from '../src/internal/shared/utils' import {noopLogs} from './common' import {Artifact} from '../src/internal/shared/interfaces' import {RequestInterface} from '@octokit/types' diff --git a/packages/artifact/__tests__/upload-artifact.test.ts b/packages/artifact/__tests__/upload-artifact.test.ts index 64cc4fb1be..ebe2752e8b 100644 --- a/packages/artifact/__tests__/upload-artifact.test.ts +++ b/packages/artifact/__tests__/upload-artifact.test.ts @@ -1,6 +1,6 @@ import * as uploadZipSpecification from '../src/internal/upload/upload-zip-specification' import * as zip from '../src/internal/upload/zip' -import * as util from '../src/internal/shared/util' +import * as util from '../src/internal/shared/utils' import * as config from '../src/internal/shared/config' import {ArtifactServiceClientJSON} from '../src/generated' import * as blobUpload from '../src/internal/upload/blob-upload' diff --git a/packages/artifact/__tests__/util.test.ts b/packages/artifact/__tests__/utils.test.ts similarity index 99% rename from packages/artifact/__tests__/util.test.ts rename to packages/artifact/__tests__/utils.test.ts index 2649662e01..f9503ce41c 100644 --- a/packages/artifact/__tests__/util.test.ts +++ b/packages/artifact/__tests__/utils.test.ts @@ -1,6 +1,6 @@ import * as config from '../src/internal/shared/config' -import * as util from '../src/internal/shared/util' -import {maskSigUrl, maskSecretUrls} from '../src/internal/shared/util' +import * as util from '../src/internal/shared/utils' +import {maskSigUrl, maskSecretUrls} from '../src/internal/shared/utils' import {setSecret, debug} from '@actions/core' export const testRuntimeToken = diff --git a/packages/artifact/src/internal/delete/delete-artifact.ts b/packages/artifact/src/internal/delete/delete-artifact.ts index 785b403574..20750036e5 100644 --- a/packages/artifact/src/internal/delete/delete-artifact.ts +++ b/packages/artifact/src/internal/delete/delete-artifact.ts @@ -8,7 +8,7 @@ import {requestLog} from '@octokit/plugin-request-log' import {retry} from '@octokit/plugin-retry' import {OctokitOptions} from '@octokit/core/dist-types/types' import {internalArtifactTwirpClient} from '../shared/artifact-twirp-client' -import {getBackendIdsFromToken} from '../shared/util' +import {getBackendIdsFromToken} from '../shared/utils' import { DeleteArtifactRequest, ListArtifactsRequest, diff --git a/packages/artifact/src/internal/download/download-artifact.ts b/packages/artifact/src/internal/download/download-artifact.ts index 4a735bb8fa..b71fc10063 100644 --- a/packages/artifact/src/internal/download/download-artifact.ts +++ b/packages/artifact/src/internal/download/download-artifact.ts @@ -19,7 +19,7 @@ import { Int64Value, ListArtifactsRequest } from '../../generated' -import {getBackendIdsFromToken} from '../shared/util' +import {getBackendIdsFromToken} from '../shared/utils' import {ArtifactNotFoundError} from '../shared/errors' const scrubQueryParameters = (url: string): string => { diff --git a/packages/artifact/src/internal/find/get-artifact.ts b/packages/artifact/src/internal/find/get-artifact.ts index 925635e70c..d6e9735515 100644 --- a/packages/artifact/src/internal/find/get-artifact.ts +++ b/packages/artifact/src/internal/find/get-artifact.ts @@ -6,7 +6,7 @@ import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils' import {getRetryOptions} from './retry-options' import {requestLog} from '@octokit/plugin-request-log' import {GetArtifactResponse} from '../shared/interfaces' -import {getBackendIdsFromToken} from '../shared/util' +import {getBackendIdsFromToken} from '../shared/utils' import {getUserAgentString} from '../shared/user-agent' import {internalArtifactTwirpClient} from '../shared/artifact-twirp-client' import {ListArtifactsRequest, StringValue, Timestamp} from '../../generated' diff --git a/packages/artifact/src/internal/find/list-artifacts.ts b/packages/artifact/src/internal/find/list-artifacts.ts index f876289b84..58f9a02fc6 100644 --- a/packages/artifact/src/internal/find/list-artifacts.ts +++ b/packages/artifact/src/internal/find/list-artifacts.ts @@ -8,7 +8,7 @@ import {requestLog} from '@octokit/plugin-request-log' import {retry} from '@octokit/plugin-retry' import {OctokitOptions} from '@octokit/core/dist-types/types' import {internalArtifactTwirpClient} from '../shared/artifact-twirp-client' -import {getBackendIdsFromToken} from '../shared/util' +import {getBackendIdsFromToken} from '../shared/utils' import {ListArtifactsRequest, Timestamp} from '../../generated' // Limiting to 1000 for perf reasons diff --git a/packages/artifact/src/internal/shared/artifact-twirp-client.ts b/packages/artifact/src/internal/shared/artifact-twirp-client.ts index 574991258f..450dd54772 100644 --- a/packages/artifact/src/internal/shared/artifact-twirp-client.ts +++ b/packages/artifact/src/internal/shared/artifact-twirp-client.ts @@ -5,7 +5,7 @@ import {ArtifactServiceClientJSON} from '../../generated' import {getResultsServiceUrl, getRuntimeToken} from './config' import {getUserAgentString} from './user-agent' import {NetworkError, UsageError} from './errors' -import {maskSecretUrls} from './util' +import {maskSecretUrls} from './utils' // The twirp http client must implement this interface interface Rpc { diff --git a/packages/artifact/src/internal/shared/util.ts b/packages/artifact/src/internal/shared/utils.ts similarity index 100% rename from packages/artifact/src/internal/shared/util.ts rename to packages/artifact/src/internal/shared/utils.ts diff --git a/packages/artifact/src/internal/upload/upload-artifact.ts b/packages/artifact/src/internal/upload/upload-artifact.ts index 81be322c75..3a167b05fa 100644 --- a/packages/artifact/src/internal/upload/upload-artifact.ts +++ b/packages/artifact/src/internal/upload/upload-artifact.ts @@ -11,7 +11,7 @@ import { getUploadZipSpecification, validateRootDirectory } from './upload-zip-specification' -import {getBackendIdsFromToken} from '../shared/util' +import {getBackendIdsFromToken} from '../shared/utils' import {uploadZipToBlobStorage} from './blob-upload' import {createZipUploadStream} from './zip' import { diff --git a/packages/cache/__tests__/cacheHttpClient.test.ts b/packages/cache/__tests__/cacheHttpClient.test.ts index e2201cd1cb..ca18bf3ff6 100644 --- a/packages/cache/__tests__/cacheHttpClient.test.ts +++ b/packages/cache/__tests__/cacheHttpClient.test.ts @@ -1,10 +1,10 @@ import {downloadCache} from '../src/internal/cacheHttpClient' -import {getCacheVersion} from '../src/internal/cacheUtils' -import {CompressionMethod} from '../src/internal/constants' -import * as downloadUtils from '../src/internal/downloadUtils' +import {getCacheVersion} from '../src/internal/shared/utils' +import {CompressionMethod} from '../src/internal/shared/constants' +import * as downloadUtils from '../src/internal/shared/downloadUtils' import {DownloadOptions, getDownloadOptions} from '../src/options' -jest.mock('../src/internal/downloadUtils') +jest.mock('../src/internal/shared/downloadUtils') test('getCacheVersion does not mutate arguments', async () => { const paths = ['node_modules'] diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index fad045b47e..1fd84503f8 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -1,6 +1,6 @@ import {promises as fs} from 'fs' import * as path from 'path' -import * as cacheUtils from '../src/internal/cacheUtils' +import * as cacheUtils from '../src/internal/shared/utils' beforeEach(() => { jest.resetModules() diff --git a/packages/cache/__tests__/downloadUtils.test.ts b/packages/cache/__tests__/downloadUtils.test.ts index 4cc089af89..067303f64d 100644 --- a/packages/cache/__tests__/downloadUtils.test.ts +++ b/packages/cache/__tests__/downloadUtils.test.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import {DownloadProgress} from '../src/internal/downloadUtils' +import {DownloadProgress} from '../src/internal/shared/downloadUtils' test('download progress tracked correctly', () => { const progress = new DownloadProgress(1000) diff --git a/packages/cache/__tests__/requestUtils.test.ts b/packages/cache/__tests__/requestUtils.test.ts index 05fc573bdf..46dc0e804a 100644 --- a/packages/cache/__tests__/requestUtils.test.ts +++ b/packages/cache/__tests__/requestUtils.test.ts @@ -1,6 +1,6 @@ -import {retry, retryTypedResponse} from '../src/internal/requestUtils' +import {retry, retryTypedResponse} from '../src/internal/shared/requestUtils' import {HttpClientError} from '@actions/http-client' -import * as requestUtils from '../src/internal/requestUtils' +import * as requestUtils from '../src/internal/shared/requestUtils' interface ITestResponse { statusCode: number diff --git a/packages/cache/__tests__/restoreCache.test.ts b/packages/cache/__tests__/restoreCache.test.ts index 7992490e5a..6b2cf72079 100644 --- a/packages/cache/__tests__/restoreCache.test.ts +++ b/packages/cache/__tests__/restoreCache.test.ts @@ -2,13 +2,16 @@ import * as core from '@actions/core' import * as path from 'path' import {restoreCache} from '../src/cache' import * as cacheHttpClient from '../src/internal/cacheHttpClient' -import * as cacheUtils from '../src/internal/cacheUtils' -import {CacheFilename, CompressionMethod} from '../src/internal/constants' +import * as cacheUtils from '../src/internal/shared/utils' +import { + CacheFilename, + CompressionMethod +} from '../src/internal/shared/constants' import {ArtifactCacheEntry} from '../src/internal/contracts' import * as tar from '../src/internal/tar' jest.mock('../src/internal/cacheHttpClient') -jest.mock('../src/internal/cacheUtils') +jest.mock('../src/internal/shared/utils') jest.mock('../src/internal/tar') beforeAll(() => { @@ -19,7 +22,7 @@ beforeAll(() => { jest.spyOn(core, 'error').mockImplementation(() => {}) jest.spyOn(cacheUtils, 'getCacheFileName').mockImplementation(cm => { - const actualUtils = jest.requireActual('../src/internal/cacheUtils') + const actualUtils = jest.requireActual('../src/internal/shared/utils') return actualUtils.getCacheFileName(cm) }) }) diff --git a/packages/cache/__tests__/restoreCacheV2.test.ts b/packages/cache/__tests__/restoreCacheV2.test.ts index 485b8aebce..7084b6ae8f 100644 --- a/packages/cache/__tests__/restoreCacheV2.test.ts +++ b/packages/cache/__tests__/restoreCacheV2.test.ts @@ -2,15 +2,18 @@ import * as core from '@actions/core' import * as path from 'path' import * as tar from '../src/internal/tar' import * as config from '../src/internal/config' -import * as cacheUtils from '../src/internal/cacheUtils' +import * as cacheUtils from '../src/internal/shared/utils' import * as cacheHttpClient from '../src/internal/cacheHttpClient' import {restoreCache} from '../src/cache' -import {CacheFilename, CompressionMethod} from '../src/internal/constants' +import { + CacheFilename, + CompressionMethod +} from '../src/internal/shared/constants' import {CacheServiceClientJSON} from '../src/generated/results/api/v1/cache.twirp-client' import {DownloadOptions} from '../src/options' jest.mock('../src/internal/cacheHttpClient') -jest.mock('../src/internal/cacheUtils') +jest.mock('../src/internal/shared/utils') jest.mock('../src/internal/config') jest.mock('../src/internal/tar') @@ -25,7 +28,7 @@ beforeAll(() => { jest.spyOn(core, 'error').mockImplementation(() => {}) jest.spyOn(cacheUtils, 'getCacheFileName').mockImplementation(cm => { - const actualUtils = jest.requireActual('../src/internal/cacheUtils') + const actualUtils = jest.requireActual('../src/internal/shared/utils') return actualUtils.getCacheFileName(cm) }) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index e5ed695b1f..6708875d55 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -2,9 +2,12 @@ import * as core from '@actions/core' import * as path from 'path' import {saveCache} from '../src/cache' import * as cacheHttpClient from '../src/internal/cacheHttpClient' -import * as cacheUtils from '../src/internal/cacheUtils' +import * as cacheUtils from '../src/internal/shared/utils' import * as config from '../src/internal/config' -import {CacheFilename, CompressionMethod} from '../src/internal/constants' +import { + CacheFilename, + CompressionMethod +} from '../src/internal/shared/constants' import * as tar from '../src/internal/tar' import {TypedResponse} from '@actions/http-client/lib/interfaces' import { @@ -14,7 +17,7 @@ import { import {HttpClientError} from '@actions/http-client' jest.mock('../src/internal/cacheHttpClient') -jest.mock('../src/internal/cacheUtils') +jest.mock('../src/internal/shared/utils') jest.mock('../src/internal/config') jest.mock('../src/internal/tar') @@ -25,7 +28,7 @@ beforeAll(() => { jest.spyOn(core, 'warning').mockImplementation(() => {}) jest.spyOn(core, 'error').mockImplementation(() => {}) jest.spyOn(cacheUtils, 'getCacheFileName').mockImplementation(cm => { - const actualUtils = jest.requireActual('../src/internal/cacheUtils') + const actualUtils = jest.requireActual('../src/internal/shared/utils') return actualUtils.getCacheFileName(cm) }) jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async filePaths => { diff --git a/packages/cache/__tests__/saveCacheV2.test.ts b/packages/cache/__tests__/saveCacheV2.test.ts index e96c2ac9da..a559c55489 100644 --- a/packages/cache/__tests__/saveCacheV2.test.ts +++ b/packages/cache/__tests__/saveCacheV2.test.ts @@ -1,8 +1,11 @@ import * as core from '@actions/core' import * as path from 'path' import {saveCache} from '../src/cache' -import * as cacheUtils from '../src/internal/cacheUtils' -import {CacheFilename, CompressionMethod} from '../src/internal/constants' +import * as cacheUtils from '../src/internal/shared/utils' +import { + CacheFilename, + CompressionMethod +} from '../src/internal/shared/constants' import * as config from '../src/internal/config' import * as tar from '../src/internal/tar' import {CacheServiceClientJSON} from '../src/generated/results/api/v1/cache.twirp-client' diff --git a/packages/cache/__tests__/tar.test.ts b/packages/cache/__tests__/tar.test.ts index 4145d9a946..25c8f21935 100644 --- a/packages/cache/__tests__/tar.test.ts +++ b/packages/cache/__tests__/tar.test.ts @@ -8,9 +8,9 @@ import { ManifestFilename, SystemTarPathOnWindows, TarFilename -} from '../src/internal/constants' +} from '../src/internal/shared/constants' import * as tar from '../src/internal/tar' -import * as utils from '../src/internal/cacheUtils' +import * as utils from '../src/internal/shared/utils' // eslint-disable-next-line @typescript-eslint/no-require-imports import fs = require('fs') diff --git a/packages/cache/__tests__/uploadUtils.test.ts b/packages/cache/__tests__/uploadUtils.test.ts index 2f0b8b554f..1f8b0733fc 100644 --- a/packages/cache/__tests__/uploadUtils.test.ts +++ b/packages/cache/__tests__/uploadUtils.test.ts @@ -1,4 +1,4 @@ -import * as uploadUtils from '../src/internal/uploadUtils' +import * as uploadUtils from '../src/internal/shared/uploadUtils' import {TransferProgressEvent} from '@azure/ms-rest-js' test('upload progress tracked correctly', () => { diff --git a/packages/cache/__tests__/util.test.ts b/packages/cache/__tests__/utils.test.ts similarity index 99% rename from packages/cache/__tests__/util.test.ts rename to packages/cache/__tests__/utils.test.ts index 3ba3bba744..cb3d0dde08 100644 --- a/packages/cache/__tests__/util.test.ts +++ b/packages/cache/__tests__/utils.test.ts @@ -1,4 +1,4 @@ -import {maskSigUrl, maskSecretUrls} from '../src/internal/shared/util' +import {maskSigUrl, maskSecretUrls} from '../src/internal/shared/utils' import {setSecret, debug} from '@actions/core' jest.mock('@actions/core') diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index f7b2d1937e..8a2091a766 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import * as path from 'path' -import * as utils from './internal/cacheUtils' +import * as utils from './internal/shared/utils' import * as cacheHttpClient from './internal/cacheHttpClient' import * as cacheTwirpClient from './internal/shared/cacheTwirpClient' import {getCacheServiceVersion, isGhes} from './internal/config' @@ -12,7 +12,7 @@ import { FinalizeCacheEntryUploadResponse, GetCacheEntryDownloadURLRequest } from './generated/results/api/v1/cache' -import {CacheFileSizeLimit} from './internal/constants' +import {CacheFileSizeLimit} from './internal/shared/constants' export class ValidationError extends Error { constructor(message: string) { super(message) diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts index 2470555bb1..91a93b7aa1 100644 --- a/packages/cache/src/internal/cacheHttpClient.ts +++ b/packages/cache/src/internal/cacheHttpClient.ts @@ -7,8 +7,8 @@ import { } from '@actions/http-client/lib/interfaces' import * as fs from 'fs' import {URL} from 'url' -import * as utils from './cacheUtils' -import {uploadCacheArchiveSDK} from './uploadUtils' +import * as utils from './shared/utils' +import {uploadCacheArchiveSDK} from './shared/uploadUtils' import { ArtifactCacheEntry, InternalCacheOptions, @@ -22,7 +22,7 @@ import { downloadCacheHttpClient, downloadCacheHttpClientConcurrent, downloadCacheStorageSDK -} from './downloadUtils' +} from './shared/downloadUtils' import { DownloadOptions, UploadOptions, @@ -33,7 +33,7 @@ import { isSuccessStatusCode, retryHttpClientResponse, retryTypedResponse -} from './requestUtils' +} from './shared/requestUtils' import {getCacheServiceURL} from './config' import {getUserAgentString} from './shared/user-agent' diff --git a/packages/cache/src/internal/contracts.d.ts b/packages/cache/src/internal/contracts.d.ts index 6fcd9427c8..8aa44e25a2 100644 --- a/packages/cache/src/internal/contracts.d.ts +++ b/packages/cache/src/internal/contracts.d.ts @@ -1,4 +1,4 @@ -import {CompressionMethod} from './constants' +import {CompressionMethod} from './shared/constants' import {TypedResponse} from '@actions/http-client/lib/interfaces' import {HttpClientError} from '@actions/http-client' diff --git a/packages/cache/src/internal/shared/cacheTwirpClient.ts b/packages/cache/src/internal/shared/cacheTwirpClient.ts index f6c2af61b3..574d56f690 100644 --- a/packages/cache/src/internal/shared/cacheTwirpClient.ts +++ b/packages/cache/src/internal/shared/cacheTwirpClient.ts @@ -2,11 +2,11 @@ import {info, debug} from '@actions/core' import {getUserAgentString} from './user-agent' import {NetworkError, UsageError} from './errors' import {getCacheServiceURL} from '../config' -import {getRuntimeToken} from '../cacheUtils' +import {getRuntimeToken} from '../shared/utils' import {BearerCredentialHandler} from '@actions/http-client/lib/auth' import {HttpClient, HttpClientResponse, HttpCodes} from '@actions/http-client' import {CacheServiceClientJSON} from '../../generated/results/api/v1/cache.twirp-client' -import {maskSecretUrls} from './util' +import {maskSecretUrls} from './requestUtils' // The twirp http client must implement this interface interface Rpc { diff --git a/packages/cache/src/internal/constants.ts b/packages/cache/src/internal/shared/constants.ts similarity index 100% rename from packages/cache/src/internal/constants.ts rename to packages/cache/src/internal/shared/constants.ts diff --git a/packages/cache/src/internal/downloadUtils.ts b/packages/cache/src/internal/shared/downloadUtils.ts similarity index 99% rename from packages/cache/src/internal/downloadUtils.ts rename to packages/cache/src/internal/shared/downloadUtils.ts index de57ed78ff..3d8e511436 100644 --- a/packages/cache/src/internal/downloadUtils.ts +++ b/packages/cache/src/internal/shared/downloadUtils.ts @@ -7,9 +7,9 @@ import * as fs from 'fs' import * as stream from 'stream' import * as util from 'util' -import * as utils from './cacheUtils' +import * as utils from './utils' import {SocketTimeout} from './constants' -import {DownloadOptions} from '../options' +import {DownloadOptions} from '../../options' import {retryHttpClientResponse} from './requestUtils' import {AbortController} from '@azure/abort-controller' diff --git a/packages/cache/src/internal/requestUtils.ts b/packages/cache/src/internal/shared/requestUtils.ts similarity index 57% rename from packages/cache/src/internal/requestUtils.ts rename to packages/cache/src/internal/shared/requestUtils.ts index 043c8a7cef..78113c79c4 100644 --- a/packages/cache/src/internal/requestUtils.ts +++ b/packages/cache/src/internal/shared/requestUtils.ts @@ -5,7 +5,8 @@ import { HttpClientResponse } from '@actions/http-client' import {DefaultRetryDelay, DefaultRetryAttempts} from './constants' -import {ITypedResponseWithError} from './contracts' +import {ITypedResponseWithError} from '../contracts' +import {debug, setSecret} from '@actions/core' export function isSuccessStatusCode(statusCode?: number): boolean { if (!statusCode) { @@ -136,3 +137,78 @@ export async function retryHttpClientResponse( delay ) } + +/** + * Masks the `sig` parameter in a URL and sets it as a secret. + * + * @param url - The URL containing the signature parameter to mask + * @remarks + * This function attempts to parse the provided URL and identify the 'sig' query parameter. + * If found, it registers both the raw and URL-encoded signature values as secrets using + * the Actions `setSecret` API, which prevents them from being displayed in logs. + * + * The function handles errors gracefully if URL parsing fails, logging them as debug messages. + * + * @example + * ```typescript + * // Mask a signature in an Azure SAS token URL + * maskSigUrl('https://example.blob.core.windows.net/container/file.txt?sig=abc123&se=2023-01-01'); + * ``` + */ +export function maskSigUrl(url: string): void { + if (!url) return + try { + const parsedUrl = new URL(url) + const signature = parsedUrl.searchParams.get('sig') + if (signature) { + setSecret(signature) + setSecret(encodeURIComponent(signature)) + } + } catch (error) { + debug( + `Failed to parse URL: ${url} ${ + error instanceof Error ? error.message : String(error) + }` + ) + } +} + +/** + * Masks sensitive information in URLs containing signature parameters. + * Currently supports masking 'sig' parameters in the 'signed_upload_url' + * and 'signed_download_url' properties of the provided object. + * + * @param body - The object should contain a signature + * @remarks + * This function extracts URLs from the object properties and calls maskSigUrl + * on each one to redact sensitive signature information. The function doesn't + * modify the original object; it only marks the signatures as secrets for + * logging purposes. + * + * @example + * ```typescript + * const responseBody = { + * signed_upload_url: 'https://blob.core.windows.net/?sig=abc123', + * signed_download_url: 'https://blob.core/windows.net/?sig=def456' + * }; + * maskSecretUrls(responseBody); + * ``` + */ +export function maskSecretUrls(body: Record | null): void { + if (typeof body !== 'object' || body === null) { + debug('body is not an object or is null') + return + } + if ( + 'signed_upload_url' in body && + typeof body.signed_upload_url === 'string' + ) { + maskSigUrl(body.signed_upload_url) + } + if ( + 'signed_download_url' in body && + typeof body.signed_download_url === 'string' + ) { + maskSigUrl(body.signed_download_url) + } +} diff --git a/packages/cache/src/internal/uploadUtils.ts b/packages/cache/src/internal/shared/uploadUtils.ts similarity index 97% rename from packages/cache/src/internal/uploadUtils.ts rename to packages/cache/src/internal/shared/uploadUtils.ts index 1b4f7af0d1..84777f17da 100644 --- a/packages/cache/src/internal/uploadUtils.ts +++ b/packages/cache/src/internal/shared/uploadUtils.ts @@ -6,8 +6,8 @@ import { BlockBlobParallelUploadOptions } from '@azure/storage-blob' import {TransferProgressEvent} from '@azure/ms-rest-js' -import {InvalidResponseError} from './shared/errors' -import {UploadOptions} from '../options' +import {InvalidResponseError} from './errors' +import {UploadOptions} from '../../options' /** * Class for tracking the upload state and displaying stats. diff --git a/packages/cache/src/internal/shared/util.ts b/packages/cache/src/internal/shared/util.ts deleted file mode 100644 index 36d2ebfdce..0000000000 --- a/packages/cache/src/internal/shared/util.ts +++ /dev/null @@ -1,76 +0,0 @@ -import {debug, setSecret} from '@actions/core' - -/** - * Masks the `sig` parameter in a URL and sets it as a secret. - * - * @param url - The URL containing the signature parameter to mask - * @remarks - * This function attempts to parse the provided URL and identify the 'sig' query parameter. - * If found, it registers both the raw and URL-encoded signature values as secrets using - * the Actions `setSecret` API, which prevents them from being displayed in logs. - * - * The function handles errors gracefully if URL parsing fails, logging them as debug messages. - * - * @example - * ```typescript - * // Mask a signature in an Azure SAS token URL - * maskSigUrl('https://example.blob.core.windows.net/container/file.txt?sig=abc123&se=2023-01-01'); - * ``` - */ -export function maskSigUrl(url: string): void { - if (!url) return - try { - const parsedUrl = new URL(url) - const signature = parsedUrl.searchParams.get('sig') - if (signature) { - setSecret(signature) - setSecret(encodeURIComponent(signature)) - } - } catch (error) { - debug( - `Failed to parse URL: ${url} ${ - error instanceof Error ? error.message : String(error) - }` - ) - } -} - -/** - * Masks sensitive information in URLs containing signature parameters. - * Currently supports masking 'sig' parameters in the 'signed_upload_url' - * and 'signed_download_url' properties of the provided object. - * - * @param body - The object should contain a signature - * @remarks - * This function extracts URLs from the object properties and calls maskSigUrl - * on each one to redact sensitive signature information. The function doesn't - * modify the original object; it only marks the signatures as secrets for - * logging purposes. - * - * @example - * ```typescript - * const responseBody = { - * signed_upload_url: 'https://blob.core.windows.net/?sig=abc123', - * signed_download_url: 'https://blob.core/windows.net/?sig=def456' - * }; - * maskSecretUrls(responseBody); - * ``` - */ -export function maskSecretUrls(body: Record | null): void { - if (typeof body !== 'object' || body === null) { - debug('body is not an object or is null') - return - } - if ( - 'signed_upload_url' in body && - typeof body.signed_upload_url === 'string' - ) { - maskSigUrl(body.signed_upload_url) - } - if ( - 'signed_download_url' in body && - typeof body.signed_download_url === 'string' - ) { - maskSigUrl(body.signed_download_url) - } -} diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/shared/utils.ts similarity index 99% rename from packages/cache/src/internal/cacheUtils.ts rename to packages/cache/src/internal/shared/utils.ts index de9053eae0..b244bf4256 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/shared/utils.ts @@ -1,3 +1,4 @@ +import {debug, setSecret} from '@actions/core' import * as core from '@actions/core' import * as exec from '@actions/exec' import * as glob from '@actions/glob' diff --git a/packages/cache/src/internal/tar.ts b/packages/cache/src/internal/tar.ts index adf610694f..31424621c1 100644 --- a/packages/cache/src/internal/tar.ts +++ b/packages/cache/src/internal/tar.ts @@ -2,7 +2,7 @@ import {exec} from '@actions/exec' import * as io from '@actions/io' import {existsSync, writeFileSync} from 'fs' import * as path from 'path' -import * as utils from './cacheUtils' +import * as utils from './shared/utils' import {ArchiveTool} from './contracts' import { CompressionMethod, @@ -10,7 +10,7 @@ import { ArchiveToolType, TarFilename, ManifestFilename -} from './constants' +} from './shared/constants' const IS_WINDOWS = process.platform === 'win32' diff --git a/packages/github/__tests__/github.test.ts b/packages/github/__tests__/github.test.ts index 50fdc74a2c..352a1a1dc9 100644 --- a/packages/github/__tests__/github.test.ts +++ b/packages/github/__tests__/github.test.ts @@ -1,7 +1,7 @@ import * as http from 'http' import {createProxy} from 'proxy' import {getOctokit} from '../src/github' -import {GitHub, getOctokitOptions} from '../src/utils' +import {GitHub, getOctokitOptions} from '../src/internal/shared/utils' describe('@actions/github', () => { const proxyUrl = 'http://127.0.0.1:8080' diff --git a/packages/github/src/context.ts b/packages/github/src/context.ts index 691c9690d0..9b5b51cfcd 100644 --- a/packages/github/src/context.ts +++ b/packages/github/src/context.ts @@ -1,5 +1,5 @@ // Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/main/src/context.ts -import {WebhookPayload} from './interfaces' +import {WebhookPayload} from './internal/shared/interfaces' import {readFileSync, existsSync} from 'fs' import {EOL} from 'os' diff --git a/packages/github/src/github.ts b/packages/github/src/github.ts index b4ed7133e4..5a3925d6cf 100644 --- a/packages/github/src/github.ts +++ b/packages/github/src/github.ts @@ -1,5 +1,5 @@ import * as Context from './context' -import {GitHub, getOctokitOptions} from './utils' +import {GitHub, getOctokitOptions} from './internal/shared/utils' // octokit + plugins import {OctokitOptions, OctokitPlugin} from '@octokit/core/dist-types/types' diff --git a/packages/github/src/interfaces.ts b/packages/github/src/internal/shared/interfaces.ts similarity index 100% rename from packages/github/src/interfaces.ts rename to packages/github/src/internal/shared/interfaces.ts diff --git a/packages/github/src/internal/utils.ts b/packages/github/src/internal/shared/utils.ts similarity index 55% rename from packages/github/src/internal/utils.ts rename to packages/github/src/internal/shared/utils.ts index 2c520789bf..0e37947486 100644 --- a/packages/github/src/internal/utils.ts +++ b/packages/github/src/internal/shared/utils.ts @@ -2,7 +2,12 @@ import * as http from 'http' import * as httpClient from '@actions/http-client' import {OctokitOptions} from '@octokit/core/dist-types/types' import {ProxyAgent, fetch} from 'undici' +import * as Context from '../../context' +// octokit + plugins +import {Octokit} from '@octokit/core' +import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods' +import {paginateRest} from '@octokit/plugin-paginate-rest' export function getAuthString( token: string, options: OctokitOptions @@ -42,3 +47,40 @@ export function getProxyFetch(destinationUrl): typeof fetch { export function getApiBaseUrl(): string { return process.env['GITHUB_API_URL'] || 'https://api.github.com' } + +export const context = new Context.Context() + +const baseUrl = getApiBaseUrl() +export const defaults: OctokitOptions = { + baseUrl, + request: { + agent: getProxyAgent(baseUrl), + fetch: getProxyFetch(baseUrl) + } +} + +export const GitHub = Octokit.plugin( + restEndpointMethods, + paginateRest +).defaults(defaults) + +/** + * Convience function to correctly format Octokit Options to pass into the constructor. + * + * @param token the repo PAT or GITHUB_TOKEN + * @param options other options to set + */ +export function getOctokitOptions( + token: string, + options?: OctokitOptions +): OctokitOptions { + const opts = Object.assign({}, options || {}) // Shallow clone - don't mutate the object provided by the caller + + // Auth + const auth = getAuthString(token, opts) + if (auth) { + opts.auth = auth + } + + return opts +} diff --git a/packages/github/src/utils.ts b/packages/github/src/utils.ts deleted file mode 100644 index 0c50d6ac82..0000000000 --- a/packages/github/src/utils.ts +++ /dev/null @@ -1,45 +0,0 @@ -import * as Context from './context' -import * as Utils from './internal/utils' - -// octokit + plugins -import {Octokit} from '@octokit/core' -import {OctokitOptions} from '@octokit/core/dist-types/types' -import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods' -import {paginateRest} from '@octokit/plugin-paginate-rest' - -export const context = new Context.Context() - -const baseUrl = Utils.getApiBaseUrl() -export const defaults: OctokitOptions = { - baseUrl, - request: { - agent: Utils.getProxyAgent(baseUrl), - fetch: Utils.getProxyFetch(baseUrl) - } -} - -export const GitHub = Octokit.plugin( - restEndpointMethods, - paginateRest -).defaults(defaults) - -/** - * Convience function to correctly format Octokit Options to pass into the constructor. - * - * @param token the repo PAT or GITHUB_TOKEN - * @param options other options to set - */ -export function getOctokitOptions( - token: string, - options?: OctokitOptions -): OctokitOptions { - const opts = Object.assign({}, options || {}) // Shallow clone - don't mutate the object provided by the caller - - // Auth - const auth = Utils.getAuthString(token, opts) - if (auth) { - opts.auth = auth - } - - return opts -} diff --git a/packages/glob/__tests__/internal-pattern-helper.test.ts b/packages/glob/__tests__/internal-pattern-helper.test.ts index 1d60f6b3b4..47d70502fa 100644 --- a/packages/glob/__tests__/internal-pattern-helper.test.ts +++ b/packages/glob/__tests__/internal-pattern-helper.test.ts @@ -1,7 +1,7 @@ import * as path from 'path' import * as patternHelper from '../src/internal-pattern-helper' import {MatchKind} from '../src/internal-match-kind' -import {IS_WINDOWS} from '../../io/src/io-util' +import {IS_WINDOWS} from '../../io/src/shared/utils' import {Pattern} from '../src/internal-pattern' describe('pattern-helper', () => { diff --git a/packages/io/__tests__/io.test.ts b/packages/io/__tests__/io.test.ts index c05be13f33..106a08da18 100644 --- a/packages/io/__tests__/io.test.ts +++ b/packages/io/__tests__/io.test.ts @@ -3,7 +3,7 @@ import {promises as fs} from 'fs' import * as os from 'os' import * as path from 'path' import * as io from '../src/io' -import * as ioUtil from '../src/io-util' +import * as ioUtil from '../src/shared/utils' describe('cp', () => { beforeAll(async () => { diff --git a/packages/io/src/io.ts b/packages/io/src/io.ts index bbd8efd319..c027cbab4b 100644 --- a/packages/io/src/io.ts +++ b/packages/io/src/io.ts @@ -1,6 +1,6 @@ import {ok} from 'assert' import * as path from 'path' -import * as ioUtil from './io-util' +import * as ioUtil from './shared/utils' /** * Interface for cp/mv options diff --git a/packages/io/src/io-util.ts b/packages/io/src/shared/utils.ts similarity index 100% rename from packages/io/src/io-util.ts rename to packages/io/src/shared/utils.ts