Sync Data from Google Sheets and PubMed #5
This file contains hidden or 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: Sync Data from Google Sheets | |
| on: | |
| schedule: | |
| # Run daily at 2 AM UTC | |
| - cron: '0 2 * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| jobs: | |
| sync-team-data: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.9' | |
| - name: Install dependencies | |
| run: | | |
| pip install google-auth google-auth-oauthlib google-auth-httplib2 | |
| pip install google-api-python-client PyYAML | |
| - name: Sync Team Data from Google Sheets | |
| env: | |
| SERVICE_ACCOUNT_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }} | |
| TEAM_SPREADSHEET_ID: ${{ secrets.TEAM_SPREADSHEET_ID }} | |
| run: | | |
| # Debug: Check if secret is set | |
| if [ -z "$SERVICE_ACCOUNT_KEY" ]; then | |
| echo "Error: SERVICE_ACCOUNT_KEY secret is not set!" | |
| exit 1 | |
| fi | |
| # Create service account key file from secret | |
| echo "$SERVICE_ACCOUNT_KEY" > service-account-key.json | |
| # Debug: Check file was created | |
| ls -la service-account-key.json | |
| # Run the team sync script | |
| python sync_team_service_account.py | |
| - name: Sync Quotes from Google Sheets | |
| env: | |
| SERVICE_ACCOUNT_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }} | |
| QUOTES_SPREADSHEET_ID: ${{ secrets.QUOTES_SPREADSHEET_ID }} | |
| run: | | |
| # Update the quotes sync script with the spreadsheet ID | |
| if [ -n "$QUOTES_SPREADSHEET_ID" ]; then | |
| sed -i "s/YOUR_QUOTES_SPREADSHEET_ID_HERE/$QUOTES_SPREADSHEET_ID/g" sync_quotes_from_sheets.py | |
| # Run the quotes sync script | |
| python sync_quotes_from_sheets.py | |
| else | |
| echo "QUOTES_SPREADSHEET_ID not set, skipping quotes sync" | |
| fi | |
| - name: Check for changes | |
| id: verify-changed-files | |
| run: | | |
| git diff --quiet _data/*.yml _pages/quotes.md || echo "changed=true" >> $GITHUB_OUTPUT | |
| - name: Commit and push if changed | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| run: | | |
| git config user.name "GitHub Actions" | |
| git config user.email "actions@github.com" | |
| git add _data/*.yml _pages/quotes.md | |
| git commit -m "Update data from Google Sheets" | |
| git push |