Skip to content

Commit

Permalink
Use separate flags for deploy and update-traffic commands (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Aug 21, 2024
1 parent c422674 commit 7bbcdb4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 11 deletions.
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ jobs:
- <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
ten minutes and 5 seconds.

- <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
features that are not exposed via this GitHub Action.
- <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
command. This can be used to apply advanced features that are not exposed
via this GitHub Action. For Cloud Run services, this command will be
`gcloud run deploy`. For Cloud Run jobs, this command will be `gcloud jobs
deploy.

with:
flags: '--add-cloudsql-instances=...'
Expand All @@ -203,9 +206,7 @@ jobs:

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

- <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
is only applies to services.
Expand All @@ -231,6 +232,28 @@ jobs:
This is mutually-exclusive with `revision_traffic`. This option is only
applies to services.

- <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
run services update-traffic` command. This can be used to apply advanced
features that are not exposed via this GitHub Action. This flag only
applies with `revision_traffic` or `tag_traffic` is set.

with:
traffic_flags: '--set-tags=...'

Flags that include other flags must quote the _entire_ outer flag value. For
example, to pass `--args=-X=123`:

with:
flags: '--set-tags=... "--args=-X=123"'

See the [complete list of
flags](https://cloud.google.com/sdk/gcloud/reference/run/services/update#FLAGS)
for more information.

Please note, this GitHub Action does not parse or validate the flags. You
are responsible for making sure the flags are available on the gcloud
version and subcommand.

- <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.

- <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.
Expand Down
36 changes: 31 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,11 @@ inputs:

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

no_traffic:
Expand Down Expand Up @@ -255,6 +256,31 @@ inputs:
applies to services.
required: false

update_traffic_flags:
description: |-
Space separate list of additional Cloud Run flags to pass to the `gcloud
run services update-traffic` command. This can be used to apply advanced
features that are not exposed via this GitHub Action. This flag only
applies with `revision_traffic` or `tag_traffic` is set.
with:
traffic_flags: '--set-tags=...'
Flags that include other flags must quote the _entire_ outer flag value. For
example, to pass `--args=-X=123`:
with:
flags: '--set-tags=... "--args=-X=123"'
See the [complete list of
flags](https://cloud.google.com/sdk/gcloud/reference/run/services/update#FLAGS)
for more information.
Please note, this GitHub Action does not parse or validate the flags. You
are responsible for making sure the flags are available on the gcloud
version and subcommand.
required: false

project_id:
description: |-
ID of the Google Cloud project in which to deploy the service.
Expand Down
10 changes: 9 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function run(): Promise<void> {
const labels = parseKVString(getInput('labels'));
const skipDefaultLabels = parseBoolean(getInput('skip_default_labels'));
const flags = getInput('flags');
const updateTrafficFlags = getInput('update_traffic_flags');

let deployCmd: string[] = [];

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

// Add optional flags
// Add optional deploy flags
if (flags) {
const flagList = parseFlags(flags);
if (flagList) {
deployCmd = deployCmd.concat(flagList);
}
}

// Add optional update-traffic flags
if (updateTrafficFlags) {
const flagList = parseFlags(updateTrafficFlags);
if (flagList) {
updateTrafficCmd = updateTrafficCmd.concat(flagList);
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,18 @@ test('#run', { concurrency: true }, async (suite) => {
assertMembers(args, ['--tag', 'test']);
});

await suite.test('sets additional flags on the deploy command', async (t) => {
const mocks = defaultMocks(t.mock, {
service: 'my-test-service',
flags: '--arg1=1 --arg2=2',
});

await run();

const args = mocks.getExecOutput.mock.calls?.at(0)?.arguments?.at(1);
assertMembers(args, ['--arg1', '1', '--arg2', '2']);
});

await suite.test('sets tag traffic if given', async (t) => {
const mocks = defaultMocks(t.mock, {
service: 'my-test-service',
Expand Down Expand Up @@ -457,6 +469,19 @@ test('#run', { concurrency: true }, async (suite) => {
assertMembers(updateTrafficArgs, ['--to-revisions', 'TEST=100']);
});

await suite.test('sets additional flags on the update-traffic command', async (t) => {
const mocks = defaultMocks(t.mock, {
service: 'my-test-service',
tag_traffic: 'test',
update_traffic_flags: '--arg1=1 --arg2=2',
});

await run();

const args = mocks.getExecOutput.mock.calls?.at(1)?.arguments?.at(1);
assertMembers(args, ['--arg1', '1', '--arg2', '2']);
});

await suite.test('fails if service is not provided with revision traffic', async (t) => {
defaultMocks(t.mock, {
service: '',
Expand Down

0 comments on commit 7bbcdb4

Please sign in to comment.