Fix service urls

This commit is contained in:
Bassem Dghaidi
2024-09-24 03:29:14 -07:00
committed by GitHub
parent 07e51a445e
commit e62c6428e7
5 changed files with 31 additions and 18 deletions

View File

@@ -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.')
}

View File

@@ -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
}

View File

@@ -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}`)
}
}

View File

@@ -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'