Skip to content

Commit be44d4d

Browse files
committed
Fix block IDs
1 parent 834677d commit be44d4d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/caching/github-actions-cache.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ export class GitHubActionsCache implements Cache {
334334
// See https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/cache/src/internal/uploadUtils.ts#L132
335335
// TODO(aomarks) Chunks could be uploaded in parallel.
336336
const blockIds: string[] = [];
337+
let blockIdx = 0;
337338
while (offset < tarballBytes) {
338339
const chunkSize = Math.min(tarballBytes - offset, maxChunkSize);
339340
const start = offset;
@@ -358,7 +359,11 @@ export class GitHubActionsCache implements Cache {
358359
};
359360
const chunkUrl = new URL(uploadUrl);
360361
chunkUrl.searchParams.set('comp', 'block');
361-
const blockId = offset.toString(16);
362+
// All block IDs must be the same length within a blob.
363+
const blockId = Buffer.from(
364+
blockIdx.toString(16).padStart(4, '0'),
365+
).toString('base64');
366+
blockIdx++;
362367
blockIds.push(blockId);
363368
chunkUrl.searchParams.set('blockid', blockId);
364369
using requestResult = this.#request(chunkUrl, opts);
@@ -389,16 +394,12 @@ export class GitHubActionsCache implements Cache {
389394
const doneXmlBody = Buffer.from(
390395
`<?xml version="1.0" encoding="utf-8"?>
391396
<BlockList>
392-
${blockIds
393-
.map(
394-
(blockId) =>
395-
` <Committed>${Buffer.from(blockId).toString('base64')}</Committed>`,
396-
)
397-
.join('\n ')}
397+
${blockIds.map((blockId) => ` <Committed>${blockId}</Committed>`).join('\n')}
398398
</BlockList>
399399
`,
400400
'utf8',
401401
);
402+
console.log({doneXmlBody});
402403
using requestResult = this.#request(doneUrl, {
403404
method: 'PUT',
404405
headers: {

0 commit comments

Comments
 (0)