taking in service account creds #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Testing notebooks with pytest | |
on: | |
workflow_dispatch: | |
#push: | |
# branches: | |
# - "*" | |
#pull_request: | |
# branches: | |
# - "*" | |
jobs: | |
test-notebook: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.8 | |
- name: Install dependencies | |
run: | | |
pip install jupyter | |
pip install pytest nbmake nbformat | |
## Later move the above to a requrements.txt and run the below | |
## pip install -r requirements.txt | |
- name: Generate configuration file from secrets | |
env: | |
TKF_CHAVI: ${{ secrets.TKF_PICHAI_BAADAL_CHAVI }} | |
NOTEBOOK_GCP_PROJECT_ID: ${{ secrets.NOTEBOOK_GCP_PROJECT_ID }} | |
NOTEBOOK_GCP_LOCATION: ${{ vars.NOTEBOOK_GCP_LOCATION }} | |
#run: | | |
# echo '{' > env.json | |
# echo ' "NOTEBOOK_GCP_PROJECT_ID": "'${NOTEBOOK_GCP_PROJECT_ID}'",' >> env.json | |
# echo ' "NOTEBOOK_GCP_LOCATION": "'${NOTEBOOK_GCP_LOCATION}'"' >> env.json | |
# echo '}' >> env.json | |
- name: Run tests with pytest | |
run: | | |
pwd | |
import os | |
import json | |
from google.oauth2 import service_account | |
# Access the service account key from the environment variable | |
service_account_key = os.environ.get("GCP_SERVICE_ACCOUNT_KEY") | |
if service_account_key is None: | |
raise ValueError("Service account key is not set in environment variables.") | |
# Parse the JSON key | |
key_data = json.loads(service_account_key) | |
# Authenticate with the service account key | |
credentials = service_account.Credentials.from_service_account_info(key_data) | |
# (Optional) Use the credentials for API initialization | |
from google.cloud import aiplatform | |
# Initialize Vertex AI Platform | |
PROJECT_ID = os.environ.get("NOTEBOOK_GCP_PROJECT_ID") | |
REGION = os.environ.get("NOTEBOOK_GCP_LOCATION") | |
aiplatform.init(project=PROJECT_ID, location=REGION, credentials=credentials) | |
jupyter nbconvert --to notebook --execute notebooks/GenAI/Gemini_Intro.ipynb | |
#pytest -s testing/test_notebooks.py | |