@@ -364077,6 +364077,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
364077
364077
Object.defineProperty(exports, "__esModule", ({ value: true }));
364078
364078
exports.CloudFunctionClient = void 0;
364079
364079
const core = __importStar(__webpack_require__(42186));
364080
+ const path = __importStar(__webpack_require__(85622));
364081
+ const os = __importStar(__webpack_require__(12087));
364080
364082
const util_1 = __webpack_require__(92629);
364081
364083
const googleapis_1 = __webpack_require__(44913);
364082
364084
/**
@@ -364220,13 +364222,24 @@ class CloudFunctionClient {
364220
364222
return __awaiter(this, void 0, void 0, function* () {
364221
364223
const authClient = yield this.getAuthClient();
364222
364224
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
+ }
364224
364232
const uploadUrl = yield this.getUploadUrl();
364225
364233
if (!uploadUrl.uploadUrl) {
364226
364234
throw new Error('Unable to generate signed Url');
364227
364235
}
364228
364236
// 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
+ }
364230
364243
// Delete temp zip file after upload
364231
364244
yield util_1.deleteZipFile(zipPath);
364232
364245
cf.setSourceUrl(uploadUrl.uploadUrl);
@@ -364256,7 +364269,7 @@ class CloudFunctionClient {
364256
364269
requestBody: cf.request,
364257
364270
};
364258
364271
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 );
364260
364273
core.info('Function deployment updated');
364261
364274
return awaitUpdate;
364262
364275
}
@@ -364268,7 +364281,7 @@ class CloudFunctionClient {
364268
364281
requestBody: cf.request,
364269
364282
};
364270
364283
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 );
364272
364285
core.info('Function deployment created');
364273
364286
return awaitCreate;
364274
364287
}
@@ -364512,6 +364525,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
364512
364525
Object.defineProperty(exports, "__esModule", ({ value: true }));
364513
364526
exports.uploadSource = exports.deleteZipFile = exports.zipDir = void 0;
364514
364527
const fs = __importStar(__webpack_require__(35747));
364528
+ const core = __importStar(__webpack_require__(42186));
364515
364529
const gaxios_1 = __webpack_require__(59555);
364516
364530
const Archiver = __importStar(__webpack_require__(43084));
364517
364531
/**
@@ -364520,23 +364534,40 @@ const Archiver = __importStar(__webpack_require__(43084));
364520
364534
* @param dirPath Directory to zip.
364521
364535
* @returns filepath of the created zip file.
364522
364536
*/
364523
- function zipDir(dirPath) {
364537
+ function zipDir(dirPath, outputPath ) {
364524
364538
return __awaiter(this, void 0, void 0, function* () {
364525
364539
// Check dirpath
364526
364540
if (!fs.existsSync(dirPath)) {
364527
364541
throw new Error(`Unable to find ${dirPath}`);
364528
364542
}
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
+ });
364540
364571
});
364541
364572
}
364542
364573
exports.zipDir = zipDir;
@@ -364585,6 +364616,7 @@ function uploadSource(uploadUrl, zipPath) {
364585
364616
if (resp.status != 200) {
364586
364617
throw new Error(`Failed to upload function source code: ${resp.statusText}`);
364587
364618
}
364619
+ core.info(`zip file ${zipPath} uploaded successfully`);
364588
364620
return uploadUrl;
364589
364621
});
364590
364622
}
0 commit comments