Skip to content

Commit fcc32e6

Browse files
Add CloudRun labels options (#350)
* add labels options * add description Co-authored-by: Averi Kitsch <[email protected]>
1 parent 530b4b6 commit fcc32e6

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
| `no_traffic` | _optional_ | `false` | Set to `true` to avoid sending traffic to the revision being deployed.|
7878
| `revision_traffic` | _optional_ | | Comma separated list of traffic assignments in the form REVISION-NAME=PERCENTAGE. |
7979
| `tag_traffic` | _optional_ | | Comma separated list of traffic assignments in the form TAG=PERCENTAGE. |
80+
| `labels` | _optional_ | | List of key-value pairs to set as labels of cloud run service in the format: KEY1=VALUE1,KEY2=VALUE2. Existing labels will be retained. |
8081
| `flags` | _optional_ | | Space separated list of other Cloud Run flags, examples can be found: https://cloud.google.com/sdk/gcloud/reference/run/deploy#FLAGS. |
8182
| `gcloud_version` | _optional_ | `latest` | Pin the version of Cloud SDK `gcloud` CLI. |
8283
| `gcloud_component` | _optional_ | | Pin the Cloud SDK `gcloud` CLI components version, valid values are `alpha` or `beta`. |

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ inputs:
5050
secrets will be retained.
5151
required: false
5252

53+
labels:
54+
description: |-
55+
List of key-value pairs to set as labels of cloud run service in the format:
56+
KEY1=VALUE1,KEY2=VALUE2. Existing labels will be retained.
57+
required: false
58+
5359
metadata:
5460
description: |-
5561
YAML service description for the Cloud Run service.

src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export async function run(): Promise<void> {
7272
const noTraffic = core.getBooleanInput('no_traffic');
7373
const revTraffic = core.getInput('revision_traffic');
7474
const tagTraffic = core.getInput('tag_traffic');
75+
const labels = parseKVString(core.getInput('labels'));
7576
const flags = core.getInput('flags');
7677

7778
// Add warning if using credentials
@@ -136,9 +137,9 @@ export async function run(): Promise<void> {
136137
if (timeout) cmd.push('--timeout', timeout);
137138
} else if (metadata) {
138139
// Deploy service from metadata
139-
if (image || name || envVars || secrets || timeout) {
140+
if (image || name || envVars || secrets || timeout || labels) {
140141
core.warning(
141-
`Metadata YAML provided, ignoring: "image", "service", "env_vars", "secrets", and "timeout" inputs.`,
142+
`Metadata YAML provided, ignoring: "image", "service", "env_vars", "secrets", "labels", and "timeout" inputs.`,
142143
);
143144
}
144145
cmd = ['run', 'services', 'replace', metadata, '--platform', 'managed', '--region', region];
@@ -173,6 +174,9 @@ export async function run(): Promise<void> {
173174
}
174175
if (suffix) cmd.push('--revision-suffix', suffix);
175176
if (noTraffic) cmd.push('--no-traffic');
177+
if (labels && Object.keys(labels).length > 0) {
178+
cmd.push('--update-labels', kvToString(labels));
179+
}
176180
}
177181
if (timeout) cmd.push('--timeout', timeout);
178182
// Add optional flags

0 commit comments

Comments
 (0)