-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up GitHub workflow to update Google Sheet
- Loading branch information
0 parents
commit f112813
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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!') |