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 core from '@actions/core'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as utils from './internal/cacheUtils'
|
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 cacheHttpClient from './internal/cacheHttpClient'
|
||||||
import * as cacheTwirpClient from './internal/cacheTwirpClient'
|
import * as cacheTwirpClient from './internal/cacheTwirpClient'
|
||||||
import { createTar, extractTar, listTar } from './internal/tar'
|
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
|
* @returns boolean return true if Actions cache service feature is available, otherwise false
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function isFeatureAvailable(): boolean {
|
// export function isFeatureAvailable(): boolean {
|
||||||
return !!CacheUrl
|
// return !!CacheUrl
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restores cache from keys
|
* Restores cache from keys
|
||||||
|
@ -90,8 +90,9 @@ export async function restoreCache(
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
checkPaths(paths)
|
checkPaths(paths)
|
||||||
|
|
||||||
console.debug(`Cache Service Version: ${CacheServiceVersion}`)
|
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||||
switch (CacheServiceVersion) {
|
console.debug(`Cache Service Version: ${cacheServiceVersion}`)
|
||||||
|
switch (cacheServiceVersion) {
|
||||||
case "v2":
|
case "v2":
|
||||||
return await restoreCachev2(paths, primaryKey, restoreKeys, options, enableCrossOsArchive)
|
return await restoreCachev2(paths, primaryKey, restoreKeys, options, enableCrossOsArchive)
|
||||||
case "v1":
|
case "v1":
|
||||||
|
@ -265,8 +266,9 @@ export async function saveCache(
|
||||||
checkPaths(paths)
|
checkPaths(paths)
|
||||||
checkKey(key)
|
checkKey(key)
|
||||||
|
|
||||||
console.debug(`Cache Service Version: ${CacheServiceVersion}`)
|
const cacheServiceVersion: string = config.getCacheServiceVersion()
|
||||||
switch (CacheServiceVersion) {
|
console.debug(`Cache Service Version: ${cacheServiceVersion}`)
|
||||||
|
switch (cacheServiceVersion) {
|
||||||
case "v2":
|
case "v2":
|
||||||
return await saveCachev2(paths, key, options, enableCrossOsArchive)
|
return await saveCachev2(paths, key, options, enableCrossOsArchive)
|
||||||
case "v1":
|
case "v1":
|
||||||
|
|
|
@ -33,10 +33,10 @@ import {
|
||||||
retryHttpClientResponse,
|
retryHttpClientResponse,
|
||||||
retryTypedResponse
|
retryTypedResponse
|
||||||
} from './requestUtils'
|
} from './requestUtils'
|
||||||
import { CacheUrl } from './constants'
|
import { getCacheServiceURL } from './config'
|
||||||
|
|
||||||
function getCacheApiUrl(resource: string): string {
|
function getCacheApiUrl(resource: string): string {
|
||||||
const baseUrl: string = CacheUrl || ''
|
const baseUrl: string = getCacheServiceURL()
|
||||||
if (!baseUrl) {
|
if (!baseUrl) {
|
||||||
throw new Error('Cache Service Url not found, unable to restore cache.')
|
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 { BearerCredentialHandler } from '@actions/http-client/lib/auth'
|
||||||
import { info, debug } from '@actions/core'
|
import { info, debug } from '@actions/core'
|
||||||
import { CacheServiceClientJSON } from '../generated/results/api/v1/cache.twirp'
|
import { CacheServiceClientJSON } from '../generated/results/api/v1/cache.twirp'
|
||||||
import { CacheUrl } from './constants'
|
import { getRuntimeToken, getCacheServiceURL } from './config'
|
||||||
import { getRuntimeToken } from './config'
|
|
||||||
// import {getUserAgentString} from './user-agent'
|
// import {getUserAgentString} from './user-agent'
|
||||||
// import {NetworkError, UsageError} from './errors'
|
// import {NetworkError, UsageError} from './errors'
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ class CacheServiceClient implements Rpc {
|
||||||
retryMultiplier?: number
|
retryMultiplier?: number
|
||||||
) {
|
) {
|
||||||
const token = getRuntimeToken()
|
const token = getRuntimeToken()
|
||||||
this.baseUrl = CacheUrl
|
this.baseUrl = getCacheServiceURL()
|
||||||
if (maxAttempts) {
|
if (maxAttempts) {
|
||||||
this.maxAttempts = maxAttempts
|
this.maxAttempts = maxAttempts
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,3 +5,19 @@ export function getRuntimeToken(): string {
|
||||||
}
|
}
|
||||||
return token
|
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 TarFilename = 'cache.tar'
|
||||||
|
|
||||||
export const ManifestFilename = 'manifest.txt'
|
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'}`
|
|
Loading…
Reference in New Issue