Add isGhes gate and refactor to clean up circular dependencies

This commit is contained in:
Bassem Dghaidi
2024-11-21 04:01:44 -08:00
committed by GitHub
parent ab58a59f33
commit 267841d7bd
8 changed files with 79 additions and 64 deletions

View File

@@ -6,7 +6,7 @@ import {
BlobDownloadOptions
} from '@azure/storage-blob'
export async function DownloadCacheFile(
export async function downloadCacheFile(
signedUploadURL: string,
archivePath: string
): Promise<{}> {

View File

@@ -5,7 +5,7 @@ import {
BlockBlobParallelUploadOptions
} from '@azure/storage-blob'
export async function UploadCacheFile(
export async function uploadCacheFile(
signedUploadURL: string,
archivePath: string
): Promise<{}> {

View File

@@ -133,19 +133,6 @@ export function assertDefined<T>(name: string, value?: T): T {
return value
}
export function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
)
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
const isGitHubHost = hostname === 'GITHUB.COM'
const isGheHost =
hostname.endsWith('.GHE.COM') || hostname.endsWith('.GHE.LOCALHOST')
return !isGitHubHost && !isGheHost
}
export function getCacheVersion(
paths: string[],
compressionMethod?: CompressionMethod,

View File

@@ -1,9 +1,29 @@
export function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
)
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
const isGitHubHost = hostname === 'GITHUB.COM'
const isGheHost = hostname.endsWith('.GHE.COM')
const isLocalHost = hostname.endsWith('.LOCALHOST')
return !isGitHubHost && !isGheHost && !isLocalHost
}
export function getCacheServiceVersion(): string {
// Cache service v2 is not supported on GHES. We will default to
// cache service v1 even if the feature flag was enabled by user.
if (isGhes()) return 'v1'
return process.env['ACTIONS_CACHE_SERVICE_V2'] ? 'v2' : 'v1'
}
export function getCacheServiceURL(): string {
const version = getCacheServiceVersion()
// Based on the version of the cache service, we will determine which
// URL to use.
switch (version) {
case 'v1':
return (