Skip to content

Commit f6e4cdb

Browse files
authored
Emit a separate warning message for each invalid key (#410)
This emits a separate warning message for each invalid key, making it easier to track down which entry was invalid. This also updates the label logic to only set default labels when labels are actually going to be used. Fixes GH-386
1 parent 4590496 commit f6e4cdb

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

dist/main/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function run(): Promise<void> {
9696
const noTraffic = (getInput('no_traffic') || '').toLowerCase() === 'true';
9797
const revTraffic = getInput('revision_traffic');
9898
const tagTraffic = getInput('tag_traffic');
99-
const labels = Object.assign({}, defaultLabels(), parseKVString(getInput('labels')));
99+
const labels = parseKVString(getInput('labels'));
100100
const flags = getInput('flags');
101101

102102
let responseType = ResponseTypes.DEPLOY; // Default response type for output parsing
@@ -124,34 +124,51 @@ export async function run(): Promise<void> {
124124
responseType = ResponseTypes.UPDATE_TRAFFIC;
125125

126126
// Update traffic
127-
cmd = [
128-
'run',
129-
'services',
130-
'update-traffic',
131-
service,
132-
'--platform',
133-
'managed',
134-
'--region',
135-
region,
136-
];
127+
cmd = ['run', 'services', 'update-traffic', service];
137128
if (revTraffic) cmd.push('--to-revisions', revTraffic);
138129
if (tagTraffic) cmd.push('--to-tags', tagTraffic);
139130

140-
if (image || envVars?.length || secrets?.length || timeout || labels?.length) {
141-
logWarning(
142-
`Updating traffic, ignoring inputs "image", "env_vars", "secrets", "timeout", and "labels"`,
143-
);
131+
const providedButIgnored: Record<string, boolean> = {
132+
image: image !== '',
133+
metadata: metadata !== '',
134+
source: source !== '',
135+
env_vars: Object.keys(envVars).length > 0,
136+
no_traffic: noTraffic,
137+
secrets: Object.keys(secrets).length > 0,
138+
suffix: suffix !== '',
139+
tag: tag !== '',
140+
labels: Object.keys(labels).length > 0,
141+
timeout: timeout !== '',
142+
};
143+
for (const key in providedButIgnored) {
144+
if (providedButIgnored[key]) {
145+
logWarning(`Updating traffic, ignoring "${key}" input`);
146+
}
144147
}
145148
} else if (metadata) {
146-
cmd = ['run', 'services', 'replace', metadata, '--platform', 'managed', '--region', region];
147-
148-
if (image || service || envVars?.length || secrets?.length || timeout || labels?.length) {
149-
logWarning(
150-
`Using metadata YAML, ignoring inputs "image", "name", "env_vars", "secrets", "timeout", and "labels"`,
151-
);
149+
cmd = ['run', 'services', 'replace', metadata];
150+
151+
const providedButIgnored: Record<string, boolean> = {
152+
image: image !== '',
153+
service: service !== '',
154+
source: source !== '',
155+
env_vars: Object.keys(envVars).length > 0,
156+
no_traffic: noTraffic,
157+
secrets: Object.keys(secrets).length > 0,
158+
suffix: suffix !== '',
159+
tag: tag !== '',
160+
revision_traffic: revTraffic !== '',
161+
tag_traffic: revTraffic !== '',
162+
labels: Object.keys(labels).length > 0,
163+
timeout: timeout !== '',
164+
};
165+
for (const key in providedButIgnored) {
166+
if (providedButIgnored[key]) {
167+
logWarning(`Using metadata YAML, ignoring "${key}" input`);
168+
}
152169
}
153170
} else {
154-
cmd = ['run', 'deploy', service, '--quiet', '--platform', 'managed', '--region', region];
171+
cmd = ['run', 'deploy', service, '--quiet'];
155172

156173
if (image) {
157174
// Deploy service with image specified
@@ -173,12 +190,19 @@ export async function run(): Promise<void> {
173190
}
174191
if (suffix) cmd.push('--revision-suffix', suffix);
175192
if (noTraffic) cmd.push('--no-traffic');
176-
if (labels && Object.keys(labels).length > 0) {
177-
cmd.push('--update-labels', kvToString(labels));
178-
}
179193
if (timeout) cmd.push('--timeout', timeout);
194+
195+
// Compile the labels
196+
const compiledLabels = Object.assign({}, defaultLabels(), labels);
197+
cmd.push('--update-labels', kvToString(compiledLabels));
180198
}
181199

200+
// Push common flags
201+
cmd.push('--platform', 'managed');
202+
cmd.push('--format', 'json');
203+
if (region) cmd.push('--region', region);
204+
if (projectId) cmd.push('--project', projectId);
205+
182206
// Add optional flags
183207
if (flags) {
184208
const flagList = parseFlags(flags);
@@ -193,6 +217,12 @@ export async function run(): Promise<void> {
193217
addPath(path.join(toolPath, 'bin'));
194218
}
195219

220+
// Install gcloud component if needed and prepend the command
221+
if (gcloudComponent) {
222+
await installGcloudComponent(gcloudComponent);
223+
cmd.unshift(gcloudComponent);
224+
}
225+
196226
// Authenticate - this comes from google-github-actions/auth.
197227
const credFile = process.env.GOOGLE_GHA_CREDS_PATH;
198228
if (credFile) {
@@ -202,18 +232,6 @@ export async function run(): Promise<void> {
202232
logWarning('No authentication found, authenticate with `google-github-actions/auth`.');
203233
}
204234

205-
// set PROJECT ID
206-
if (projectId) cmd.push('--project', projectId);
207-
208-
// Install gcloud component if needed and prepend the command
209-
if (gcloudComponent) {
210-
await installGcloudComponent(gcloudComponent);
211-
cmd.unshift(gcloudComponent);
212-
}
213-
214-
// Set output format to json
215-
cmd.push('--format', 'json');
216-
217235
const toolCommand = getToolCommand();
218236
const options = { silent: true, ignoreReturnCode: true };
219237
const commandString = `${toolCommand} ${cmd.join(' ')}`;

0 commit comments

Comments
 (0)