Skip to content

Export Google Sheet #78

Export Google Sheet

Export Google Sheet #78

name: Export Google Sheet
on:
schedule:
- cron: "30 1,13 * * *" # Runs at 01:30 and 13:30 UTC every day
workflow_dispatch: # Allows manual triggering of the workflow
permissions: write-all
jobs:
export_gsheet:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v4
- name: Create necessary directories
run: |
mkdir -p gsheet/csv gsheet/xlsx
- name: Download Google Sheet as XLSX
run: |
curl -L -o gsheet/xlsx/entities.xlsx "https://docs.google.com/spreadsheets/d/${{ secrets.GOOGLE_SHEET_ID }}/export?format=xlsx"
- name: Download Google Sheet as CSV
run: |
curl -L -o gsheet/csv/persons.csv "https://docs.google.com/spreadsheets/d/${{ secrets.GOOGLE_SHEET_ID }}/export?format=csv&gid=0"
curl -L -o gsheet/csv/places.csv "https://docs.google.com/spreadsheets/d/${{ secrets.GOOGLE_SHEET_ID }}/export?format=csv&gid=184309475"
curl -L -o gsheet/csv/works.csv "https://docs.google.com/spreadsheets/d/${{ secrets.GOOGLE_SHEET_ID }}/export?format=csv&gid=1455068830"
curl -L -o gsheet/csv/institutions.csv "https://docs.google.com/spreadsheets/d/${{ secrets.GOOGLE_SHEET_ID }}/export?format=csv&gid=1506597506"
- name: Configure Git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
- name: Commit CSV files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git add gsheet/csv/persons.csv
git add gsheet/csv/places.csv
git add gsheet/csv/works.csv
git add gsheet/csv/institutions.csv
git commit -m "Export CSV from Google Sheet (entities)" || echo "No changes to commit"
- name: Commit XLSX file if a CSV file has changed
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git diff --name-only origin/main -- gsheet/csv/*.csv > changed_files.txt
if grep -qE '(persons|places|works|institutions)\.csv' changed_files.txt; then
git add gsheet/xlsx/entities.xlsx
git commit -m "Export XLSX from Google Sheet (entities)"
fi
- name: Push Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push