Skip to content

Commit 24b4341

Browse files
committed
VertexAI: add support for mock responses versioning system
1 parent 52f8deb commit 24b4341

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright 2024 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: Check Vertex AI Mock Responses Version
16+
17+
on: pull_request
18+
19+
jobs:
20+
check-responses-version:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Clone mock responses
25+
run: scripts/update_vertexai_responses.sh
26+
- name: Find cloned and latest versions
27+
run: |
28+
echo "current_tag=$(git describe --tags)" >> $GITHUB_ENV
29+
# Fetch the latest tag matching the major version from the golden files repository
30+
echo "latest_tag=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' \
31+
https://github.com/FirebaseExtended/vertexai-sdk-test-data.git | tail -n1 \
32+
| awk -F'/' '{print $NF}')" >> $GITHUB_ENV
33+
working-directory: packages/vertexai/test-utils/vertexai-sdk-test-data
34+
- name: Find comment from previous run if exists
35+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
36+
id: fc
37+
with:
38+
issue-number: ${{github.event.number}}
39+
body-includes: Vertex AI Mock Responses Check
40+
- name: Comment on PR if newer version is available
41+
if: ${{env.current_tag != env.latest_tag && !steps.fc.outputs.comment-id}}
42+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
43+
with:
44+
issue-number: ${{github.event.number}}
45+
body: >
46+
### Vertex AI Mock Responses Check :warning:
47+
48+
A newer major version of the mock responses for Vertex AI unit tests is available.
49+
[update_vertexai_responses.sh](https://github.com/firebase/firebase-js-sdk/blob/main/scripts/update_vertexai_responses.sh)
50+
should be updated to clone the latest version of the responses.
51+
- name: Delete comment when version gets updated
52+
if: ${{env.current_tag == env.latest_tag && steps.fc.outputs.comment-id}}
53+
uses: detomarco/delete-comment@850734dd44d8b15fef55b45252613b903ceb06f0
54+
with:
55+
comment-id: ${{ steps.fc.outputs.comment-id }}

packages/vertexai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"build": "rollup -c && yarn api-report",
3434
"build:deps": "lerna run --scope @firebase/vertexai --include-dependencies build",
3535
"dev": "rollup -c -w",
36-
"update-responses": "cd test-utils && rm -rf vertexai-sdk-test-data && git clone --depth 1 https://github.com/FirebaseExtended/vertexai-sdk-test-data.git",
36+
"update-responses": "../../scripts/update_vertexai_responses.sh",
3737
"testsetup": "yarn update-responses && yarn ts-node ./test-utils/convert-mocks.ts",
3838
"test": "run-p --npm-path npm lint test:browser",
3939
"test:ci": "yarn testsetup && node ../../scripts/run_tests_in_ci.js -s test",

scripts/update_vertexai_responses.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script replaces mock response files for Vertex AI unit tests with a fresh
18+
# clone of the shared repository of Vertex AI test data.
19+
20+
RESPONSES_VERSION='v1.*' # The major version of mock responses to use
21+
REPO="https://github.com/FirebaseExtended/vertexai-sdk-test-data.git"
22+
# Fetch the latest tag matching the major version from the golden files repository
23+
TAG=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' "$REPO" \
24+
| grep "$RESPONSES_VERSION" \
25+
| tail -n1 \
26+
| awk -F'/' '{print $NF}')
27+
28+
cd "$(dirname "$0")/../packages/vertexai/test-utils" || exit
29+
rm -rf vertexai-sdk-test-data
30+
git clone --quiet --config advice.detachedHead=false --depth 1 --branch "$TAG" "$REPO"

0 commit comments

Comments
 (0)