Skip to content

Nightly traffic snapshot #165

Nightly traffic snapshot

Nightly traffic snapshot #165

name: Nightly traffic snapshot
on:
schedule:
# 03:00 UTC daily — after GitHub's traffic counters roll over.
- cron: "0 3 * * *"
workflow_dispatch: {}
permissions:
contents: write
jobs:
snapshot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: actions/create-github-app-token@v2
id: personal-token
with:
app-id: ${{ secrets.TRAFFIC_APP_ID }}
private-key: ${{ secrets.TRAFFIC_APP_PRIVATE_KEY }}
owner: jordankingisalive
- name: Run snapshot
id: snapshot
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.TRAFFIC_PAT }}
# Personal repos authenticate via the GitHub App - nothing to rotate.
# The org half stays on TRAFFIC_PAT until microsoft approves the install.
GITHUB_TOKEN_PERSONAL: ${{ steps.personal-token.outputs.token }}
CLARITY_TOKEN_HUB: ${{ secrets.CLARITY_TOKEN_HUB }}
CLARITY_TOKEN_PERSONAL: ${{ secrets.CLARITY_TOKEN_PERSONAL }}
run: python scripts/snapshot_traffic.py
# Always commit whatever was captured. The script writes the file before
# evaluating its health gates, so a single failing gate must not discard
# data that fetched correctly. A TRAFFIC_PAT expiry on 4 Aug 2026 caused
# seven consecutive days of Clarity data to be thrown away this way, and
# the resulting hole was mistaken for a Clarity outage.
- name: Commit & push if changed
if: always()
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add docs/data/traffic-history.json
if git diff --cached --quiet; then
echo "No traffic changes."
else
git commit -m "chore: nightly traffic snapshot $(date -u +%Y-%m-%d)"
git push
fi
# Surface the health-gate result after the data is safely committed, so
# the run still goes red and sends the failure notification.
- name: Fail if snapshot health gates tripped
if: always() && steps.snapshot.outcome == 'failure'
run: |
echo "::error::Snapshot health gates failed — see the 'Run snapshot' step."
echo "Data captured before the failure has still been committed."
exit 1