1
0
Fork 0

Add v2 cache upload

Link-/blobcache-spike
Bassem Dghaidi 2024-06-10 10:56:20 -07:00 committed by GitHub
parent c8466d1fac
commit 66d5434f23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 6 deletions

View File

@ -6,7 +6,8 @@ import * as cacheHttpClient from './internal/cacheHttpClient'
import * as cacheTwirpClient from './internal/cacheTwirpClient'
import {createTar, extractTar, listTar} from './internal/tar'
import {DownloadOptions, UploadOptions} from './options'
import {GetCachedBlobRequest} from './generated/results/api/v1/blobcache'
import {GetCacheBlobUploadURLRequest, GetCacheBlobUploadURLResponse} from './generated/results/api/v1/blobcache'
import {UploadCache} from './internal/v2/upload/upload-cache'
export class ValidationError extends Error {
constructor(message: string) {
@ -177,12 +178,12 @@ export async function saveCache(
// TODO: REMOVE ME
// Making a call to the service
const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient()
const getBlobRequest: GetCachedBlobRequest = {
owner: "link-/test",
keys: ['test-123412631236126'],
const getSignedUploadURL: GetCacheBlobUploadURLRequest = {
organization: "github",
keys: [key],
}
const getBlobResponse = await twirpClient.GetCachedBlob(getBlobRequest)
core.info(`GetCachedBlobResponse: ${JSON.stringify(getBlobResponse)}`)
const signedUploadURL: GetCacheBlobUploadURLResponse = await twirpClient.GetCacheBlobUploadURL(getSignedUploadURL)
core.info(`GetCacheBlobUploadURLResponse: ${JSON.stringify(signedUploadURL)}`)
const compressionMethod = await utils.getCompressionMethod()
let cacheId = -1
@ -251,6 +252,14 @@ export async function saveCache(
core.debug(`Saving Cache (ID: ${cacheId})`)
await cacheHttpClient.saveCache(cacheId, archivePath, options)
// Cache v2 upload
// inputs:
// - getSignedUploadURL
// - archivePath
core.debug(`Saving Cache v2: ${archivePath}`)
await UploadCache(signedUploadURL, archivePath)
} catch (error) {
const typedError = error as Error
if (typedError.name === ValidationError.name) {

View File

@ -0,0 +1,22 @@
import * as core from '@actions/core'
import {GetCacheBlobUploadURLResponse} from '../../../generated/results/api/v1/blobcache'
import {BlobClient, BlockBlobParallelUploadOptions} from '@azure/storage-blob'
export async function UploadCache(
uploadURL: GetCacheBlobUploadURLResponse,
archivePath: string,
): Promise<{}> {
core.debug(`Uploading cache to: ${uploadURL}`)
// Specify data transfer options
const uploadOptions: BlockBlobParallelUploadOptions = {
blockSize: 4 * 1024 * 1024, // 4 MiB max block size
concurrency: 2, // maximum number of parallel transfer workers
maxSingleShotSize: 8 * 1024 * 1024, // 8 MiB initial transfer size
};
// Create blob client from container client
const blobClient: BlobClient = new BlobClient(uploadURL.urls[0])
return blobClient.uploadFile(archivePath, uploadOptions);
}