From d24b5f499a4d1b59f6b0c982312e0e1856c7dc7b Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 6 Jul 2020 17:41:54 -0700 Subject: [PATCH 1/6] Adds newly available GCF regions. --- src/function-configuration.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/function-configuration.ts b/src/function-configuration.ts index 05d4517a8..59063d3a1 100644 --- a/src/function-configuration.ts +++ b/src/function-configuration.ts @@ -5,11 +5,15 @@ export const SUPPORTED_REGIONS = [ 'us-central1', 'us-east1', 'us-east4', + 'us-west3', 'europe-west1', 'europe-west2', 'europe-west3', + 'europe-west6', 'asia-east2', 'asia-northeast1', + 'northamerica-northeast1', + 'australia-southeast1' ] as const; /** From b118737c189eaed52f9d66b37fd03ab796560096 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 6 Jul 2020 17:45:25 -0700 Subject: [PATCH 2/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43975c685..eaac773d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Fixes error when last argument to logger methods is `null`. (#716) +- Adds newly available locations `us-west3`, `europe-west6`, `northamerica-northeast1`, and `australia-southeast1`. From 3fe2b8359dc572f253de6205b20b880ce894a2e8 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Mon, 6 Jul 2020 17:47:35 -0700 Subject: [PATCH 3/6] Prettier --- src/function-configuration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/function-configuration.ts b/src/function-configuration.ts index 59063d3a1..2006145fb 100644 --- a/src/function-configuration.ts +++ b/src/function-configuration.ts @@ -13,7 +13,7 @@ export const SUPPORTED_REGIONS = [ 'asia-east2', 'asia-northeast1', 'northamerica-northeast1', - 'australia-southeast1' + 'australia-southeast1', ] as const; /** From 995641cbda04593287d0d42de94677b6afa715be Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 7 Jul 2020 09:24:27 -0700 Subject: [PATCH 4/6] Don't throw on unrecognized region. --- src/function-builder.ts | 11 ++++------- src/function-configuration.ts | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/function-builder.ts b/src/function-builder.ts index 580e0498b..76c4b6c9d 100644 --- a/src/function-builder.ts +++ b/src/function-builder.ts @@ -78,11 +78,6 @@ function assertRegionsAreValid(regions: string[]): boolean { if (!regions.length) { throw new Error('You must specify at least one region'); } - if (_.difference(regions, SUPPORTED_REGIONS).length) { - throw new Error( - `The only valid regions are: ${SUPPORTED_REGIONS.join(', ')}` - ); - } return true; } @@ -95,7 +90,7 @@ function assertRegionsAreValid(regions: string[]): boolean { * functions.region('us-east1', 'us-central1') */ export function region( - ...regions: Array + ...regions: Array ): FunctionBuilder { if (assertRegionsAreValid(regions)) { return new FunctionBuilder({ regions }); @@ -127,7 +122,9 @@ export class FunctionBuilder { * @example * functions.region('us-east1', 'us-central1') */ - region(...regions: Array): FunctionBuilder { + region( + ...regions: Array + ): FunctionBuilder { if (assertRegionsAreValid(regions)) { this.options.regions = regions; return this; diff --git a/src/function-configuration.ts b/src/function-configuration.ts index 2006145fb..2ec102fda 100644 --- a/src/function-configuration.ts +++ b/src/function-configuration.ts @@ -74,6 +74,6 @@ export interface RuntimeOptions { } export interface DeploymentOptions extends RuntimeOptions { - regions?: Array; + regions?: Array; schedule?: Schedule; } From 30767e0968dedc1bda49f9e9aeff34df883d9238 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 7 Jul 2020 10:14:28 -0700 Subject: [PATCH 5/6] CHANGELOG, region fetching script. --- CHANGELOG.md | 1 + scripts/fetch-regions | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100755 scripts/fetch-regions diff --git a/CHANGELOG.md b/CHANGELOG.md index eaac773d7..edab83fdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ - Fixes error when last argument to logger methods is `null`. (#716) - Adds newly available locations `us-west3`, `europe-west6`, `northamerica-northeast1`, and `australia-southeast1`. +- No longer throw errors for unrecognized regions (deploy will error instead). diff --git a/scripts/fetch-regions b/scripts/fetch-regions new file mode 100755 index 000000000..d529cdf9b --- /dev/null +++ b/scripts/fetch-regions @@ -0,0 +1,7 @@ +#!/bin/bash + +if [ -z $1 ]; then + echo "Must provide a project id as first argument." && exit 1 +fi; + +gcloud functions regions list --project $1 --format=json | jq 'map(.locationId)' \ No newline at end of file From ee0309563fb47af8fb12d5bf4e3a3a4968de3327 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 7 Jul 2020 10:21:01 -0700 Subject: [PATCH 6/6] Fix tests. --- spec/function-builder.spec.ts | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/spec/function-builder.spec.ts b/spec/function-builder.spec.ts index 0044e5661..0ad4265ed 100644 --- a/spec/function-builder.spec.ts +++ b/spec/function-builder.spec.ts @@ -121,14 +121,6 @@ describe('FunctionBuilder', () => { expect(fn.__trigger.timeout).to.deep.equal('90s'); }); - it('should fail if valid runtime options but unsupported region are set (reverse order)', () => { - expect(() => { - functions - .runWith({ timeoutSeconds: 90, memory: '256MB' }) - .region('unsupported' as any); - }).to.throw(Error, 'region'); - }); - it('should fail if supported region but invalid runtime options are set (reverse order)', () => { expect(() => { functions @@ -165,28 +157,6 @@ describe('FunctionBuilder', () => { }).to.throw(Error, 'TimeoutSeconds'); }); - it('should throw an error if user chooses an invalid region', () => { - expect(() => { - return functions.region('unsupported' as any); - }).to.throw(Error, 'region'); - - expect(() => { - return functions.region('unsupported' as any).runWith({ - timeoutSeconds: 500, - } as any); - }).to.throw(Error, 'region'); - - expect(() => { - return functions.region('unsupported' as any, 'us-east1'); - }).to.throw(Error, 'region'); - - expect(() => { - return functions.region('unsupported' as any, 'us-east1').runWith({ - timeoutSeconds: 500, - } as any); - }).to.throw(Error, 'region'); - }); - it('should throw an error if user chooses no region when using .region()', () => { expect(() => { return functions.region();