Skip to content

Commit 5d58680

Browse files
authored
feat: Add optional memory input (#27)
* feat: Add optional memory input * fmt
1 parent 2ee38a0 commit 5d58680

File tree

7 files changed

+19
-1
lines changed

7 files changed

+19
-1
lines changed

.github/workflows/deploy-cf-it.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
region: us-east1
9797
runtime: nodejs10
9898
entry_point: helloWorld
99+
memory_mb: 512
99100
source_dir: ./tests/test-node-func/
100101
credentials: ${{ secrets.DEPLOY_CF_SA_KEY_JSON }}
101102
- uses: actions/setup-node@master

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ steps:
4949

5050
- `runtime`: (Required) Runtime to use for the function. Possible options documented [here][runtimes].
5151

52-
- `entry_point`: (Optional) Name of a function (as defined in source code) that will be executed. Defaults to the resource name suffix, if not specified.
52+
- `entry_point`: (Optional) Name of a function (as defined in source code) that will be executed. Defaults to the resource name suffix, if not specified.
53+
54+
- `memory_mb`: (Optional) The amount of memory in MB available for a function. Defaults to 256MB.
5355

5456
- `region`: (Optional) [Region](https://cloud.google.com/functions/docs/locations) in which the function should be deployed. Defaults to `us-central1`.
5557

action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ inputs:
6666
Runtime to use for the function.
6767
required: true
6868

69+
memory_mb:
70+
description: |-
71+
The amount of memory in MB available for a function. Defaults to 256MB.
72+
required: false
73+
6974
vpc_connector:
7075
description: |-
7176
The VPC Access connector that the function can connect to.

src/cloudFunction.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type EnvVar = {
2929
* @param envVars List of key-value pairs to set as environment variables.
3030
* @param entryPoint Name of function to execute.
3131
* @param runtime Runtime to use for the function.
32+
* @param availableMemoryMb The amount of memory in MB available for a function.
3233
* @param vpcConnector The VPC Access connector that the function can connect to.
3334
* @param parent Parent of the form projects/${projectId}/locations/${region}.
3435
* @param serviceAccountEmail The email address of the IAM service account associated with the function at runtime.
@@ -46,6 +47,7 @@ export type CloudFunctionOptions = {
4647
envVars?: string;
4748
entryPoint?: string;
4849
runtime: string;
50+
availableMemoryMb?: number;
4951
vpcConnector?: string;
5052
parent: string;
5153
serviceAccountEmail?: string;
@@ -102,6 +104,9 @@ export class CloudFunction {
102104
request.vpcConnector = opts?.vpcConnector ? opts.vpcConnector : null;
103105
request.timeout = opts?.timeout ? `${opts.timeout}s` : null;
104106
request.maxInstances = opts?.maxInstances ? opts.maxInstances : null;
107+
request.availableMemoryMb = opts?.availableMemoryMb
108+
? opts.availableMemoryMb
109+
: null;
105110

106111
// Parse env vars
107112
let envVars;

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async function run(): Promise<void> {
2525
const runtime = core.getInput('runtime', { required: true });
2626
const credentials = core.getInput('credentials');
2727
const projectId = core.getInput('project_id');
28+
const availableMemoryMb = core.getInput('memory_mb');
2829
const region = core.getInput('region') || 'us-central1';
2930
const envVars = core.getInput('env_vars');
3031
const entryPoint = core.getInput('entry_point');
@@ -46,6 +47,7 @@ async function run(): Promise<void> {
4647
parent: client.parent,
4748
sourceDir,
4849
runtime,
50+
availableMemoryMb: +availableMemoryMb,
4951
entryPoint,
5052
envVars,
5153
timeout,

tests/cloudFunction.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('CloudFunction', function () {
3939
serviceAccountEmail: '[email protected]',
4040
timeout: '500',
4141
maxInstances: 10,
42+
availableMemoryMb: 512,
4243
};
4344
const cf = new CloudFunction(funcOptions);
4445
expect(cf.request.name).equal(`${parent}/functions/${name}`);
@@ -52,6 +53,7 @@ describe('CloudFunction', function () {
5253
);
5354
expect(cf.request.timeout).equal(`${funcOptions.timeout}s`);
5455
expect(cf.request.maxInstances).equal(funcOptions.maxInstances);
56+
expect(cf.request.availableMemoryMb).equal(funcOptions.availableMemoryMb);
5557
expect(cf.request.httpsTrigger).not.to.be.null;
5658
expect(cf.request.environmentVariables?.KEY1).equal('VALUE1');
5759
});

tests/cloudFunctionClient.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe('CloudFunction', function () {
5656
runtime: 'nodejs10',
5757
envVars: 'KEY1=VALUE1,KEY2=VALUE2',
5858
entryPoint: 'helloWorld',
59+
availableMemoryMb: 512,
5960
});
6061
const result = await client.deploy(newHttpFunc);
6162
// expect function to be deployed without error

0 commit comments

Comments
 (0)