mirror of
https://github.com/LukeHagar/usage-statistics.git
synced 2025-12-06 04:21:55 +00:00
67 lines
2.1 KiB
YAML
67 lines
2.1 KiB
YAML
name: Update Usage Statistics
|
|
|
|
on:
|
|
schedule:
|
|
# Run daily at 2 AM UTC
|
|
- cron: '0 2 * * *'
|
|
workflow_dispatch:
|
|
# Allow manual triggering
|
|
|
|
jobs:
|
|
update-stats:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@v1
|
|
with:
|
|
bun-version: latest
|
|
|
|
- name: Install dependencies
|
|
run: bun install
|
|
|
|
- name: Run usage statistics tracker
|
|
run: bun run src/index.ts --action
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GITHUB_ACTIONS: true
|
|
NODE_ENV: production
|
|
|
|
- name: Check for changes
|
|
id: check-changes
|
|
run: |
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
echo "changes=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "changes=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Commit and push changes
|
|
if: steps.check-changes.outputs.changes == 'true'
|
|
run: |
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add stats.json README.md
|
|
git commit -m "chore: update usage statistics [skip ci]" || echo "No changes to commit"
|
|
git push
|
|
|
|
- name: Create summary
|
|
run: |
|
|
if [ -f "stats.json" ]; then
|
|
echo "## 📊 Usage Statistics Updated" >> $GITHUB_STEP_SUMMARY
|
|
echo "Stats have been updated and committed to the repository." >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "### Summary:" >> $GITHUB_STEP_SUMMARY
|
|
cat stats.json | jq -r '.totalDownloads, .uniquePackages, (.platforms | join(", "))' | while read line; do
|
|
echo "- $line" >> $GITHUB_STEP_SUMMARY
|
|
done
|
|
else
|
|
echo "## ❌ No stats file generated" >> $GITHUB_STEP_SUMMARY
|
|
echo "The stats.json file was not created. Check the logs for errors." >> $GITHUB_STEP_SUMMARY
|
|
fi |