mirror of
https://github.com/actions/toolkit.git
synced 2026-08-11 00:00:28 +02:00
Add isGhes gate and refactor to clean up circular dependencies
This commit is contained in:
Vendored
+15
-15
@@ -1,20 +1,20 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import * as config from './internal/config'
|
||||
import * as utils from './internal/cacheUtils'
|
||||
import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||
import * as cacheTwirpClient from './internal/shared/cacheTwirpClient'
|
||||
import {DownloadOptions, UploadOptions} from './options'
|
||||
import {createTar, extractTar, listTar} from './internal/tar'
|
||||
import { getCacheServiceVersion, isGhes } from './internal/config'
|
||||
import { DownloadOptions, UploadOptions } from './options'
|
||||
import { createTar, extractTar, listTar } from './internal/tar'
|
||||
import {
|
||||
CreateCacheEntryRequest,
|
||||
FinalizeCacheEntryUploadRequest,
|
||||
FinalizeCacheEntryUploadResponse,
|
||||
GetCacheEntryDownloadURLRequest
|
||||
} from './generated/results/api/v1/cache'
|
||||
import {CacheFileSizeLimit} from './internal/constants'
|
||||
import {UploadCacheFile} from './internal/blob/upload-cache'
|
||||
import {DownloadCacheFile} from './internal/blob/download-cache'
|
||||
import { CacheFileSizeLimit } from './internal/constants'
|
||||
import { uploadCacheFile } from './internal/blob/upload-cache'
|
||||
import { downloadCacheFile } from './internal/blob/download-cache'
|
||||
export class ValidationError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
@@ -81,7 +81,7 @@ export async function restoreCache(
|
||||
): Promise<string | undefined> {
|
||||
checkPaths(paths)
|
||||
|
||||
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||
const cacheServiceVersion: string = getCacheServiceVersion()
|
||||
switch (cacheServiceVersion) {
|
||||
case 'v2':
|
||||
return await restoreCacheV2(
|
||||
@@ -269,7 +269,7 @@ async function restoreCacheV2(
|
||||
core.debug(`Archive path: ${archivePath}`)
|
||||
core.debug(`Starting download of archive to: ${archivePath}`)
|
||||
|
||||
await DownloadCacheFile(response.signedDownloadUrl, archivePath)
|
||||
await downloadCacheFile(response.signedDownloadUrl, archivePath)
|
||||
|
||||
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath)
|
||||
core.info(
|
||||
@@ -317,7 +317,7 @@ export async function saveCache(
|
||||
checkPaths(paths)
|
||||
checkKey(key)
|
||||
|
||||
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||
const cacheServiceVersion: string = getCacheServiceVersion()
|
||||
switch (cacheServiceVersion) {
|
||||
case 'v2':
|
||||
return await saveCacheV2(paths, key, options, enableCrossOsArchive)
|
||||
@@ -373,7 +373,7 @@ async function saveCacheV1(
|
||||
core.debug(`File Size: ${archiveFileSize}`)
|
||||
|
||||
// For GHES, this check will take place in ReserveCache API with enterprise file size limit
|
||||
if (archiveFileSize > fileSizeLimit && !utils.isGhes()) {
|
||||
if (archiveFileSize > fileSizeLimit && !isGhes()) {
|
||||
throw new Error(
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
@@ -397,9 +397,9 @@ async function saveCacheV1(
|
||||
} else if (reserveCacheResponse?.statusCode === 400) {
|
||||
throw new Error(
|
||||
reserveCacheResponse?.error?.message ??
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
)} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
)} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`
|
||||
)
|
||||
} else {
|
||||
throw new ReserveCacheError(
|
||||
@@ -477,7 +477,7 @@ async function saveCacheV2(
|
||||
core.debug(`File Size: ${archiveFileSize}`)
|
||||
|
||||
// For GHES, this check will take place in ReserveCache API with enterprise file size limit
|
||||
if (archiveFileSize > CacheFileSizeLimit && !utils.isGhes()) {
|
||||
if (archiveFileSize > CacheFileSizeLimit && !isGhes()) {
|
||||
throw new Error(
|
||||
`Cache size of ~${Math.round(
|
||||
archiveFileSize / (1024 * 1024)
|
||||
@@ -504,7 +504,7 @@ async function saveCacheV2(
|
||||
}
|
||||
|
||||
core.debug(`Attempting to upload cache located at: ${archivePath}`)
|
||||
await UploadCacheFile(response.signedUploadUrl, archivePath)
|
||||
await uploadCacheFile(response.signedUploadUrl, archivePath)
|
||||
|
||||
const finalizeRequest: FinalizeCacheEntryUploadRequest = {
|
||||
key,
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import {
|
||||
BlobDownloadOptions
|
||||
} from '@azure/storage-blob'
|
||||
|
||||
export async function DownloadCacheFile(
|
||||
export async function downloadCacheFile(
|
||||
signedUploadURL: string,
|
||||
archivePath: string
|
||||
): Promise<{}> {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
||||
BlockBlobParallelUploadOptions
|
||||
} from '@azure/storage-blob'
|
||||
|
||||
export async function UploadCacheFile(
|
||||
export async function uploadCacheFile(
|
||||
signedUploadURL: string,
|
||||
archivePath: string
|
||||
): Promise<{}> {
|
||||
|
||||
-13
@@ -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,
|
||||
|
||||
+20
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user