diff --git a/.github/workflows/traffic-exporter.yml b/.github/workflows/traffic-exporter.yml new file mode 100644 index 00000000..06e9db07 --- /dev/null +++ b/.github/workflows/traffic-exporter.yml @@ -0,0 +1,37 @@ +name: Export Repo Traffic to Google Sheets + +on: + schedule: + # Runs at 02:00 UTC every day + - cron: '0 2 * * *' + workflow_dispatch: # Allows you to run this workflow manually from the Actions tab + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install gspread oauth2client requests + + - name: Write Google credentials to a file + id: write_creds + uses: timheuer/base64-to-file@v1.2 + with: + fileName: 'google-credentials.json' + encodedString: ${{ secrets.GOOGLE_SHEETS_CREDENTIALS }} + + - name: Run the Python script + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + GOOGLE_SHEETS_CREDENTIALS: ${{ steps.write_creds.outputs.filePath }} + run: python export_traffic.py