Update main.yml #9
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
name: Fetch GitHub Traffic Data | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs every day at midnight UTC | |
push: | |
branches: | |
- main | |
jobs: | |
fetch-traffic: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Fetch traffic data | |
id: traffic | |
run: | | |
API_URL_CLONES="https://api.github.com/repos/${{ github.repository }}/traffic/clones" | |
API_URL_TOP_PATHS="https://api.github.com/repos/${{ github.repository }}/traffic/popular/paths" | |
API_URL_TOP_REFERRERS="https://api.github.com/repos/${{ github.repository }}/traffic/popular/referrers" | |
API_URL_VIEWS="https://api.github.com/repos/${{ github.repository }}/traffic/views" | |
AUTH_HEADER="Authorization: token ${{ secrets.PAT }}" | |
mkdir -p traffic_data | |
curl -sSL -H "${AUTH_HEADER}" "${API_URL_CLONES}" > traffic_data/clones.json | |
curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_PATHS}" > traffic_data/top_paths.json | |
curl -sSL -H "${AUTH_HEADER}" "${API_URL_TOP_REFERRERS}" > traffic_data/top_referrers.json | |
curl -sSL -H "${AUTH_HEADER}" "${API_URL_VIEWS}" > traffic_data/views.json | |
- name: Debug - Check contents of traffic_data directory | |
run: | | |
ls -l traffic_data | |
cat traffic_data/*.json | |
- name: Commit and push changes | |
uses: ad-m/[email protected] | |
with: | |
# Valid Inputs: ['github_token', 'github_url', 'ssh', 'repository', 'branch', 'force', 'force_with_lease', 'atomic', 'tags', 'directory'] | |
github_token: ${{ secrets.PAT }} | |
repository: ${{ github.repository }} | |
branch: traffic | |
directory: traffic_data |