From f7e6edf3a0d9da971c2dd20129ec199e7e70a2de Mon Sep 17 00:00:00 2001 From: Bassem Dghaidi <568794+Link-@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:07:49 -0700 Subject: [PATCH] Implement cache v2 --- dist/restore-only/index.js | 79 +++++++++++++++++++++++++++++++++++--- dist/restore/index.js | 79 +++++++++++++++++++++++++++++++++++--- dist/save-only/index.js | 79 +++++++++++++++++++++++++++++++++++--- dist/save/index.js | 79 +++++++++++++++++++++++++++++++++++--- package-lock.json | 3 ++ 5 files changed, 299 insertions(+), 20 deletions(-) diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index eb25199..145310b 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -9852,6 +9852,7 @@ const constants_1 = __nccwpck_require__(4010); const cacheHttpClient = __importStar(__nccwpck_require__(2370)); const cacheTwirpClient = __importStar(__nccwpck_require__(5451)); const tar_1 = __nccwpck_require__(9099); +const upload_cache_1 = __nccwpck_require__(8105); class ValidationError extends Error { constructor(message) { super(message); @@ -9983,12 +9984,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { // TODO: REMOVE ME // Making a call to the service const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient(); - const getBlobRequest = { - owner: "link-/test", - keys: ['test-123412631236126'], + const getSignedUploadURL = { + organization: "github", + keys: [key], }; - const getBlobResponse = yield twirpClient.GetCachedBlob(getBlobRequest); - core.info(`GetCachedBlobResponse: ${JSON.stringify(getBlobResponse)}`); + const signedUploadURL = yield twirpClient.GetCacheBlobUploadURL(getSignedUploadURL); + core.info(`GetCacheBlobUploadURLResponse: ${JSON.stringify(signedUploadURL)}`); const compressionMethod = yield utils.getCompressionMethod(); let cacheId = -1; const cachePaths = yield utils.resolvePaths(paths); @@ -10029,6 +10030,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { } core.debug(`Saving Cache (ID: ${cacheId})`); yield cacheHttpClient.saveCache(cacheId, archivePath, options); + // Cache v2 upload + // inputs: + // - getSignedUploadURL + // - archivePath + core.debug(`Saving Cache v2: ${archivePath}`); + yield (0, upload_cache_1.UploadCache)(signedUploadURL, archivePath); } catch (error) { const typedError = error; @@ -12312,6 +12319,68 @@ exports.createTar = createTar; /***/ }), +/***/ 8105: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.UploadCache = void 0; +const core = __importStar(__nccwpck_require__(4850)); +const storage_blob_1 = __nccwpck_require__(3864); +function UploadCache(uploadURL, archivePath) { + return __awaiter(this, void 0, void 0, function* () { + core.debug(`Uploading cache to: ${uploadURL}`); + // Specify data transfer options + const uploadOptions = { + blockSize: 4 * 1024 * 1024, + concurrency: 2, + maxSingleShotSize: 8 * 1024 * 1024, // 8 MiB initial transfer size + }; + // Create blob client from container client + // const blobClient: BlobClient = new BlobClient(uploadURL.urls[0]) + const blobClient = new storage_blob_1.BlobClient(uploadURL.urls[0].url); + const blockBlobClient = blobClient.getBlockBlobClient(); + return blockBlobClient.uploadFile(archivePath, uploadOptions); + }); +} +exports.UploadCache = UploadCache; +//# sourceMappingURL=upload-cache.js.map + +/***/ }), + /***/ 7190: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { diff --git a/dist/restore/index.js b/dist/restore/index.js index d284717..83361c6 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -9852,6 +9852,7 @@ const constants_1 = __nccwpck_require__(4010); const cacheHttpClient = __importStar(__nccwpck_require__(2370)); const cacheTwirpClient = __importStar(__nccwpck_require__(5451)); const tar_1 = __nccwpck_require__(9099); +const upload_cache_1 = __nccwpck_require__(8105); class ValidationError extends Error { constructor(message) { super(message); @@ -9983,12 +9984,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { // TODO: REMOVE ME // Making a call to the service const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient(); - const getBlobRequest = { - owner: "link-/test", - keys: ['test-123412631236126'], + const getSignedUploadURL = { + organization: "github", + keys: [key], }; - const getBlobResponse = yield twirpClient.GetCachedBlob(getBlobRequest); - core.info(`GetCachedBlobResponse: ${JSON.stringify(getBlobResponse)}`); + const signedUploadURL = yield twirpClient.GetCacheBlobUploadURL(getSignedUploadURL); + core.info(`GetCacheBlobUploadURLResponse: ${JSON.stringify(signedUploadURL)}`); const compressionMethod = yield utils.getCompressionMethod(); let cacheId = -1; const cachePaths = yield utils.resolvePaths(paths); @@ -10029,6 +10030,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { } core.debug(`Saving Cache (ID: ${cacheId})`); yield cacheHttpClient.saveCache(cacheId, archivePath, options); + // Cache v2 upload + // inputs: + // - getSignedUploadURL + // - archivePath + core.debug(`Saving Cache v2: ${archivePath}`); + yield (0, upload_cache_1.UploadCache)(signedUploadURL, archivePath); } catch (error) { const typedError = error; @@ -12312,6 +12319,68 @@ exports.createTar = createTar; /***/ }), +/***/ 8105: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.UploadCache = void 0; +const core = __importStar(__nccwpck_require__(4850)); +const storage_blob_1 = __nccwpck_require__(3864); +function UploadCache(uploadURL, archivePath) { + return __awaiter(this, void 0, void 0, function* () { + core.debug(`Uploading cache to: ${uploadURL}`); + // Specify data transfer options + const uploadOptions = { + blockSize: 4 * 1024 * 1024, + concurrency: 2, + maxSingleShotSize: 8 * 1024 * 1024, // 8 MiB initial transfer size + }; + // Create blob client from container client + // const blobClient: BlobClient = new BlobClient(uploadURL.urls[0]) + const blobClient = new storage_blob_1.BlobClient(uploadURL.urls[0].url); + const blockBlobClient = blobClient.getBlockBlobClient(); + return blockBlobClient.uploadFile(archivePath, uploadOptions); + }); +} +exports.UploadCache = UploadCache; +//# sourceMappingURL=upload-cache.js.map + +/***/ }), + /***/ 7190: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 0633d93..462e613 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -9852,6 +9852,7 @@ const constants_1 = __nccwpck_require__(4010); const cacheHttpClient = __importStar(__nccwpck_require__(2370)); const cacheTwirpClient = __importStar(__nccwpck_require__(5451)); const tar_1 = __nccwpck_require__(9099); +const upload_cache_1 = __nccwpck_require__(8105); class ValidationError extends Error { constructor(message) { super(message); @@ -9983,12 +9984,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { // TODO: REMOVE ME // Making a call to the service const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient(); - const getBlobRequest = { - owner: "link-/test", - keys: ['test-123412631236126'], + const getSignedUploadURL = { + organization: "github", + keys: [key], }; - const getBlobResponse = yield twirpClient.GetCachedBlob(getBlobRequest); - core.info(`GetCachedBlobResponse: ${JSON.stringify(getBlobResponse)}`); + const signedUploadURL = yield twirpClient.GetCacheBlobUploadURL(getSignedUploadURL); + core.info(`GetCacheBlobUploadURLResponse: ${JSON.stringify(signedUploadURL)}`); const compressionMethod = yield utils.getCompressionMethod(); let cacheId = -1; const cachePaths = yield utils.resolvePaths(paths); @@ -10029,6 +10030,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { } core.debug(`Saving Cache (ID: ${cacheId})`); yield cacheHttpClient.saveCache(cacheId, archivePath, options); + // Cache v2 upload + // inputs: + // - getSignedUploadURL + // - archivePath + core.debug(`Saving Cache v2: ${archivePath}`); + yield (0, upload_cache_1.UploadCache)(signedUploadURL, archivePath); } catch (error) { const typedError = error; @@ -12312,6 +12319,68 @@ exports.createTar = createTar; /***/ }), +/***/ 8105: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.UploadCache = void 0; +const core = __importStar(__nccwpck_require__(4850)); +const storage_blob_1 = __nccwpck_require__(3864); +function UploadCache(uploadURL, archivePath) { + return __awaiter(this, void 0, void 0, function* () { + core.debug(`Uploading cache to: ${uploadURL}`); + // Specify data transfer options + const uploadOptions = { + blockSize: 4 * 1024 * 1024, + concurrency: 2, + maxSingleShotSize: 8 * 1024 * 1024, // 8 MiB initial transfer size + }; + // Create blob client from container client + // const blobClient: BlobClient = new BlobClient(uploadURL.urls[0]) + const blobClient = new storage_blob_1.BlobClient(uploadURL.urls[0].url); + const blockBlobClient = blobClient.getBlockBlobClient(); + return blockBlobClient.uploadFile(archivePath, uploadOptions); + }); +} +exports.UploadCache = UploadCache; +//# sourceMappingURL=upload-cache.js.map + +/***/ }), + /***/ 7190: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { diff --git a/dist/save/index.js b/dist/save/index.js index c51de56..9b681ed 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -9852,6 +9852,7 @@ const constants_1 = __nccwpck_require__(4010); const cacheHttpClient = __importStar(__nccwpck_require__(2370)); const cacheTwirpClient = __importStar(__nccwpck_require__(5451)); const tar_1 = __nccwpck_require__(9099); +const upload_cache_1 = __nccwpck_require__(8105); class ValidationError extends Error { constructor(message) { super(message); @@ -9983,12 +9984,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { // TODO: REMOVE ME // Making a call to the service const twirpClient = cacheTwirpClient.internalBlobCacheTwirpClient(); - const getBlobRequest = { - owner: "link-/test", - keys: ['test-123412631236126'], + const getSignedUploadURL = { + organization: "github", + keys: [key], }; - const getBlobResponse = yield twirpClient.GetCachedBlob(getBlobRequest); - core.info(`GetCachedBlobResponse: ${JSON.stringify(getBlobResponse)}`); + const signedUploadURL = yield twirpClient.GetCacheBlobUploadURL(getSignedUploadURL); + core.info(`GetCacheBlobUploadURLResponse: ${JSON.stringify(signedUploadURL)}`); const compressionMethod = yield utils.getCompressionMethod(); let cacheId = -1; const cachePaths = yield utils.resolvePaths(paths); @@ -10029,6 +10030,12 @@ function saveCache(paths, key, options, enableCrossOsArchive = false) { } core.debug(`Saving Cache (ID: ${cacheId})`); yield cacheHttpClient.saveCache(cacheId, archivePath, options); + // Cache v2 upload + // inputs: + // - getSignedUploadURL + // - archivePath + core.debug(`Saving Cache v2: ${archivePath}`); + yield (0, upload_cache_1.UploadCache)(signedUploadURL, archivePath); } catch (error) { const typedError = error; @@ -12312,6 +12319,68 @@ exports.createTar = createTar; /***/ }), +/***/ 8105: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.UploadCache = void 0; +const core = __importStar(__nccwpck_require__(4850)); +const storage_blob_1 = __nccwpck_require__(3864); +function UploadCache(uploadURL, archivePath) { + return __awaiter(this, void 0, void 0, function* () { + core.debug(`Uploading cache to: ${uploadURL}`); + // Specify data transfer options + const uploadOptions = { + blockSize: 4 * 1024 * 1024, + concurrency: 2, + maxSingleShotSize: 8 * 1024 * 1024, // 8 MiB initial transfer size + }; + // Create blob client from container client + // const blobClient: BlobClient = new BlobClient(uploadURL.urls[0]) + const blobClient = new storage_blob_1.BlobClient(uploadURL.urls[0].url); + const blockBlobClient = blobClient.getBlockBlobClient(); + return blockBlobClient.uploadFile(archivePath, uploadOptions); + }); +} +exports.UploadCache = UploadCache; +//# sourceMappingURL=upload-cache.js.map + +/***/ }), + /***/ 7190: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { diff --git a/package-lock.json b/package-lock.json index 46e2e82..bf73181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -71,6 +71,7 @@ } }, "../toolkit/packages/cache": { + "name": "@actions/cache", "version": "3.2.4", "license": "MIT", "dependencies": { @@ -112,6 +113,7 @@ "extraneous": true }, "../toolkit/packages/exec": { + "name": "@actions/exec", "version": "1.1.1", "license": "MIT", "dependencies": { @@ -119,6 +121,7 @@ } }, "../toolkit/packages/io": { + "name": "@actions/io", "version": "1.1.3", "license": "MIT" },