Skip to content

Daily Metrics Saver #34

Daily Metrics Saver

Daily Metrics Saver #34

Workflow file for this run

name: Daily Metrics Saver
on:
schedule:
- cron: '0 3 * * *' # Gira ogni giorno alle 03:00 UTC
workflow_dispatch: # Permette l'avvio manuale con un click
concurrency:
group: daily-metrics-${{ github.repository }}
cancel-in-progress: false
permissions:
contents: write
env:
# Forza l'ambiente di esecuzione su Node.js 24 per prevenire i warning di deprecazione di giugno 2026
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
save-metrics:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Sync latest branch before metrics
run: git pull --rebase origin "${GITHUB_REF_NAME}"
- name: Fetch and Archive Quarterly Metrics
env:
GITHUB_TOKEN: ${{ secrets.METRICS_TOKEN }}
REPO_SLUG: ${{ github.repository }}
run: python scripts/archive_repository_metrics.py
- name: Commit & Push Changes
env:
BRANCH: ${{ github.ref_name }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action Bot"
git add metrics/
if git diff --quiet && git diff --staged --quiet; then
echo "No metric changes to commit."
exit 0
fi
git commit -m "chore(analytics): archive quarterly repository metrics [skip ci]"
max_attempts=5
for attempt in $(seq 1 "$max_attempts"); do
if git pull --rebase origin "$BRANCH" && git push origin "HEAD:${BRANCH}"; then
echo "Pushed metrics archive (attempt ${attempt})."
exit 0
fi
echo "Push failed (attempt ${attempt}/${max_attempts}), retrying after backoff..."
sleep $((attempt * 3))
done
echo "Failed to push metrics after ${max_attempts} attempts."
exit 1