@@ -364077,6 +364077,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
364077364077Object.defineProperty(exports, "__esModule", ({ value: true }));
364078364078exports.CloudFunctionClient = void 0;
364079364079const core = __importStar(__webpack_require__(42186));
364080+ const path = __importStar(__webpack_require__(85622));
364081+ const os = __importStar(__webpack_require__(12087));
364080364082const util_1 = __webpack_require__(92629);
364081364083const googleapis_1 = __webpack_require__(44913);
364082364084/**
@@ -364220,13 +364222,24 @@ class CloudFunctionClient {
364220364222 return __awaiter(this, void 0, void 0, function* () {
364221364223 const authClient = yield this.getAuthClient();
364222364224 const deployedFunctions = yield this.listFunctions();
364223- const zipPath = yield util_1.zipDir(cf.sourceDir);
364225+ const zipPath = path.join(os.tmpdir(), `cfsrc-${Math.floor(Math.random() * 100000)}.zip`);
364226+ try {
364227+ yield util_1.zipDir(cf.sourceDir, zipPath);
364228+ }
364229+ catch (err) {
364230+ throw new Error(`Zip file ${zipPath} creation failed: ${err}`);
364231+ }
364224364232 const uploadUrl = yield this.getUploadUrl();
364225364233 if (!uploadUrl.uploadUrl) {
364226364234 throw new Error('Unable to generate signed Url');
364227364235 }
364228364236 // Upload source code
364229- yield util_1.uploadSource(uploadUrl.uploadUrl, zipPath);
364237+ try {
364238+ yield util_1.uploadSource(uploadUrl.uploadUrl, zipPath);
364239+ }
364240+ catch (err) {
364241+ throw new Error(`Zip file upload failed: ${err}`);
364242+ }
364230364243 // Delete temp zip file after upload
364231364244 yield util_1.deleteZipFile(zipPath);
364232364245 cf.setSourceUrl(uploadUrl.uploadUrl);
@@ -364256,7 +364269,7 @@ class CloudFunctionClient {
364256364269 requestBody: cf.request,
364257364270 };
364258364271 const updateFunctionResponse = yield this.gcf.projects.locations.functions.patch(updateFunctionRequest, this.methodOptions);
364259- const awaitUpdate = yield this.pollOperation(updateFunctionResponse.data, 'Updating function deployment');
364272+ const awaitUpdate = yield this.pollOperation(updateFunctionResponse.data, 'Updating function deployment', 2, 150 );
364260364273 core.info('Function deployment updated');
364261364274 return awaitUpdate;
364262364275 }
@@ -364268,7 +364281,7 @@ class CloudFunctionClient {
364268364281 requestBody: cf.request,
364269364282 };
364270364283 const createFunctionResponse = yield this.gcf.projects.locations.functions.create(createFunctionRequest, this.methodOptions);
364271- const awaitCreate = yield this.pollOperation(createFunctionResponse.data, 'Creating function deployment');
364284+ const awaitCreate = yield this.pollOperation(createFunctionResponse.data, 'Creating function deployment', 2, 150 );
364272364285 core.info('Function deployment created');
364273364286 return awaitCreate;
364274364287 }
@@ -364512,6 +364525,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
364512364525Object.defineProperty(exports, "__esModule", ({ value: true }));
364513364526exports.uploadSource = exports.deleteZipFile = exports.zipDir = void 0;
364514364527const fs = __importStar(__webpack_require__(35747));
364528+ const core = __importStar(__webpack_require__(42186));
364515364529const gaxios_1 = __webpack_require__(59555);
364516364530const Archiver = __importStar(__webpack_require__(43084));
364517364531/**
@@ -364520,23 +364534,40 @@ const Archiver = __importStar(__webpack_require__(43084));
364520364534 * @param dirPath Directory to zip.
364521364535 * @returns filepath of the created zip file.
364522364536 */
364523- function zipDir(dirPath) {
364537+ function zipDir(dirPath, outputPath ) {
364524364538 return __awaiter(this, void 0, void 0, function* () {
364525364539 // Check dirpath
364526364540 if (!fs.existsSync(dirPath)) {
364527364541 throw new Error(`Unable to find ${dirPath}`);
364528364542 }
364529- // Create output file stream
364530- const outputPath = `./cfsrc-${Math.floor(Math.random() * 100000)}.zip`;
364531- const output = fs.createWriteStream(outputPath);
364532- // Init archive
364533- const archive = Archiver.create('zip');
364534- archive.pipe(output);
364535- // Add dir to root of archive
364536- archive.directory(dirPath, false);
364537- // Finish writing files
364538- archive.finalize();
364539- return outputPath;
364543+ return new Promise((resolve, reject) => {
364544+ // Create output file stream
364545+ const output = fs.createWriteStream(outputPath);
364546+ output.on('finish', () => {
364547+ core.info(`zip file ${outputPath} created successfully`);
364548+ resolve(outputPath);
364549+ });
364550+ // Init archive
364551+ const archive = Archiver.create('zip');
364552+ // log archive warnings
364553+ archive.on('warning', (err) => {
364554+ if (err.code === 'ENOENT') {
364555+ core.info(err.message);
364556+ }
364557+ else {
364558+ reject(err);
364559+ }
364560+ });
364561+ // listen for all archive data to be written
364562+ output.on('close', function () {
364563+ core.info(`function source zipfile created: ${archive.pointer()} bytes`);
364564+ });
364565+ archive.pipe(output);
364566+ // Add dir to root of archive
364567+ archive.directory(dirPath, false);
364568+ // Finish writing files
364569+ archive.finalize();
364570+ });
364540364571 });
364541364572}
364542364573exports.zipDir = zipDir;
@@ -364585,6 +364616,7 @@ function uploadSource(uploadUrl, zipPath) {
364585364616 if (resp.status != 200) {
364586364617 throw new Error(`Failed to upload function source code: ${resp.statusText}`);
364587364618 }
364619+ core.info(`zip file ${zipPath} uploaded successfully`);
364588364620 return uploadUrl;
364589364621 });
364590364622}
0 commit comments