Skip to content

Commit a5b186d

Browse files
authored
Switch to gen2 API (#409)
This PR moves everything to use the `v2` API and adopts the "GEN_2" function type. This is a major breaking change that should be released as v3. As per our support policy, we will support v2 and v3, with v2 receiving critical bug fixes. We will drop support for v1. - Fixes #304 - Closes #384 (N/A in GEN_2) - Fixes #373 - Closes #399 (Cloud Functions recommends against CI/CD systems controlling IAM permissions) - Closes #9 (N/A)
1 parent 6282b54 commit a5b186d

18 files changed

+1967
-1298
lines changed

.github/workflows/cleanup.yml

+22-22
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ jobs:
1414
runs-on: 'ubuntu-latest'
1515

1616
steps:
17-
- uses: 'actions/checkout@v4'
18-
19-
- uses: 'google-github-actions/auth@v2'
20-
with:
21-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
22-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
23-
24-
- uses: 'google-github-actions/setup-gcloud@v2'
25-
26-
- name: Delete services
27-
run: |-
28-
gcloud config set core/project "${{ vars.PROJECT_ID }}"
29-
gcloud config set functions/region "us-central1"
30-
31-
# List and delete all functions that were deployed 30 minutes ago or
32-
# earlier. The date math here is a little weird, but we're looking for
33-
# deployments "earlier than" 30 minutes ago, so it's less than since
34-
# time increases.
35-
(IFS=$'\n'; for NAME in $(gcloud functions list --format="value(name)" --filter="updateTime < '-pt30m'"); do
36-
echo "Deleting ${NAME}..."
37-
gcloud functions delete ${NAME} --quiet
38-
done)
17+
- uses: 'actions/checkout@v4'
18+
19+
- uses: 'google-github-actions/auth@v2'
20+
with:
21+
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
22+
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
23+
24+
- uses: 'google-github-actions/setup-gcloud@v2'
25+
26+
- name: Delete services
27+
run: |-
28+
gcloud config set core/project "${{ vars.PROJECT_ID }}"
29+
gcloud config set functions/region "us-central1"
30+
31+
# List and delete all functions that were deployed 30 minutes ago or
32+
# earlier. The date math here is a little weird, but we're looking for
33+
# deployments "earlier than" 30 minutes ago, so it's less than since
34+
# time increases.
35+
(IFS=$'\n'; for NAME in $(gcloud functions list --format="value(name)" --filter="updateTime < '-pt30m'"); do
36+
echo "Deleting ${NAME}..."
37+
gcloud functions delete ${NAME} --quiet
38+
done)

.github/workflows/draft-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
version_strategy: '${{ github.event.inputs.version_strategy }}'
2222
# secrets must be explicitly passed to reusable workflows https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/reusing-workflows#using-inputs-and-secrets-in-a-reusable-workflow
2323
secrets:
24-
ACTIONS_BOT_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'
24+
ACTIONS_BOT_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'

.github/workflows/integration.yml

+54-51
Original file line numberDiff line numberDiff line change
@@ -17,74 +17,77 @@ concurrency:
1717

1818
jobs:
1919
https_trigger:
20-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
20+
timeout-minutes: 10
2121
permissions:
2222
contents: 'read'
2323
id-token: 'write'
2424
runs-on: 'ubuntu-latest'
2525
steps:
26-
- uses: 'actions/checkout@v4'
26+
- uses: 'actions/checkout@v4'
2727

28-
- uses: 'actions/setup-node@v4'
29-
with:
30-
node-version: '20.x'
28+
- uses: 'actions/setup-node@v4'
29+
with:
30+
node-version: '20.x'
3131

32-
- name: 'npm build'
33-
run: 'npm ci && npm run build'
32+
- name: 'npm build'
33+
run: 'npm ci && npm run build'
3434

35-
- uses: 'google-github-actions/auth@v2'
36-
with:
37-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
38-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
35+
- uses: 'google-github-actions/auth@v2'
36+
with:
37+
project_id: '${{ vars.PROJECT_ID }}'
38+
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
3939

40-
- id: 'deploy'
41-
uses: './'
42-
with:
43-
name: 'https-trigger-${{ github.run_number }}'
44-
runtime: 'nodejs16'
45-
entry_point: 'helloWorld'
46-
source_dir: './tests/test-node-func/'
47-
https_trigger_security_level: 'secure_always'
40+
- id: 'deploy'
41+
uses: './'
42+
with:
43+
name: 'https-trigger-${{ github.run_number }}'
44+
runtime: 'nodejs22'
45+
entry_point: 'helloWorld'
46+
source_dir: './tests/test-node-func/'
47+
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
4848

4949
event_trigger:
50-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
50+
timeout-minutes: 10
5151
permissions:
5252
contents: 'read'
5353
id-token: 'write'
5454
runs-on: 'ubuntu-latest'
5555
steps:
56-
- uses: 'actions/checkout@v4'
56+
- uses: 'actions/checkout@v4'
5757

58-
- uses: 'actions/setup-node@v4'
59-
with:
60-
node-version: '20.x'
58+
- uses: 'actions/setup-node@v4'
59+
with:
60+
node-version: '20.x'
6161

62-
- name: 'npm build'
63-
run: 'npm ci && npm run build'
62+
- name: 'npm build'
63+
run: 'npm ci && npm run build'
6464

65-
- uses: 'google-github-actions/auth@v2'
66-
with:
67-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
68-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
65+
- uses: 'google-github-actions/auth@v2'
66+
with:
67+
project_id: '${{ vars.PROJECT_ID }}'
68+
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
6969

70-
- id: 'deploy'
71-
uses: './'
72-
with:
73-
name: 'event-trigger-${{ github.run_number }}'
74-
runtime: 'nodejs16'
75-
entry_point: 'helloWorld'
76-
source_dir: './tests/test-node-func/'
77-
event_trigger_type: 'providers/cloud.pubsub/eventTypes/topic.publish'
78-
event_trigger_resource: '${{ vars.PUBSUB_TOPIC_NAME }}'
79-
event_trigger_retry: true
80-
env_vars_file: './tests/env-var-files/test.good.yaml'
81-
build_environment_variables: 'FOO=bar, ZIP=zap'
82-
build_environment_variables_file: './tests/env-var-files/test.good.yaml'
83-
secret_environment_variables: |-
84-
FOO=${{ vars.SECRET_VERSION_NAME }}
85-
BAR=${{ vars.SECRET_NAME }}
86-
secret_volumes: '/etc/secrets/foo=${{ vars.SECRET_VERSION_NAME }}'
87-
service_account_email: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
88-
min_instances: 2
89-
max_instances: 5
90-
timeout: 300
70+
- id: 'deploy'
71+
uses: './'
72+
with:
73+
name: 'event-trigger-${{ github.run_number }}'
74+
runtime: 'nodejs22'
75+
entry_point: 'helloWorld'
76+
source_dir: './tests/test-node-func/'
77+
event_trigger_type: 'google.cloud.pubsub.topic.v1.messagePublished'
78+
event_trigger_pubsub_topic: '${{ vars.PUBSUB_TOPIC_NAME }}'
79+
event_trigger_retry: true
80+
event_trigger_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
81+
environment_variables: |-
82+
FOO=bar
83+
ZIP=zap
84+
build_environment_variables: |-
85+
FRUIT=apple
86+
MEAT=bacon
87+
secrets: |-
88+
SECRET_FOO=${{ vars.SECRET_VERSION_NAME }}
89+
SECRET_BAR=${{ vars.SECRET_NAME }}
90+
/etc/secrets/foo=${{ vars.SECRET_VERSION_NAME }}
91+
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
92+
min_instance_count: 2
93+
max_instance_count: 5

.github/workflows/unit.yml

+30-30
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,36 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
os:
28-
- 'ubuntu-latest'
29-
- 'windows-latest'
30-
- 'macos-latest'
28+
- 'ubuntu-latest'
29+
- 'windows-latest'
30+
- 'macos-latest'
3131
runs-on: '${{ matrix.os }}'
3232

3333
steps:
34-
- uses: 'actions/checkout@v4'
35-
36-
- uses: 'actions/setup-node@v4'
37-
with:
38-
node-version: '20.x'
39-
40-
- name: 'npm build'
41-
run: 'npm ci && npm run build'
42-
43-
- name: 'npm lint'
44-
# There's no need to run the linter for each operating system, since it
45-
# will find the same thing 3x and clog up the PR review.
46-
if: ${{ matrix.os == 'ubuntu-latest' }}
47-
run: 'npm run lint'
48-
49-
- uses: 'google-github-actions/auth@v2'
50-
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
51-
with:
52-
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
53-
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
54-
55-
- name: 'npm test'
56-
env:
57-
TEST_PROJECT_ID: '${{ vars.PROJECT_ID }}'
58-
TEST_SERVICE_ACCOUNT_EMAIL: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
59-
TEST_SECRET_VERSION_NAME: '${{ vars.SECRET_VERSION_NAME }}'
60-
run: 'npm run test'
34+
- uses: 'actions/checkout@v4'
35+
36+
- uses: 'actions/setup-node@v4'
37+
with:
38+
node-version: '20.x'
39+
40+
- name: 'npm build'
41+
run: 'npm ci && npm run build'
42+
43+
- name: 'npm lint'
44+
# There's no need to run the linter for each operating system, since it
45+
# will find the same thing 3x and clog up the PR review.
46+
if: ${{ matrix.os == 'ubuntu-latest' }}
47+
run: 'npm run lint'
48+
49+
- uses: 'google-github-actions/auth@v2'
50+
if: ${{ github.event_name == 'push' || github.repository == github.event.pull_request.head.repo.full_name && github.actor != 'dependabot[bot]' }}
51+
with:
52+
workload_identity_provider: '${{ vars.WIF_PROVIDER_NAME }}'
53+
service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
54+
55+
- name: 'npm test'
56+
env:
57+
TEST_PROJECT_ID: '${{ vars.PROJECT_ID }}'
58+
TEST_SERVICE_ACCOUNT_EMAIL: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
59+
TEST_SECRET_VERSION_NAME: '${{ vars.SECRET_VERSION_NAME }}'
60+
run: 'npm run test'

0 commit comments

Comments
 (0)