mirror of https://github.com/actions/toolkit
Add v2 cache upload
parent
c8466d1fac
commit
66d5434f23
|
@ -6,7 +6,8 @@ import * as cacheHttpClient from './internal/cacheHttpClient'
|
||||||
import * as cacheTwirpClient from './internal/cacheTwirpClient'
|
import * as cacheTwirpClient from './internal/cacheTwirpClient'
|
||||||
import {createTar, extractTar, listTar} from './internal/tar'
|
import {createTar, extractTar, listTar} from './internal/tar'
|
||||||
import {DownloadOptions, UploadOptions} from './options'
|
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 {
|
export class ValidationError extends Error {
|
||||||
constructor(message: string) {
|
constructor(message: string) {
|
||||||
|
@ -177,12 +178,12 @@ export async function saveCache(
|
||||||
// TODO: REMOVE ME
|
// TODO: REMOVE ME
|
||||||
// Making a call to the service
|
// Making a call to the service
|
||||||
const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient()
|
const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient()
|
||||||
const getBlobRequest: GetCachedBlobRequest = {
|
const getSignedUploadURL: GetCacheBlobUploadURLRequest = {
|
||||||
owner: "link-/test",
|
organization: "github",
|
||||||
keys: ['test-123412631236126'],
|
keys: [key],
|
||||||
}
|
}
|
||||||
const getBlobResponse = await twirpClient.GetCachedBlob(getBlobRequest)
|
const signedUploadURL: GetCacheBlobUploadURLResponse = await twirpClient.GetCacheBlobUploadURL(getSignedUploadURL)
|
||||||
core.info(`GetCachedBlobResponse: ${JSON.stringify(getBlobResponse)}`)
|
core.info(`GetCacheBlobUploadURLResponse: ${JSON.stringify(signedUploadURL)}`)
|
||||||
|
|
||||||
const compressionMethod = await utils.getCompressionMethod()
|
const compressionMethod = await utils.getCompressionMethod()
|
||||||
let cacheId = -1
|
let cacheId = -1
|
||||||
|
@ -251,6 +252,14 @@ export async function saveCache(
|
||||||
|
|
||||||
core.debug(`Saving Cache (ID: ${cacheId})`)
|
core.debug(`Saving Cache (ID: ${cacheId})`)
|
||||||
await cacheHttpClient.saveCache(cacheId, archivePath, options)
|
await cacheHttpClient.saveCache(cacheId, archivePath, options)
|
||||||
|
|
||||||
|
// Cache v2 upload
|
||||||
|
// inputs:
|
||||||
|
// - getSignedUploadURL
|
||||||
|
// - archivePath
|
||||||
|
core.debug(`Saving Cache v2: ${archivePath}`)
|
||||||
|
await UploadCache(signedUploadURL, archivePath)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const typedError = error as Error
|
const typedError = error as Error
|
||||||
if (typedError.name === ValidationError.name) {
|
if (typedError.name === ValidationError.name) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue