From d72fed6791d39f5fe633c9ad96907d2c35331b0c Mon Sep 17 00:00:00 2001 From: Chris Keller Date: Wed, 21 Jul 2021 11:43:54 -0600 Subject: [PATCH] feat: expose deploy timeout as an action input (#125) Resolves #124 Co-authored-by: Bharath KKB --- README.md | 2 ++ action.yaml | 5 +++++ src/cloudFunction.ts | 7 +++++++ src/cloudFunctionClient.ts | 10 ++++++---- src/main.ts | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9b22bad..7a6220f 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,8 @@ steps: - `event_trigger_service`: (Optional) The hostname of the service that should be observed. +- `deploy_timeout`: (Optional) The function deployment timeout in seconds. Defaults to 300. + ## Allow unauthenticated requests A Cloud Functions product recommendation is that CI/CD systems not set or change diff --git a/action.yaml b/action.yaml index ea9d46f..5c01ae6 100644 --- a/action.yaml +++ b/action.yaml @@ -116,6 +116,11 @@ inputs: The hostname of the service that should be observed. required: false + deploy_timeout: + description: |- + The function deployment timeout in seconds. + required: false + outputs: url: description: The URL of your Cloud Function. Only available with HTTP Trigger. diff --git a/src/cloudFunction.ts b/src/cloudFunction.ts index 97a8589..7247f4c 100644 --- a/src/cloudFunction.ts +++ b/src/cloudFunction.ts @@ -40,6 +40,7 @@ export type KVPair = { * @param eventTriggerType Specifies which action should trigger the function. * @param eventTriggerResource Specifies which resource from eventTrigger is observed. * @param eventTriggerService The hostname of the service that should be observed. + * @param deployTimeout The function deployment timeout in seconds. * @param labels List of key-value pairs to set as function labels. */ @@ -60,6 +61,7 @@ export type CloudFunctionOptions = { eventTriggerType?: string; eventTriggerResource?: string; eventTriggerService?: string; + deployTimeout?: string; labels?: string; }; @@ -74,6 +76,8 @@ export class CloudFunction { readonly name: string; readonly sourceDir: string; readonly functionPath: string; + readonly deployTimeout: number; + constructor(opts: CloudFunctionOptions) { this.functionPath = `${opts.parent}/functions/${opts.name}`; @@ -138,6 +142,9 @@ export class CloudFunction { this.request = request; this.name = opts.name; this.sourceDir = opts.sourceDir ? opts.sourceDir : './'; + this.deployTimeout = opts.deployTimeout + ? parseInt(opts.deployTimeout) + : 300; } /** diff --git a/src/cloudFunctionClient.ts b/src/cloudFunctionClient.ts index 6445051..5176fdb 100644 --- a/src/cloudFunctionClient.ts +++ b/src/cloudFunctionClient.ts @@ -19,12 +19,12 @@ import * as path from 'path'; import * as os from 'os'; import { GaxiosResponse } from 'gaxios'; import { CloudFunction } from './cloudFunction'; -import { uploadSource, zipDir, deleteZipFile } from './util'; -import { google, cloudfunctions_v1 } from 'googleapis'; +import { deleteZipFile, uploadSource, zipDir } from './util'; +import { cloudfunctions_v1, google } from 'googleapis'; import { + Compute, GoogleAuth, JWT, - Compute, UserRefreshClient, } from 'google-auth-library'; @@ -100,6 +100,7 @@ export class CloudFunctionClient { this.parent = `projects/${projectId}/locations/${region}`; } + /** * Retrieves the auth client for authenticating requests. * @@ -260,7 +261,7 @@ export class CloudFunctionClient { updateFunctionResponse.data, 'Updating function deployment', 2, - 150, + cf.deployTimeout / 2, ); core.info('Function deployment updated'); return awaitUpdate; @@ -287,6 +288,7 @@ export class CloudFunctionClient { return awaitCreate; } } + /** * Delete a Cloud Function. * diff --git a/src/main.ts b/src/main.ts index e75b2ca..0a786c9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,6 +38,7 @@ async function run(): Promise { const eventTriggerType = core.getInput('event_trigger_type'); const eventTriggerResource = core.getInput('event_trigger_resource'); const eventTriggerService = core.getInput('event_trigger_service'); + const deployTimeout = core.getInput('deploy_timeout'); const labels = core.getInput('labels'); // Create Cloud Functions client @@ -58,6 +59,7 @@ async function run(): Promise { eventTriggerType, eventTriggerResource, eventTriggerService, + deployTimeout, vpcConnector, serviceAccountEmail, labels,