Skip to content

Calculate Usage

Calculate Usage #133

# .github/workflows/calculate-public-usage.yml
name: Calculate Usage
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
count_repos:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: stats
persist-credentials: true
- name: Count unique repos referencing JF_URL
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Capture current date in YYYY-MM-DD (UTC)
current_date=$(date -u +%Y-%m-%d)
# Run the GitHub Code Search API, extract repo names, dedupe, and count
count=$(
curl -sSL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/search/code?q=artifacts-artefacts.devops.cloud-nuage.canada.ca" \
| jq -r '.items[].repository.full_name' \
| sort -u \
| wc -l
)
echo "Date: $current_date"
echo "Unique repos found: $count"
# Ensure data directory exists
mkdir -p stats
# Define the CSV file path
file="stats/usage.csv"
# If the file doesn't exist, add a header
if [ ! -f "$file" ]; then
echo "date,count" > "$file"
fi
# Append today's date and the count
echo "$current_date,$count" >> "$file"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install plotting dependencies
run: |
pip install pandas matplotlib
- name: Generate XKCD-style usage graph
run: |
python3 scripts/generate_graph.py
- name: Commit and push updated data file + graph
run: |
# Configure git author
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Stage CSV and PNG
git add stats/usage.csv stats/usage.png
# Commit changes if there are any
git commit -m "Add usage for $(date -u +%Y-%m-%d): ${{ steps.count_repos.outputs.count }}" || echo "No changes to commit"
# Push back to the default branch
git push