Skip to content

Commit ff5efa5

Browse files
authored
Allow skipping default labels (#430)
Fixes #429
1 parent 34547bf commit ff5efa5

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

.github/workflows/integration.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
labels: |-
6969
label1=value1
7070
label2=value2
71+
skip_default_labels: true
7172
flags: '--cpu=2 --concurrency=20'
7273

7374
- run: 'npm run e2e-tests'
@@ -77,7 +78,7 @@ jobs:
7778
ENV: 'FOO=bar,ZIP=zap,TEXT_FOO=bar,TEXT_ZIP=zap'
7879
SECRET_ENV: MY_SECRET=${{ secrets.SECRET_NAME }}:latest,MY_SECOND_SECRET=${{ secrets.SECRET_NAME }}:1
7980
PARAMS: '{"cpu":2, "containerConcurrency":20}'
80-
LABELS: '{"label1":"value1", "label2":"value2", "commit-sha":"${{ github.sha }}", "managed-by":"github-actions"}'
81+
LABELS: '{"label1":"value1", "label2":"value2"}'
8182

8283
- id: 'deploy-cloudrun-again'
8384
name: 'Deploy again'

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,22 @@ jobs:
141141
my-label=my-value
142142
```
143143

144-
The GitHub Action will automatically apply the following labels which Cloud
145-
Run uses to enhance the user experience:
144+
Labels have strict naming and casing requirements. See [Requirements for
145+
labels](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
146+
for more information.
147+
148+
- `skip_default_labels`: (Optional) Skip applying the special annotation
149+
labels that indicate the deployment came from GitHub Actions. The GitHub
150+
Action will automatically apply the following labels which Cloud Run uses to
151+
enhance the user experience:
146152

147153
```text
148154
managed-by: github-actions
149155
commit-sha: <sha>
150156
```
151157

152-
Labels have strict naming and casing requirements. See [Requirements for
153-
labels](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
154-
for more information.
158+
Setting this to `true` will skip adding these special labels. The default
159+
value is `false`.
155160

156161
- `tag`: (Optional) Traffic tag to assign to the newly-created revision.
157162

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ inputs:
6767
KEY1=VALUE1,KEY2=VALUE2. Existing labels will be retained.
6868
required: false
6969

70+
skip_default_labels:
71+
description: |-
72+
Skip applying the special annotation labels that indicate the deployment
73+
came from GitHub Actions.
74+
required: false
75+
default: false
76+
7077
metadata:
7178
description: |-
7279
YAML service description for the Cloud Run service.

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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
errorMessage,
3131
isPinnedToHead,
3232
KVPair,
33+
parseBoolean,
3334
parseFlags,
3435
parseKVString,
3536
parseKVStringAndFile,
@@ -104,6 +105,7 @@ export async function run(): Promise<void> {
104105
const revTraffic = getInput('revision_traffic');
105106
const tagTraffic = getInput('tag_traffic');
106107
const labels = parseKVString(getInput('labels'));
108+
const skipDefaultLabels = parseBoolean(getInput('skip_default_labels'));
107109
const flags = getInput('flags');
108110

109111
let responseType = ResponseTypes.DEPLOY; // Default response type for output parsing
@@ -201,8 +203,11 @@ export async function run(): Promise<void> {
201203
if (timeout) cmd.push('--timeout', timeout);
202204

203205
// Compile the labels
204-
const compiledLabels = Object.assign({}, defaultLabels(), labels);
205-
cmd.push('--update-labels', kvToString(compiledLabels));
206+
const defLabels = skipDefaultLabels ? {} : defaultLabels();
207+
const compiledLabels = Object.assign({}, defLabels, labels);
208+
if (compiledLabels && Object.keys(compiledLabels).length > 0) {
209+
cmd.push('--update-labels', kvToString(compiledLabels));
210+
}
206211
}
207212

208213
// Push common flags

tests/unit/main.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const fakeInputs: { [key: string]: string } = {
3535
env_vars: '',
3636
env_vars_file: '',
3737
labels: '',
38+
skip_default_labels: 'false',
3839
source: '',
3940
suffix: '',
4041
tag: '',
@@ -125,6 +126,22 @@ describe('#run', function () {
125126
expect(args).to.include.members(['--update-labels', kvToString(expectedLabels)]);
126127
});
127128

129+
it('skips default labels', async function () {
130+
this.stubs.getInput.withArgs('skip_default_labels').returns('true');
131+
this.stubs.getInput.withArgs('labels').returns('foo=bar,zip=zap');
132+
133+
const expectedLabels = {
134+
foo: 'bar',
135+
zip: 'zap',
136+
};
137+
138+
await run();
139+
const call = this.stubs.getExecOutput.getCall(0);
140+
expect(call).to.be;
141+
const args = call.args[1];
142+
expect(args).to.include.members(['--update-labels', kvToString(expectedLabels)]);
143+
});
144+
128145
it('overwrites default labels', async function () {
129146
this.stubs.getInput.withArgs('labels').returns('commit-sha=custom-value');
130147

0 commit comments

Comments
 (0)