-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (85 loc) · 2.91 KB
/
org-traffic-collector.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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:
discover-repos:
runs-on: ubuntu-latest
outputs:
repo_matrix: ${{ steps.list-repos.outputs.repos }}
steps:
- name: List Organization Repositories
id: list-repos
env:
GH_TOKEN: ${{ secrets.ADMIN_TOKEN }}
ORG_NAME: CCP-NC
run: |
# Get all repos in the organization
repos=$(gh api graphql -f query='
query($org: String!) {
organization(login: $org) {
repositories(first: 100, privacy: PUBLIC) {
nodes {
name
isArchived
}
}
}
}' -f org=$ORG_NAME | jq -c '.data.organization.repositories.nodes | map(select(.isArchived == false)) | map(.name)')
echo "repos=${repos}" >> $GITHUB_OUTPUT
collect-traffic:
needs: discover-repos
runs-on: ubuntu-latest
strategy:
matrix:
repository: ${{ fromJson(needs.discover-repos.outputs.repo_matrix) }}
# Allow other repos to continue if one fails
fail-fast: false
# Limit parallel jobs to avoid API rate limits
max-parallel: 1
steps:
- name: Checkout Metrics Repository
uses: actions/checkout@v4
with:
repository: CCP-NC/metrics # Check out the metrics repo
token: ${{ secrets.ADMIN_TOKEN }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Collect Traffic Data
env:
GH_TOKEN: ${{ secrets.ADMIN_TOKEN }}
REPO_NAME: ${{ matrix.repository }}
run: |
python .github/scripts/collect_traffic.py ${{ matrix.repository }} || echo "Data collection failed for ${{ matrix.repository }}"
- 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 $(date +%Y-%m-%d)"
git pull --rebase
git push
else
echo "No changes to commit"
fi