@@ -30009,7 +30009,7 @@ class CloudRun {
3000930009 !process.env.GOOGLE_APPLICATION_CREDENTIALS)) {
3001030010 throw new Error('No method for authentication. Set credentials in this action or export credentials from the setup-gcloud action');
3001130011 }
30012- // Instatiate Auth Client
30012+ // Instantiate Auth Client
3001330013 // This method looks for the GCLOUD_PROJECT and GOOGLE_APPLICATION_CREDENTIALS
3001430014 // environment variables.
3001530015 this.auth = new googleapis_1.google.auth.GoogleAuth({
@@ -30171,6 +30171,28 @@ class CloudRun {
3017130171 }
3017230172 });
3017330173 }
30174+ /** Get revisions */
30175+ listRevisions() {
30176+ return __awaiter(this, void 0, void 0, function* () {
30177+ const authClient = yield this.getAuthClient();
30178+ const listRequest = {
30179+ parent: this.parent,
30180+ auth: authClient,
30181+ };
30182+ const revisionListResponse = yield this.run.namespaces.revisions.list(listRequest, this.methodOptions);
30183+ const revisionList = revisionListResponse.data;
30184+ let revisionNames = [];
30185+ if (revisionList.items) {
30186+ revisionNames = revisionList.items.map((revision) => {
30187+ if (revision.metadata) {
30188+ return revision.metadata.name;
30189+ }
30190+ return '';
30191+ });
30192+ }
30193+ return revisionNames;
30194+ });
30195+ }
3017430196 /**
3017530197 * Set's IAM policy for service (Not Recommended).
3017630198 *
@@ -105836,19 +105858,23 @@ class Service {
105836105858 */
105837105859 merge(prevService) {
105838105860 var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
105839- // Merge Revision Metadata
105861+ // Get Revision names if set
105862+ const name = lodash_1.get(this.request, 'spec.template.metadata.name');
105863+ const previousName = lodash_1.get(prevService, 'spec.template.metadata.name');
105864+ // Merge Revision metadata
105840105865 const labels = Object.assign(Object.assign({}, (_c = (_b = (_a = prevService.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.labels), (_f = (_e = (_d = this.request.spec) === null || _d === void 0 ? void 0 : _d.template) === null || _e === void 0 ? void 0 : _e.metadata) === null || _f === void 0 ? void 0 : _f.labels);
105841105866 const annotations = Object.assign(Object.assign({}, (_j = (_h = (_g = prevService.spec) === null || _g === void 0 ? void 0 : _g.template) === null || _h === void 0 ? void 0 : _h.metadata) === null || _j === void 0 ? void 0 : _j.annotations), (_m = (_l = (_k = this.request.spec) === null || _k === void 0 ? void 0 : _k.template) === null || _l === void 0 ? void 0 : _l.metadata) === null || _m === void 0 ? void 0 : _m.annotations);
105842105867 this.request.spec.template.metadata = {
105843105868 annotations,
105844105869 labels,
105845105870 };
105846- // Merge Revision Spec
105871+ // Force update with Revision name change
105872+ this.request.spec.template.metadata.name = this.generateRevisionName(name, previousName);
105873+ // Merge Container spec
105847105874 const prevContainer = prevService.spec.template.spec.containers[0];
105848105875 const currentContainer = this.request.spec.template.spec.containers[0];
105849- // Merge Container spec
105850105876 const container = Object.assign(Object.assign({}, prevContainer), currentContainer);
105851- // Merge Spec
105877+ // Merge Revision spec
105852105878 const spec = Object.assign(Object.assign({}, (_p = (_o = prevService.spec) === null || _o === void 0 ? void 0 : _o.template) === null || _p === void 0 ? void 0 : _p.spec), this.request.spec.template.spec);
105853105879 if (!currentContainer.command) {
105854105880 // Remove entrypoint cmd and arguments if not specified
@@ -105870,6 +105896,34 @@ class Service {
105870105896 spec.containers = [container];
105871105897 this.request.spec.template.spec = spec;
105872105898 }
105899+ generateRevisionName(name, prevName) {
105900+ const message = 'Resource name must use only lowercase letters, numbers and ' +
105901+ '. Must begin with a letter and cannot end with a ' +
105902+ '. Maximum length is 63 characters.';
105903+ if (name && name.length > 63)
105904+ throw new Error(message);
105905+ if (!name) {
105906+ // Increment suffix number if set
105907+ let num;
105908+ if (prevName) {
105909+ const suffix = prevName.split('-');
105910+ num = (parseInt(suffix[suffix.length - 2]) + 1).toString();
105911+ }
105912+ else {
105913+ num = '1';
105914+ }
105915+ // Generate 3 random letters
105916+ const letters = Math.random()
105917+ .toString(36)
105918+ .replace(/[^a-z]+/g, '')
105919+ .substring(0, 3);
105920+ // Set revision suffix "-XXXXX-abc"
105921+ const newSuffix = `-${num.padStart(4, '0')}-${letters}`;
105922+ const serviceName = this.name.substring(0, 53);
105923+ name = serviceName + newSuffix;
105924+ }
105925+ return name;
105926+ }
105873105927}
105874105928exports.Service = Service;
105875105929
@@ -107510,7 +107564,6 @@ function run() {
107510107564 core.setOutput('url', lodash_1.get(serviceResponse, 'status.url'));
107511107565 }
107512107566 catch (error) {
107513- core.error(error);
107514107567 core.setFailed(error.message);
107515107568 }
107516107569 });
0 commit comments