Skip to content

Consistent naming for utils and utilising shared folder #1999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/artifact/__tests__/delete-artifacts.test.ts
Original file line number Diff line number Diff line change
@@ -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<RequestInterface<object>>
2 changes: 1 addition & 1 deletion packages/artifact/__tests__/download-artifact.test.ts
Original file line number Diff line number Diff line change
@@ -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']
2 changes: 1 addition & 1 deletion packages/artifact/__tests__/get-artifact.test.ts
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion packages/artifact/__tests__/list-artifacts.test.ts
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion packages/artifact/__tests__/upload-artifact.test.ts
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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 =
2 changes: 1 addition & 1 deletion packages/artifact/src/internal/delete/delete-artifact.ts
Original file line number Diff line number Diff line change
@@ -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,
Original file line number Diff line number Diff line change
@@ -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 => {
2 changes: 1 addition & 1 deletion packages/artifact/src/internal/find/get-artifact.ts
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion packages/artifact/src/internal/find/list-artifacts.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion packages/artifact/src/internal/upload/upload-artifact.ts
Original file line number Diff line number Diff line change
@@ -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 {
8 changes: 4 additions & 4 deletions packages/cache/__tests__/cacheHttpClient.test.ts
Original file line number Diff line number Diff line change
@@ -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']
2 changes: 1 addition & 1 deletion packages/cache/__tests__/cacheUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion packages/cache/__tests__/downloadUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions packages/cache/__tests__/requestUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions packages/cache/__tests__/restoreCache.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
11 changes: 7 additions & 4 deletions packages/cache/__tests__/restoreCacheV2.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})

11 changes: 7 additions & 4 deletions packages/cache/__tests__/saveCache.test.ts
Original file line number Diff line number Diff line change
@@ -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 => {
7 changes: 5 additions & 2 deletions packages/cache/__tests__/saveCacheV2.test.ts
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 2 additions & 2 deletions packages/cache/__tests__/tar.test.ts
Original file line number Diff line number Diff line change
@@ -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')

2 changes: 1 addition & 1 deletion packages/cache/__tests__/uploadUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Original file line number Diff line number Diff line change
@@ -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')
4 changes: 2 additions & 2 deletions packages/cache/src/cache.ts
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 4 additions & 4 deletions packages/cache/src/internal/cacheHttpClient.ts
Original file line number Diff line number Diff line change
@@ -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'

2 changes: 1 addition & 1 deletion packages/cache/src/internal/contracts.d.ts
Original file line number Diff line number Diff line change
@@ -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'

4 changes: 2 additions & 2 deletions packages/cache/src/internal/shared/cacheTwirpClient.ts
Original file line number Diff line number Diff line change
@@ -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 {
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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'
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.