Collect LP GitHub Traffic Metrics #20
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: Collect LP GitHub Traffic Metrics | |
| permissions: | |
| contents: write | |
| on: | |
| schedule: | |
| # Run weekly on Fridays at 05:00 UTC | |
| - cron: '0 5 * * 5' | |
| workflow_dispatch: # also allow manual runs | |
| jobs: | |
| collect: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: “Check bi‑weekly cadence” | |
| run: | | |
| START="2025-05-23" | |
| TODAY=$(date +%Y-%m-%d) | |
| DIFF_DAYS=$(( ( $(date -d "$TODAY" +%s) - $(date -d "$START" +%s) ) / 86400 )) | |
| if [ $(( DIFF_DAYS % 14 )) -ne 0 ]; then | |
| echo "Not on a 14‑day boundary; skipping." | |
| exit 0 # success but stop this job | |
| fi | |
| - name: Check out code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: true # allows pushing commits | |
| - name: Create or switch to lp_metrics branch | |
| run: | | |
| # Try to fetch remote branch | |
| git fetch origin lp_metrics:lp_metrics || true | |
| if git show-ref --verify --quiet refs/heads/lp_metrics; then | |
| git checkout lp_metrics | |
| else | |
| git checkout -b lp_metrics | |
| fi | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests | |
| - name: Run traffic collector | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.LP_METRICS_PAT }} | |
| run: | | |
| python .github/scripts/lp_repo_metrics.py --token "$GITHUB_TOKEN" | |
| - name: Commit & push metrics | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add _metrics/*.csv | |
| if ! git diff --cached --quiet; then | |
| git commit -m "Automated metrics update: $(date -u +'%Y-%m-%d')" | |
| git push origin lp_metrics | |
| else | |
| echo "No changes to metrics files." | |
| fi |