Skip to content

Commit 30692e4

Browse files
authored
feat: add timeout option for setting execution timeouts (#291)
1 parent 4e33c27 commit 30692e4

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
| `source` | _optional_ | | Deploy from source by specifying the source directory. The [Artifact Registry API][artifact-api] needs to be enabled and the service account role `Cloud Build Service Account` is required. The first deployment will create an [Artifact Registry repository][repo] which requires the `Artifact Registry Admin` role. Learn more about [Deploying from source code](https://cloud.google.com/run/docs/deploying-source-code). |
8484
| `suffix` | _optional_ | | Specify the suffix of the revision name. Revision names always start with named 'helloworld', would lead to a revision named 'helloworld-v1'. |
8585
| `tag` | _optional_ | | Traffic tag to assign to the newly created revision. |
86+
| `timeout` | _optional_ | | Set the maximum request execution time. It is specified as a duration; for example, "10m5s" is ten minutes and five seconds. If you don't specify a unit, seconds is assumed. |
8687
| `no_traffic` | _optional_ | `false` | Set to `true` to avoid sending traffic to the revision being deployed.|
8788
| `revision_traffic` | _optional_ | | Comma separated list of traffic assignments in the form REVISION-NAME=PERCENTAGE. |
8889
| `tag_traffic` | _optional_ | | Comma separated list of traffic assignments in the form TAG=PERCENTAGE. |

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ inputs:
8686
Traffic tag to assign to the newly created revision.
8787
required: false
8888

89+
timeout:
90+
description: |-
91+
Set the maximum request execution time. It is specified as a duration; for
92+
example, "10m5s" is ten minutes and five seconds. If you don't specify a
93+
unit, seconds is assumed.
94+
required: false
95+
8996
no_traffic:
9097
description: |-
9198
True to avoid sending traffic to the revision being deployed. Setting

dist/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/deploy-cloudrun.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export async function run(): Promise<void> {
6161
const source = core.getInput('source'); // Source directory
6262
const suffix = core.getInput('suffix');
6363
const tag = core.getInput('tag');
64+
const timeout = core.getInput('timeout');
6465
const noTraffic = core.getBooleanInput('no_traffic');
6566
const revTraffic = core.getInput('revision_traffic');
6667
const tagTraffic = core.getInput('tag_traffic');
@@ -121,11 +122,12 @@ export async function run(): Promise<void> {
121122
source,
122123
];
123124
installBeta = true;
125+
if (timeout) cmd.push('--timeout', timeout);
124126
} else if (metadata) {
125127
// Deploy service from metadata
126-
if (image || name || envVars || secrets) {
128+
if (image || name || envVars || secrets || timeout) {
127129
core.warning(
128-
'Metadata YAML provided: ignoring `image`, `service`, `env_vars` and `secrets` inputs.',
130+
`Metadata YAML provided, ignoring: "image", "service", "env_vars", "secrets", and "timeout" inputs.`,
129131
);
130132
}
131133
cmd = ['run', 'services', 'replace', metadata, '--platform', 'managed', '--region', region];
@@ -159,6 +161,7 @@ export async function run(): Promise<void> {
159161
if (suffix) cmd.push('--revision-suffix', suffix);
160162
if (noTraffic) cmd.push('--no-traffic');
161163
}
164+
if (timeout) cmd.push('--timeout', timeout);
162165
// Add optional flags
163166
if (flags) {
164167
const flagList = parseFlags(flags);

tests/unit/deploy-cloudrun.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const fakeInputs: { [key: string]: string } = {
3333
source: '',
3434
suffix: '',
3535
tag: '',
36+
timeout: '',
3637
revision_traffic: '',
3738
tag_traffic: '',
3839
};
@@ -56,7 +57,6 @@ describe('#deploy-cloudrun', function () {
5657
parseServiceAccountKey: sinon.stub(setupGcloud, 'parseServiceAccountKey'),
5758
isProjectIdSet: sinon.stub(setupGcloud, 'isProjectIdSet').resolves(true),
5859
installComponent: sinon.stub(setupGcloud, 'installComponent'),
59-
6060
getExecOutput: sinon.stub(exec, 'getExecOutput'),
6161
};
6262
});
@@ -126,6 +126,14 @@ describe('#deploy-cloudrun', function () {
126126
await run();
127127
expect(this.stubs.installComponent.withArgs('beta').callCount).to.eq(1);
128128
});
129+
it('sets timeout if given', async function () {
130+
this.stubs.getInput.withArgs('timeout').returns('55m12s');
131+
await run();
132+
const call = this.stubs.getExecOutput.getCall(0);
133+
expect(call).to.be;
134+
const args = call.args[1];
135+
expect(args).to.include.members(['--timeout', '55m12s']);
136+
});
129137
it('installs beta components with tag', async function () {
130138
this.stubs.getInput.withArgs('tag').returns('test');
131139
await run();

0 commit comments

Comments
 (0)