Skip to content

Commit

Permalink
Add support for build_environment_variables (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Dec 8, 2021
1 parent b15c729 commit 564e6a0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ jobs:
event_trigger_type: 'providers/cloud.pubsub/eventTypes/topic.publish'
event_trigger_resource: '${{ secrets.DEPLOY_CF_EVENT_PUBSUB_TOPIC }}'
env_vars_file: './tests/env-var-files/test.good.yaml'
build_environment_variables: 'FOO=bar, ZIP=zap'
build_environment_variables_file: './tests/env-var-files/test.good.yaml'

# Auth as the main account for integration and cleanup
- uses: 'google-github-actions/auth@main'
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ steps:

- `deploy_timeout`: (Optional) The function deployment timeout in seconds. Defaults to 300.

- `build_environment_variables`: (Optional) List of environment variables that
should be available while the function is built. Note this is different than
runtime environment variables, which should be set with 'env_vars'.

- `build_environment_variables_file`: (Optional) Path to a local YAML file
containing variables. See 'env_vars_file' for syntax.

- `credentials`: (**Deprecated**) This input is deprecated. See [auth section](https://github.com/google-github-actions/deploy-cloud-functions#via-google-github-actionsauth) for more details.
Service account key to use for authentication. This should be
the JSON formatted private key which can be exported from the Cloud Console. The
Expand Down
13 changes: 13 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ inputs:
default: 300
required: false

build_environment_variables:
description: |-
Optional list of environment variables that should be available while the
function is built. Note this is different than runtime environment
variables, which should be set with 'env_vars'.
required: false

build_environment_variables_file:
description: |-
Path to a local YAML file containing variables. See 'env_vars_file' for
syntax.
required: false

outputs:
url:
description: The URL of your Cloud Function. Only available with HTTP Trigger.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ async function run(): Promise<void> {
const deployTimeout = presence(getInput('deploy_timeout'));
const labels = parseKVString(getInput('labels'));

const buildEnvVars = presence(getInput('build_environment_variables'));
const buildEnvVarsFile = presence(
getInput('build_environment_variables_file'),
);

// Add warning if using credentials
let credentialsJSON:
| ServiceAccountKey
Expand Down Expand Up @@ -102,6 +107,10 @@ async function run(): Promise<void> {
credentials: credentialsJSON,
});

const buildEnvironmentVariables = parseKVStringAndFile(
buildEnvVars,
buildEnvVarsFile,
);
const environmentVariables = parseKVStringAndFile(envVars, envVarsFile);

// Create Function definition
Expand All @@ -110,7 +119,7 @@ async function run(): Promise<void> {
runtime: runtime,
description: description,
availableMemoryMb: availableMemoryMb ? +availableMemoryMb : undefined,
// buildEnvironmentVariables: buildEnvironmentVariables, // TODO: add support
buildEnvironmentVariables: buildEnvironmentVariables,
// buildWorkerPool: buildWorkerPool, // TODO: add support
// dockerRepository: dockerRepository, // TODO: add support
entryPoint: entryPoint,
Expand Down
1 change: 1 addition & 0 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('CloudFunctionsClient', () => {
name: testFunctionName,
runtime: 'nodejs12',
environmentVariables: { KEY1: 'VALUE1' },
buildEnvironmentVariables: { KEY1: 'VALUE1' },
entryPoint: 'helloWorld',
availableMemoryMb: 512,
sourceUploadUrl: sourceURL,
Expand Down

0 comments on commit 564e6a0

Please sign in to comment.