Skip to content

Commit

Permalink
Set up GitHub workflow to update Google Sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
mythilytm committed Jul 23, 2024
0 parents commit f112813
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/sheetsapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# update google sheets
name: Update Google Sheets

on:
push:
branches:
- main
tags:
- '*'

jobs:
update-sheet:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
- name: Update Google Sheets
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
run: echo "${GOOGLE_SHEETS_CREDENTIALS}" > credentials.json
python update_matrix.py
23 changes: 23 additions & 0 deletions update_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import json
import gspread
from google.oauth2.service_account import Credentials

# Load credentials from the environment variable
credentials_json = os.getenv('GOOGLE_SHEETS_CREDENTIALS')
credentials_data = json.loads(credentials_json)

# Define the scope and credentials

credentials = Credentials.from_service_account_info(credentials_data, 'https://www.googleapis.com/auth/spreadsheets')

# Initialize the client
client = gspread.authorize(credentials)

# Open the Google Sheet
sheet = client.open("Product Matrices").worksheet("Deployment Matrix")

# Update the sheet
sheet.update('B2', 'Hello, sheet!')

print('Sheet updated successfully!')

0 comments on commit f112813

Please sign in to comment.