Skip to content

Commit 7bbcdb4

Browse files
authored
Use separate flags for deploy and update-traffic commands (#539)
#537 (comment)
1 parent c422674 commit 7bbcdb4

File tree

4 files changed

+93
-11
lines changed

4 files changed

+93
-11
lines changed

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ jobs:
185185
- <a name="timeout"></a><a href="#user-content-timeout"><code>timeout</code></a>: _(Optional)_ Maximum request execution time, specified as a duration like "10m5s" for
186186
ten minutes and 5 seconds.
187187

188-
- <a name="flags"></a><a href="#user-content-flags"><code>flags</code></a>: _(Optional)_ Space separate list of other Cloud Run flags. This can be used to access
189-
features that are not exposed via this GitHub Action.
188+
- <a name="flags"></a><a href="#user-content-flags"><code>flags</code></a>: _(Optional)_ Space separate list of additional Cloud Run flags to pass to the deploy
189+
command. This can be used to apply advanced features that are not exposed
190+
via this GitHub Action. For Cloud Run services, this command will be
191+
`gcloud run deploy`. For Cloud Run jobs, this command will be `gcloud jobs
192+
deploy.
190193

191194
with:
192195
flags: '--add-cloudsql-instances=...'
@@ -203,9 +206,7 @@ jobs:
203206

204207
Please note, this GitHub Action does not parse or validate the flags. You
205208
are responsible for making sure the flags are available on the gcloud
206-
version and subcommand. The provided flags will be appended to the
207-
`deploy` command. When `revision_traffic` or `tag_traffic` are set, the
208-
flags will also be appended to the subsequent `update-traffic` command.
209+
version and subcommand.
209210

210211
- <a name="no_traffic"></a><a href="#user-content-no_traffic"><code>no_traffic</code></a>: _(Optional, default: `false`)_ If true, the newly deployed revision will not receive traffic. This option
211212
is only applies to services.
@@ -231,6 +232,28 @@ jobs:
231232
This is mutually-exclusive with `revision_traffic`. This option is only
232233
applies to services.
233234

235+
- <a name="update_traffic_flags"></a><a href="#user-content-update_traffic_flags"><code>update_traffic_flags</code></a>: _(Optional)_ Space separate list of additional Cloud Run flags to pass to the `gcloud
236+
run services update-traffic` command. This can be used to apply advanced
237+
features that are not exposed via this GitHub Action. This flag only
238+
applies with `revision_traffic` or `tag_traffic` is set.
239+
240+
with:
241+
traffic_flags: '--set-tags=...'
242+
243+
Flags that include other flags must quote the _entire_ outer flag value. For
244+
example, to pass `--args=-X=123`:
245+
246+
with:
247+
flags: '--set-tags=... "--args=-X=123"'
248+
249+
See the [complete list of
250+
flags](https://cloud.google.com/sdk/gcloud/reference/run/services/update#FLAGS)
251+
for more information.
252+
253+
Please note, this GitHub Action does not parse or validate the flags. You
254+
are responsible for making sure the flags are available on the gcloud
255+
version and subcommand.
256+
234257
- <a name="project_id"></a><a href="#user-content-project_id"><code>project_id</code></a>: _(Optional)_ ID of the Google Cloud project in which to deploy the service.
235258

236259
- <a name="region"></a><a href="#user-content-region"><code>region</code></a>: _(Optional, default: `us-central1`)_ Region in which the Cloud Run services are deployed.

action.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ inputs:
198198

199199
flags:
200200
description: |-
201-
Space separate list of other Cloud Run flags. This can be used to access
202-
features that are not exposed via this GitHub Action.
201+
Space separate list of additional Cloud Run flags to pass to the deploy
202+
command. This can be used to apply advanced features that are not exposed
203+
via this GitHub Action. For Cloud Run services, this command will be
204+
`gcloud run deploy`. For Cloud Run jobs, this command will be `gcloud jobs
205+
deploy.
203206
204207
with:
205208
flags: '--add-cloudsql-instances=...'
@@ -216,9 +219,7 @@ inputs:
216219
217220
Please note, this GitHub Action does not parse or validate the flags. You
218221
are responsible for making sure the flags are available on the gcloud
219-
version and subcommand. The provided flags will be appended to the
220-
`deploy` command. When `revision_traffic` or `tag_traffic` are set, the
221-
flags will also be appended to the subsequent `update-traffic` command.
222+
version and subcommand.
222223
required: false
223224

224225
no_traffic:
@@ -255,6 +256,31 @@ inputs:
255256
applies to services.
256257
required: false
257258

259+
update_traffic_flags:
260+
description: |-
261+
Space separate list of additional Cloud Run flags to pass to the `gcloud
262+
run services update-traffic` command. This can be used to apply advanced
263+
features that are not exposed via this GitHub Action. This flag only
264+
applies with `revision_traffic` or `tag_traffic` is set.
265+
266+
with:
267+
traffic_flags: '--set-tags=...'
268+
269+
Flags that include other flags must quote the _entire_ outer flag value. For
270+
example, to pass `--args=-X=123`:
271+
272+
with:
273+
flags: '--set-tags=... "--args=-X=123"'
274+
275+
See the [complete list of
276+
flags](https://cloud.google.com/sdk/gcloud/reference/run/services/update#FLAGS)
277+
for more information.
278+
279+
Please note, this GitHub Action does not parse or validate the flags. You
280+
are responsible for making sure the flags are available on the gcloud
281+
version and subcommand.
282+
required: false
283+
258284
project_id:
259285
description: |-
260286
ID of the Google Cloud project in which to deploy the service.

src/main.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export async function run(): Promise<void> {
118118
const labels = parseKVString(getInput('labels'));
119119
const skipDefaultLabels = parseBoolean(getInput('skip_default_labels'));
120120
const flags = getInput('flags');
121+
const updateTrafficFlags = getInput('update_traffic_flags');
121122

122123
let deployCmd: string[] = [];
123124

@@ -262,11 +263,18 @@ export async function run(): Promise<void> {
262263
updateTrafficCmd.push('--project', projectId);
263264
}
264265

265-
// Add optional flags
266+
// Add optional deploy flags
266267
if (flags) {
267268
const flagList = parseFlags(flags);
268269
if (flagList) {
269270
deployCmd = deployCmd.concat(flagList);
271+
}
272+
}
273+
274+
// Add optional update-traffic flags
275+
if (updateTrafficFlags) {
276+
const flagList = parseFlags(updateTrafficFlags);
277+
if (flagList) {
270278
updateTrafficCmd = updateTrafficCmd.concat(flagList);
271279
}
272280
}

tests/unit/main.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,18 @@ test('#run', { concurrency: true }, async (suite) => {
398398
assertMembers(args, ['--tag', 'test']);
399399
});
400400

401+
await suite.test('sets additional flags on the deploy command', async (t) => {
402+
const mocks = defaultMocks(t.mock, {
403+
service: 'my-test-service',
404+
flags: '--arg1=1 --arg2=2',
405+
});
406+
407+
await run();
408+
409+
const args = mocks.getExecOutput.mock.calls?.at(0)?.arguments?.at(1);
410+
assertMembers(args, ['--arg1', '1', '--arg2', '2']);
411+
});
412+
401413
await suite.test('sets tag traffic if given', async (t) => {
402414
const mocks = defaultMocks(t.mock, {
403415
service: 'my-test-service',
@@ -457,6 +469,19 @@ test('#run', { concurrency: true }, async (suite) => {
457469
assertMembers(updateTrafficArgs, ['--to-revisions', 'TEST=100']);
458470
});
459471

472+
await suite.test('sets additional flags on the update-traffic command', async (t) => {
473+
const mocks = defaultMocks(t.mock, {
474+
service: 'my-test-service',
475+
tag_traffic: 'test',
476+
update_traffic_flags: '--arg1=1 --arg2=2',
477+
});
478+
479+
await run();
480+
481+
const args = mocks.getExecOutput.mock.calls?.at(1)?.arguments?.at(1);
482+
assertMembers(args, ['--arg1', '1', '--arg2', '2']);
483+
});
484+
460485
await suite.test('fails if service is not provided with revision traffic', async (t) => {
461486
defaultMocks(t.mock, {
462487
service: '',

0 commit comments

Comments
 (0)