Skip to content

Commit dc9370f

Browse files
committed
feat: initial base for generative-ai
1 parent 73de2e8 commit dc9370f

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

.github/auto-label.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ path:
4545
eventarc: "eventarc"
4646
error-reporting: "clouderrorreporting"
4747
functions: "cloudfunctions"
48+
generative-ai: "genai"
4849
game-servers: "gameservices"
4950
healthcare: "healhcare"
5051
iam: "iam"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: generative-ai-snippets
16+
on:
17+
push:
18+
branches:
19+
- main
20+
paths:
21+
- 'generative-ai/snippets/**'
22+
- '.github/workflows/generative-ai-snippets.yaml'
23+
pull_request:
24+
paths:
25+
- 'generative-ai/snippets/**'
26+
- '.github/workflows/generative-ai-snippets.yaml'
27+
pull_request_target:
28+
types: [labeled]
29+
paths:
30+
- 'generative-ai/snippets/**'
31+
- '.github/workflows/generative-ai-snippets.yaml'
32+
schedule:
33+
- cron: '0 0 * * 0'
34+
jobs:
35+
test:
36+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 120
39+
permissions:
40+
contents: 'read'
41+
id-token: 'write'
42+
defaults:
43+
run:
44+
working-directory: 'generative-ai/snippets'
45+
steps:
46+
- uses: actions/[email protected]
47+
with:
48+
ref: ${{github.event.pull_request.head.sha}}
49+
- uses: 'google-github-actions/[email protected]'
50+
with:
51+
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider'
52+
service_account: '[email protected]'
53+
create_credentials_file: 'true'
54+
access_token_lifetime: 600s
55+
- id: secrets
56+
uses: 'google-github-actions/get-secretmanager-secrets@v1'
57+
with:
58+
secrets: |-
59+
caip_id:nodejs-docs-samples-tests/nodejs-docs-samples-ai-platform-caip-project-id
60+
location:nodejs-docs-samples-tests/nodejs-docs-samples-ai-platform-location
61+
- uses: actions/[email protected]
62+
with:
63+
node-version: 16
64+
- name: Get npm cache directory
65+
id: npm-cache-dir
66+
shell: bash
67+
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
68+
- uses: actions/cache@v3
69+
id: npm-cache
70+
with:
71+
path: ${{ steps.npm-cache-dir.outputs.dir }}
72+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
73+
restore-keys: |
74+
${{ runner.os }}-node-
75+
- name: install repo dependencies
76+
run: npm install
77+
working-directory: .
78+
- name: install directory dependencies
79+
run: npm install
80+
- run: npm run build --if-present
81+
- name: set env vars for scheduled run
82+
if: github.event.action == 'schedule'
83+
run: |
84+
echo "MOCHA_REPORTER_SUITENAME=generative-ai-snippets" >> $GITHUB_ENV
85+
echo "MOCHA_REPORTER_OUTPUT=${{github.run_id}}_sponge_log.xml" >> $GITHUB_ENV
86+
echo "MOCHA_REPORTER=xunit" >> $GITHUB_ENV
87+
- run: npm test
88+
env:
89+
LOCATION: ${{ steps.secrets.outputs.location }}
90+
CAIP_PROJECT_ID: ${{ steps.secrets.outputs.caip_id }}
91+
- name: upload test results for FlakyBot workflow
92+
if: github.event.action == 'schedule' && always()
93+
uses: actions/upload-artifact@v3
94+
env:
95+
MOCHA_REPORTER_OUTPUT: "${{github.run_id}}_sponge_log.xml"
96+
with:
97+
name: test-results
98+
path: generative-ai/snippets/${{ env.MOCHA_REPORTER_OUTPUT }}
99+
retention-days: 1
100+
flakybot:
101+
permissions:
102+
contents: 'read'
103+
id-token: 'write'
104+
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
105+
uses: ./.github/workflows/flakybot.yaml
106+
needs: [test]

.github/workflows/utils/workflows-secrets.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"iam/deny",
66
"security-center/snippets",
77
"storagetransfer",
8+
"generative-ai/snippets",
89
"vision"
910
]

generative-ai/snippets/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "nodejs-generativeai-samples",
3+
"private": true,
4+
"license": "Apache-2.0",
5+
"author": "Google LLC",
6+
"engines": {
7+
"node": ">=16.0.0"
8+
},
9+
"files": [
10+
"*.js"
11+
],
12+
"scripts": {
13+
"test": "c8 mocha -p -j 2 --timeout 2400000 test/*.js"
14+
},
15+
"dependencies": {
16+
"@google-cloud/aiplatform": "^3.0.0"
17+
},
18+
"devDependencies": {
19+
"c8": "^8.0.0",
20+
"chai": "^4.2.0",
21+
"mocha": "^10.0.0",
22+
"uuid": "^9.0.0",
23+
"sinon": "^16.0.0"
24+
}
25+
}

0 commit comments

Comments
 (0)