Skip to content

Commit 098dfb3

Browse files
sethvargogaluszkak
andauthored
feat: add support for --wait flag in jobs (#571)
Closes #570 (opening the PR as myself to allow CI to run) Thanks @galuszkak --------- Co-authored-by: Kamil Gałuszka <[email protected]>
1 parent 5819800 commit 098dfb3

File tree

8 files changed

+53
-13
lines changed

8 files changed

+53
-13
lines changed

.github/workflows/integration.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ defaults:
2626
jobs:
2727
deploy:
2828
runs-on: 'ubuntu-latest'
29+
timeout-minutes: 7
2930

3031
strategy:
3132
fail-fast: false
3233
matrix:
3334
include:
3435
- name: 'image'
35-
image: 'gcr.io/cloudrun/hello'
36+
image: 'us-docker.pkg.dev/cloudrun/container/hello:latest'
3637
- name: 'source'
3738
source: 'example-app'
3839

@@ -153,6 +154,7 @@ jobs:
153154

154155
metadata:
155156
runs-on: 'ubuntu-latest'
157+
timeout-minutes: 7
156158

157159
steps:
158160
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
@@ -206,7 +208,7 @@ jobs:
206208
name: 'Deploy again'
207209
uses: './'
208210
with:
209-
image: 'gcr.io/cloudrun/hello'
211+
image: 'us-docker.pkg.dev/cloudrun/container/hello:latest'
210212
service: '${{ env.SERVICE_NAME }}'
211213
revision_traffic: 'LATEST=100'
212214

@@ -229,6 +231,7 @@ jobs:
229231

230232
jobs:
231233
runs-on: 'ubuntu-latest'
234+
timeout-minutes: 7
232235

233236
steps:
234237
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4
@@ -252,7 +255,7 @@ jobs:
252255
name: 'Deploy'
253256
uses: './'
254257
with:
255-
image: 'gcr.io/cloudrun/hello'
258+
image: 'us-docker.pkg.dev/cloudrun/container/job:latest'
256259
job: '${{ env.JOB_NAME }}'
257260
env_vars: |-
258261
FOO=bar
@@ -294,7 +297,7 @@ jobs:
294297
name: 'Deploy again'
295298
uses: './'
296299
with:
297-
image: 'gcr.io/cloudrun/hello'
300+
image: 'us-docker.pkg.dev/cloudrun/container/job:latest'
298301
job: '${{ env.JOB_NAME }}'
299302
env_vars: |-
300303
ABC=123

.github/workflows/unit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- 'windows-latest'
3434
- 'macos-latest'
3535
runs-on: '${{ matrix.os }}'
36+
timeout-minutes: 7
3637

3738
steps:
3839
- uses: 'actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683' # ratchet:actions/checkout@v4

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
uses: 'google-github-actions/deploy-cloudrun@v2'
4646
with:
4747
service: 'hello-cloud-run'
48-
image: 'gcr.io/cloudrun/hello'
48+
image: 'us-docker.pkg.dev/cloudrun/container/hello:latest'
4949

5050
- name: 'Use output'
5151
run: 'curl "${{ steps.deploy.outputs.url }}"'
@@ -67,7 +67,7 @@ jobs:
6767
- <a name="image"></a><a href="#user-content-image"><code>image</code></a>: _(Optional)_ (Required, unless providing `metadata` or `source`) Fully-qualified name
6868
of the container image to deploy. For example:
6969

70-
gcr.io/cloudrun/hello:latest
70+
us-docker.pkg.dev/cloudrun/container/hello:latest
7171

7272
or
7373

@@ -362,7 +362,7 @@ jobs:
362362
363363
- uses: 'google-github-actions/deploy-cloudrun@v2'
364364
with:
365-
image: 'gcr.io/cloudrun/hello'
365+
image: 'us-docker.pkg.dev/cloudrun/container/hello:latest'
366366
service: 'hello-cloud-run'
367367
```
368368

@@ -381,7 +381,7 @@ jobs:
381381
382382
- uses: 'google-github-actions/deploy-cloudrun@v2'
383383
with:
384-
image: 'gcr.io/cloudrun/hello'
384+
image: 'us-docker.pkg.dev/cloudrun/container/hello:latest'
385385
service: 'hello-cloud-run'
386386
```
387387

action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inputs:
4141
(Required, unless providing `metadata` or `source`) Fully-qualified name
4242
of the container image to deploy. For example:
4343
44-
gcr.io/cloudrun/hello:latest
44+
us-docker.pkg.dev/cloudrun/container/hello:latest
4545
4646
or
4747
@@ -229,6 +229,13 @@ inputs:
229229
default: 'false'
230230
required: false
231231

232+
wait:
233+
description: |-
234+
If true, the action will wait for the job to complete before exiting. This
235+
option only applies to jobs.
236+
default: 'true'
237+
required: false
238+
232239
revision_traffic:
233240
description: |-
234241
Comma-separated list of revision traffic assignments.

src/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function run(): Promise<void> {
9595

9696
try {
9797
// Get action inputs
98-
const image = getInput('image'); // Image ie gcr.io/...
98+
const image = getInput('image'); // Image ie us-docker.pkg.dev/...
9999
let service = getInput('service'); // Service name
100100
const job = getInput('job'); // Job name
101101
const metadata = getInput('metadata'); // YAML file
@@ -113,6 +113,7 @@ export async function run(): Promise<void> {
113113
const tag = getInput('tag');
114114
const timeout = getInput('timeout');
115115
const noTraffic = (getInput('no_traffic') || '').toLowerCase() === 'true';
116+
const wait = parseBoolean(getInput('wait'));
116117
const revTraffic = getInput('revision_traffic');
117118
const tagTraffic = getInput('tag_traffic');
118119
const labels = parseKVString(getInput('labels'));
@@ -196,6 +197,10 @@ export async function run(): Promise<void> {
196197
setEnvVarsFlags(deployCmd, envVars, envVarsFile, envVarsUpdateStrategy);
197198
setSecretsFlags(deployCmd, secrets, secretsUpdateStrategy);
198199

200+
if (wait) {
201+
deployCmd.push('--wait');
202+
}
203+
199204
// There is no --update-secrets flag on jobs, but there will be in the
200205
// future. At that point, we can remove this.
201206
const idx = deployCmd.indexOf('--update-secrets');

tests/fixtures/job.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
template:
1616
spec:
1717
containers:
18-
- image: 'gcr.io/cloudrun/hello'
18+
- image: 'us-docker.pkg.dev/cloudrun/container/job:latest'
1919
imagePullPolicy: 'Always'
2020
resources:
2121
limits:

tests/fixtures/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ spec:
1212
spec:
1313
containerConcurrency: 20
1414
containers:
15-
- image: 'gcr.io/cloudrun/hello'
15+
- image: 'us-docker.pkg.dev/cloudrun/container/hello:latest'
1616
ports:
1717
- containerPort: 8080
1818
resources:

tests/unit/main.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { assertMembers } from '@google-github-actions/actions-utils';
2727
import { run } from '../../src/main';
2828

2929
const fakeInputs: { [key: string]: string } = {
30-
image: 'gcr.io/cloudrun/hello',
30+
image: 'us-docker.pkg.dev/cloudrun/container/hello:latest',
3131
project_id: 'test',
3232
};
3333

@@ -520,6 +520,30 @@ test('#run', { concurrency: true }, async (suite) => {
520520
const args = mocks.getExecOutput.mock.calls?.at(0)?.arguments?.at(1);
521521
assertMembers(args, ['run', 'jobs', 'deploy', 'my-test-job']);
522522
});
523+
524+
await suite.test('deploys a job with --wait', async (t) => {
525+
const mocks = defaultMocks(t.mock, {
526+
job: 'my-test-job',
527+
wait: 'true',
528+
});
529+
530+
await run();
531+
532+
const args = mocks.getExecOutput.mock.calls?.at(0)?.arguments?.at(1);
533+
assert.ok(args?.includes('--wait'));
534+
});
535+
536+
await suite.test('deploys a job without --wait', async (t) => {
537+
const mocks = defaultMocks(t.mock, {
538+
job: 'my-test-job',
539+
wait: 'false',
540+
});
541+
542+
await run();
543+
544+
const args = mocks.getExecOutput.mock.calls?.at(0)?.arguments?.at(1);
545+
assert.ok(!args.includes('--wait'));
546+
});
523547
});
524548

525549
const splitKV = (s: string): Record<string, string> => {

0 commit comments

Comments
 (0)