CCP-NC Organisation Traffic Collection #106
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: CCP-NC Organisation Traffic Collection | |
on: | |
schedule: | |
- cron: "0 */12 * * *" # Twice daily | |
workflow_dispatch: | |
inputs: | |
full_refresh: | |
description: 'Force refresh all repositories' | |
type: boolean | |
default: false | |
jobs: | |
collect-and-commit-traffic: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out Metrics Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: CCP-NC/metrics | |
token: ${{ secrets.ADMIN_TOKEN }} | |
fetch-depth: 1 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: List Organization Repositories | |
id: list-repos | |
env: | |
GH_TOKEN: ${{ secrets.ADMIN_TOKEN }} | |
ORG_NAME: CCP-NC | |
run: | | |
repos=$(gh api graphql -f query=' | |
query($org: String!) { | |
organization(login: $org) { | |
repositories(first: 100, privacy: PUBLIC, orderBy: {field: PUSHED_AT, direction: DESC}) { | |
nodes { | |
name | |
isArchived | |
pushedAt | |
} | |
} | |
} | |
}' -f org=$ORG_NAME | jq -c '.data.organization.repositories.nodes | map(select(.isArchived == false)) | map(.name)') | |
echo "repos=$repos" >> $GITHUB_ENV | |
- name: Collect Traffic Data | |
env: | |
GH_TOKEN: ${{ secrets.ADMIN_TOKEN }} | |
REPO_NAMES: ${{ env.repos }} | |
run: | | |
for repo in $(echo $REPO_NAMES | jq -r '.[]'); do | |
echo "Collecting traffic data for $repo" | |
python .github/scripts/collect_traffic.py "$repo" | |
done | |
- name: Commit and Push Changes | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add traffic-stats/ | |
if ! git diff-index --quiet HEAD --; then | |
git commit -m "chore: update traffic stats for $(date +%Y-%m-%d)" | |
git pull --rebase | |
git push | |
else | |
echo "No changes to commit" | |
fi |