mirror of https://github.com/actions/toolkit
Fix service urls
parent
07e51a445e
commit
e62c6428e7
|
@ -1,7 +1,7 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as path from 'path'
|
||||
import * as utils from './internal/cacheUtils'
|
||||
import { CacheServiceVersion, CacheUrl } from './internal/constants'
|
||||
import * as config from './internal/config'
|
||||
import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||
import * as cacheTwirpClient from './internal/cacheTwirpClient'
|
||||
import { createTar, extractTar, listTar } from './internal/tar'
|
||||
|
@ -67,9 +67,9 @@ function checkKey(key: string): void {
|
|||
* @returns boolean return true if Actions cache service feature is available, otherwise false
|
||||
*/
|
||||
|
||||
export function isFeatureAvailable(): boolean {
|
||||
return !!CacheUrl
|
||||
}
|
||||
// export function isFeatureAvailable(): boolean {
|
||||
// return !!CacheUrl
|
||||
// }
|
||||
|
||||
/**
|
||||
* Restores cache from keys
|
||||
|
@ -90,8 +90,9 @@ export async function restoreCache(
|
|||
): Promise<string | undefined> {
|
||||
checkPaths(paths)
|
||||
|
||||
console.debug(`Cache Service Version: ${CacheServiceVersion}`)
|
||||
switch (CacheServiceVersion) {
|
||||
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||
console.debug(`Cache Service Version: ${cacheServiceVersion}`)
|
||||
switch (cacheServiceVersion) {
|
||||
case "v2":
|
||||
return await restoreCachev2(paths, primaryKey, restoreKeys, options, enableCrossOsArchive)
|
||||
case "v1":
|
||||
|
@ -265,8 +266,9 @@ export async function saveCache(
|
|||
checkPaths(paths)
|
||||
checkKey(key)
|
||||
|
||||
console.debug(`Cache Service Version: ${CacheServiceVersion}`)
|
||||
switch (CacheServiceVersion) {
|
||||
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||
console.debug(`Cache Service Version: ${cacheServiceVersion}`)
|
||||
switch (cacheServiceVersion) {
|
||||
case "v2":
|
||||
return await saveCachev2(paths, key, options, enableCrossOsArchive)
|
||||
case "v1":
|
||||
|
|
|
@ -33,10 +33,10 @@ import {
|
|||
retryHttpClientResponse,
|
||||
retryTypedResponse
|
||||
} from './requestUtils'
|
||||
import { CacheUrl } from './constants'
|
||||
import { getCacheServiceURL } from './config'
|
||||
|
||||
function getCacheApiUrl(resource: string): string {
|
||||
const baseUrl: string = CacheUrl || ''
|
||||
const baseUrl: string = getCacheServiceURL()
|
||||
if (!baseUrl) {
|
||||
throw new Error('Cache Service Url not found, unable to restore cache.')
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ import { HttpClient, HttpClientResponse, HttpCodes } from '@actions/http-client'
|
|||
import { BearerCredentialHandler } from '@actions/http-client/lib/auth'
|
||||
import { info, debug } from '@actions/core'
|
||||
import { CacheServiceClientJSON } from '../generated/results/api/v1/cache.twirp'
|
||||
import { CacheUrl } from './constants'
|
||||
import { getRuntimeToken } from './config'
|
||||
import { getRuntimeToken, getCacheServiceURL } from './config'
|
||||
// import {getUserAgentString} from './user-agent'
|
||||
// import {NetworkError, UsageError} from './errors'
|
||||
|
||||
|
@ -31,7 +30,7 @@ class CacheServiceClient implements Rpc {
|
|||
retryMultiplier?: number
|
||||
) {
|
||||
const token = getRuntimeToken()
|
||||
this.baseUrl = CacheUrl
|
||||
this.baseUrl = getCacheServiceURL()
|
||||
if (maxAttempts) {
|
||||
this.maxAttempts = maxAttempts
|
||||
}
|
||||
|
|
|
@ -5,3 +5,19 @@ export function getRuntimeToken(): string {
|
|||
}
|
||||
return token
|
||||
}
|
||||
|
||||
export function getCacheServiceVersion(): string {
|
||||
return process.env['ACTIONS_CACHE_SERVICE_VERSION'] || 'v1'
|
||||
}
|
||||
|
||||
export function getCacheServiceURL(): string {
|
||||
const version = getCacheServiceVersion()
|
||||
switch (version) {
|
||||
case 'v1':
|
||||
return process.env['ACTIONS_CACHE_URL'] || process.env['ACTIONS_RESULTS_URL'] || ""
|
||||
case 'v2':
|
||||
return process.env['ACTIONS_RESULTS_URL'] || ""
|
||||
default:
|
||||
throw new Error(`Unsupported cache service version: ${version}`)
|
||||
}
|
||||
}
|
|
@ -35,8 +35,4 @@ export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\S
|
|||
|
||||
export const TarFilename = 'cache.tar'
|
||||
|
||||
export const ManifestFilename = 'manifest.txt'
|
||||
|
||||
// Cache Service Metadata
|
||||
export const CacheUrl = `${process.env['ACTIONS_CACHE_URL_NEXT']} || ${process.env['ACTIONS_CACHE_URL']}`
|
||||
export const CacheServiceVersion = `${process.env['ACTIONS_CACHE_URL_NEXT'] ? 'v2' : 'v1'}`
|
||||
export const ManifestFilename = 'manifest.txt'
|
Loading…
Reference in New Issue