@@ -287,10 +287,12 @@ export class GitHubActionsCache implements Cache {
287287 } ) ;
288288 return false ;
289289 }
290+ const key = this . #computeCacheKey( script ) ;
291+ const version = this . #computeVersion( fingerprint ) ;
290292 const uploadUrl = await this . #reserveCacheEntry(
291293 script ,
292- this . #computeCacheKey ( script ) ,
293- this . #computeVersion ( fingerprint ) ,
294+ key ,
295+ version ,
294296 tarballBytes ,
295297 ) ;
296298 // It's likely that we'll occasionally fail to reserve an entry and get
@@ -304,7 +306,7 @@ export class GitHubActionsCache implements Cache {
304306 if ( ! ( await this . #upload( script , uploadUrl , tarballPath , tarballBytes ) ) ) {
305307 return false ;
306308 }
307- if ( ! ( await this . #commit( script , uploadUrl , tarballBytes ) ) ) {
309+ if ( ! ( await this . #commit( script , key , version , tarballBytes ) ) ) {
308310 return false ;
309311 }
310312 return true ;
@@ -390,25 +392,34 @@ export class GitHubActionsCache implements Cache {
390392 */
391393 async #commit(
392394 script : ScriptReference ,
393- uploadUrl : string ,
395+ key : string ,
396+ version : string ,
394397 tarballBytes : number ,
395398 ) : Promise < boolean > {
396399 const url = new URL (
397- // TODO(aomarks) Definitely wrong.
398- uploadUrl ,
400+ // See
401+ // https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/cache/src/generated/results/api/v1/cache.twirp-client.ts#L132
402+ `/twirp/github.actions.results.api.v1.CacheService/FinalizeCacheEntryUpload` ,
399403 this . #baseUrl,
400404 ) ;
401- const reqBody = JSON . stringify ( {
402- size : tarballBytes ,
403- } ) ;
405+ // See
406+ // https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/cache/src/cache.ts#L555
407+ // and https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/cache/src/generated/results/api/v1/cache.ts#L57
408+ const body = {
409+ key,
410+ version,
411+ sizeBytes : tarballBytes ,
412+ } ;
413+ const bodyBuffer = Buffer . from ( JSON . stringify ( body ) , 'utf8' ) ;
404414 using requestResult = this . #request( url , {
405415 method : 'POST' ,
406416 headers : {
407417 'content-type' : 'application/json' ,
418+ 'content-length' : bodyBuffer . length ,
408419 } ,
409420 } ) ;
410421 const { req, resPromise} = requestResult ;
411- req . end ( reqBody ) ;
422+ req . end ( bodyBuffer ) ;
412423
413424 const result = await resPromise ;
414425 if ( ! this . #maybeHandleServiceDown( result , script ) ) {
@@ -438,6 +449,7 @@ export class GitHubActionsCache implements Cache {
438449 ...options ,
439450 headers : {
440451 // https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/cache/src/internal/cacheHttpClient.ts#L55
452+ // TODO(aomarks) What's the right new accept for v2?
441453 accept : 'application/json;api-version=6.0-preview.1' ,
442454 // https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/http-client/src/auth.ts#L46
443455 authorization : `Bearer ${ this . #authToken} ` ,
@@ -598,8 +610,8 @@ export class GitHubActionsCache implements Cache {
598610 version : string ,
599611 _cacheSize : number ,
600612 ) : Promise < string | undefined > {
601- // See https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/cache/src/generated/results/api/v1/cache.twirp-client.ts#L117
602613 const url = new URL (
614+ // See https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/cache/src/generated/results/api/v1/cache.twirp-client.ts#L117
603615 '/twirp/github.actions.results.api.v1.CacheService/CreateCacheEntry' ,
604616 this . #baseUrl,
605617 ) ;
0 commit comments