Skip to content

Manually Update Website from Google Sheets #95

Manually Update Website from Google Sheets

Manually Update Website from Google Sheets #95

name: Manually Update Website from Google Sheets
on:
workflow_dispatch: # Allow manual triggering
schedule:
- cron: '0 10 * * *' # Automatic refresh once per day (12:00 CAT / 10:00 UTC)
jobs:
update:
runs-on: ubuntu-latest
concurrency:
group: website-sheet-update
cancel-in-progress: true
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: main # Checkout the main branch
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
# Install all necessary dependencies for build and backup
pip install pandas openpyxl gspread oauth2client python-dotenv thefuzz[speedup]
- name: Create service account credentials
env:
GOOGLE_SHEETS_CREDENTIALS: ${{ secrets.GOOGLE_SHEETS_CREDENTIALS }}
run: |
echo "Creating credentials file..."
CRED_DIR="data_sources/google_sheets_api"
CRED_FILE="$CRED_DIR/service_account_JN.json"
mkdir -p $CRED_DIR
echo "${GOOGLE_SHEETS_CREDENTIALS}" > "$CRED_FILE"
if [ ! -f "$CRED_FILE" ] || [ ! -s "$CRED_FILE" ]; then
echo "Error: Failed to create credentials file."
exit 1
fi
echo "Credentials file created."
- name: Build Website and Backup Data
env:
GOOGLE_SHEET_URL: https://docs.google.com/spreadsheets/d/18sgZgPGZuZjeBTHrmbr1Ra7mx8vSToUqnx8vCjhIp0c/edit?gid=2002859408#gid=2002859408
GOOGLE_SHEET_GID: '2002859408'
run: |
echo "Running build script..."
python scripts/build_from_google_sheets.py
if [ $? -ne 0 ]; then
echo "::error::Build script failed."
exit 1
fi
echo "Build script finished."
- name: Commit and push changes to main
run: |
git config --global user.name "GitHub Actions (Sheet Update)"
git config --global user.email "actions@github.com"
git add --all # Add all changes (index.html, excel, backups, etc.)
# Check if there are changes staged
if git diff --staged --quiet; then
echo "No changes to commit."
else
echo "Committing changes..."
# Commit with a timestamp
if [ "${{ github.event_name }}" = "schedule" ]; then
commit_msg="Automated update from Google Sheets - $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
else
commit_msg="Manually triggered update from Google Sheets - $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
fi
git commit -m "$commit_msg"
echo "Pushing changes to main branch..."
# Ensure push goes to the correct branch (main)
git push origin main
fi
# Removed the GitHub Pages status check as it might not be relevant
# depending on exact deployment setup.