Skip to content

Commit 42ca54d

Browse files
authored
Add update_strategy for envvars and secrets (#523)
The default behavior remains to merge (--update), but setting the update_strategy to "overwrite" will set all values. Closes #522
1 parent 08b62e2 commit 42ca54d

File tree

9 files changed

+234
-174
lines changed

9 files changed

+234
-174
lines changed

.github/workflows/integration.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ permissions:
2121

2222
jobs:
2323
deploy:
24-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
2524
runs-on: 'ubuntu-latest'
2625

2726
strategy:
@@ -44,7 +43,7 @@ jobs:
4443
4544
- uses: 'actions/setup-node@v4'
4645
with:
47-
node-version: '20.x'
46+
node-version: '20.12.x' # https://github.com/nodejs/node/issues/53033
4847

4948
- run: 'npm ci && npm run build'
5049

@@ -111,7 +110,9 @@ jobs:
111110
env_vars: |-
112111
ABC=123
113112
DEF=456
113+
env_vars_update_strategy: 'overwrite'
114114
secrets: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest
115+
secrets_update_strategy: 'overwrite'
115116

116117
- name: 'Run re-deploy tests'
117118
run: 'npm run e2e-tests'
@@ -120,18 +121,11 @@ jobs:
120121
SERVICE: '${{ env.SERVICE_NAME }}'
121122
ENV: |-
122123
{
123-
"FOO": "bar",
124-
"ZIP": "zap,with|separators,and&stuff",
125-
"TEXT_FOO": "bar",
126-
"TEXT_ZIP": "zap,with|separators,and&stuff",
127124
"ABC": "123",
128125
"DEF": "456"
129126
}
130127
SECRET_ENV: |-
131-
{
132-
"MY_SECRET": "${{ vars.SECRET_NAME }}:latest",
133-
"MY_SECOND_SECRET": "${{ vars.SECRET_NAME }}:1"
134-
}
128+
{}
135129
SECRET_VOLUMES: |-
136130
{
137131
"/api/secrets/my-secret": "${{ vars.SECRET_NAME }}:latest"
@@ -151,7 +145,6 @@ jobs:
151145
REVISION_COUNT: 2
152146

153147
metadata:
154-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
155148
runs-on: 'ubuntu-latest'
156149

157150
steps:
@@ -167,7 +160,7 @@ jobs:
167160
168161
- uses: 'actions/setup-node@v4'
169162
with:
170-
node-version: '20.x'
163+
node-version: '20.12.x' # https://github.com/nodejs/node/issues/53033
171164

172165
- run: 'npm ci && npm run build'
173166

@@ -227,7 +220,6 @@ jobs:
227220
REVISION_COUNT: 2
228221

229222
jobs:
230-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
231223
runs-on: 'ubuntu-latest'
232224

233225
steps:
@@ -239,7 +231,7 @@ jobs:
239231
240232
- uses: 'actions/setup-node@v4'
241233
with:
242-
node-version: '20.x'
234+
node-version: '20.12.x' # https://github.com/nodejs/node/issues/53033
243235

244236
- run: 'npm ci && npm run build'
245237

@@ -299,6 +291,7 @@ jobs:
299291
env_vars: |-
300292
ABC=123
301293
DEF=456
294+
env_vars_update_strategy: 'overwrite'
302295
secrets: /api/secrets/my-secret=${{ vars.SECRET_NAME }}:latest
303296

304297
- name: 'Run re-deploy tests'
@@ -308,10 +301,6 @@ jobs:
308301
JOB: '${{ env.JOB_NAME }}'
309302
ENV: |-
310303
{
311-
"FOO": "bar",
312-
"ZIP": "zap,with|separators,and&stuff",
313-
"TEXT_FOO": "bar",
314-
"TEXT_ZIP": "zap,with|separators,and&stuff",
315304
"ABC": "123",
316305
"DEF": "456"
317306
}

README.md

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -92,61 +92,46 @@ jobs:
9292
specifying 'v1' for a service named 'helloworld', would lead to a revision
9393
named 'helloworld-v1'. The default value is no suffix.
9494

95-
- `env_vars`: (Optional) List of key=value pairs to set as environment
96-
variables. All existing environment variables will be retained. If both
97-
`env_vars` and `env_vars_file` are specified, the keys in `env_vars` will take
98-
precendence over the keys in `env_vars_files`.
95+
- `env_vars`, `env_vars_file`, and `env_vars_update_strategy`: (Optional)
96+
These values define environment variables and their update strategy.
9997

100-
```yaml
101-
with:
102-
env_vars: |
103-
FOO=bar
104-
ZIP=zap
105-
```
106-
107-
Entries are separated by commas (`,`) and newline characters. Keys and
108-
values are separated by `=`. To use `,`, `=`, or newline characters, escape
109-
them with a backslash:
98+
`env_vars` is specified as comma-separated or newline-separated key-value
99+
pairs, with special characters escaped using a backslash.
110100

111101
```yaml
112102
with:
113103
env_vars: |
104+
NAME=person
114105
EMAILS=foo@bar.com\,zip@zap.com
115106
```
116107

117-
- `env_vars_file`: (Optional) Path to a file on disk, relative to the
118-
workspace, that defines environment variables. The file can be
119-
newline-separated KEY=VALUE pairs, JSON, or YAML format. If both `env_vars`
120-
and `env_vars_file` are specified, the keys in env_vars will take
121-
precendence over the keys in env_vars_files.
108+
`env_vars_file` is the path to a file on disk relative to the workspace that
109+
defines newline-separated KEY=VALUE pairs, JSON, or YAML.
122110

123111
```text
124-
FOO=bar
125-
ZIP=zap
112+
NAME=person
113+
EMAILS=foo@bar.com\,zip@zap.com
126114
```
127115

128-
or
129-
130-
```json
131-
{
132-
"FOO": "bar",
133-
"ZIP": "zap"
134-
}
135-
```
116+
If both `env_vars` and `env_vars_file` are specified, they are merged and
117+
the values from `env_vars` will take precedence on conflict.
136118

137-
or
119+
`env_vars_update_strategy` controls how the environment variables are set on
120+
the Cloud Run service. If `env_vars_update_strategy` is set to "merge", then
121+
the environment variables are _merged_ with any upstream values. If set to
122+
"overwrite", then all environment variables on the Cloud Run service will be
123+
replaced with exactly the values given by the GitHub Action (making it
124+
authoritative). The default value is "merge".
138125

139126
```yaml
140-
FOO: 'bar'
141-
ZIP: 'zap'
127+
with:
128+
env_vars_update_strategy: 'overwrite'
142129
```
143130

144-
When specified as KEY=VALUE pairs, the same escaping rules apply as
145-
described in `env_vars`. You do not have to escape YAML or JSON.
146-
147-
- `secrets`: (Optional) List of key=value pairs to use as secrets. These can
148-
either be injected as environment variables or mounted as volumes. All
149-
existing environment secrets and volume mounts will be retained.
131+
- `secrets`, `secrets_update_strategy`: (Optional) List of key=value pairs to
132+
use as secrets. These can either be injected as environment variables or
133+
mounted as volumes. All existing environment secrets and volume mounts will
134+
be retained.
150135

151136
```yaml
152137
with:
@@ -161,6 +146,18 @@ jobs:
161146
The same rules apply for escaping entries as from `env_vars`, but Cloud Run
162147
is more restrictive with allowed keys and names for secrets.
163148

149+
`secrets_update_strategy` controls how the secrets are set on the Cloud Run
150+
service. If `secrets_update_strategy` is set to "merge", then the secrets
151+
are _merged_ with any upstream values. If set to "overwrite", then all
152+
secrets on the Cloud Run service will be replaced with exactly the values
153+
given by the GitHub Action (making it authoritative). The default value is
154+
"merge".
155+
156+
```yaml
157+
with:
158+
secrets_update_strategy: 'overwrite'
159+
```
160+
164161
- `labels`: (Optional) List of key=value pairs to set as labels on the Cloud
165162
Run service. Existing labels will be overwritten.
166163

action.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ inputs:
111111
described in `env_vars`. You do not have to escape YAML or JSON.
112112
required: false
113113

114+
env_vars_update_strategy:
115+
description: |-
116+
(Optional) Controls how the environment variables are set on the Cloud Run
117+
service. If set to "merge", then the environment variables are merged with
118+
any upstream values. If set to "overwrite", then all environment variables
119+
on the Cloud Run service will be replaced with exactly the values given by
120+
the GitHub Action (making it authoritative).
121+
required: true
122+
default: 'merge'
123+
114124
secrets:
115125
description: |-
116126
(Optional) List of key=value pairs to use as secrets. These can either be
@@ -129,6 +139,16 @@ inputs:
129139
Run is more restrictive with allowed keys and names for secrets.
130140
required: false
131141

142+
secrets_update_strategy:
143+
description: |-
144+
(Optional) Controls how the secrets are set on the Cloud Run service. If
145+
set to "merge", then the secrets are merged with any upstream values. If
146+
set to "overwrite", then all secrets on the Cloud Run service will be
147+
replaced with exactly the values given by the GitHub Action (making it
148+
authoritative).
149+
required: true
150+
default: 'merge'
151+
132152
labels:
133153
description: |-
134154
(Optional) List of key=value pairs to set as labels on the Cloud

dist/main/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)