@@ -30009,7 +30009,7 @@ class CloudRun {
30009
30009
!process.env.GOOGLE_APPLICATION_CREDENTIALS)) {
30010
30010
throw new Error('No method for authentication. Set credentials in this action or export credentials from the setup-gcloud action');
30011
30011
}
30012
- // Instatiate Auth Client
30012
+ // Instantiate Auth Client
30013
30013
// This method looks for the GCLOUD_PROJECT and GOOGLE_APPLICATION_CREDENTIALS
30014
30014
// environment variables.
30015
30015
this.auth = new googleapis_1.google.auth.GoogleAuth({
@@ -30171,6 +30171,28 @@ class CloudRun {
30171
30171
}
30172
30172
});
30173
30173
}
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
+ }
30174
30196
/**
30175
30197
* Set's IAM policy for service (Not Recommended).
30176
30198
*
@@ -105836,19 +105858,23 @@ class Service {
105836
105858
*/
105837
105859
merge(prevService) {
105838
105860
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
105840
105865
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);
105841
105866
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);
105842
105867
this.request.spec.template.metadata = {
105843
105868
annotations,
105844
105869
labels,
105845
105870
};
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
105847
105874
const prevContainer = prevService.spec.template.spec.containers[0];
105848
105875
const currentContainer = this.request.spec.template.spec.containers[0];
105849
- // Merge Container spec
105850
105876
const container = Object.assign(Object.assign({}, prevContainer), currentContainer);
105851
- // Merge Spec
105877
+ // Merge Revision spec
105852
105878
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);
105853
105879
if (!currentContainer.command) {
105854
105880
// Remove entrypoint cmd and arguments if not specified
@@ -105870,6 +105896,34 @@ class Service {
105870
105896
spec.containers = [container];
105871
105897
this.request.spec.template.spec = spec;
105872
105898
}
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
+ }
105873
105927
}
105874
105928
exports.Service = Service;
105875
105929
@@ -107510,7 +107564,6 @@ function run() {
107510
107564
core.setOutput('url', lodash_1.get(serviceResponse, 'status.url'));
107511
107565
}
107512
107566
catch (error) {
107513
- core.error(error);
107514
107567
core.setFailed(error.message);
107515
107568
}
107516
107569
});
0 commit comments