Nightly Snapshot of Release Download Statistics #16
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: Nightly Snapshot of Release Download Statistics | |
on: | |
schedule: | |
- cron: '0 1 * * *' # Runs every day at 1:00 AM (UTC) | |
workflow_dispatch: # Allows manual triggering | |
permissions: | |
contents: write # Ensure write permissions | |
jobs: | |
collect-stats: | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Checkout the repository with GitHub token for authentication | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 # Fetch full history | |
# 2. Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
# 3. Install required Python dependencies | |
- name: Install dependencies | |
run: | | |
pip install requests pandas | |
# 4. Create stats directory (if it doesn't exist) | |
- name: Create stats directory | |
run: mkdir -p stats | |
# 5. Check if "release_stats" branch exists and create if necessary | |
- name: Check if release_stats branch exists | |
run: | | |
git fetch origin | |
if git show-ref --verify --quiet refs/heads/release_stats; then | |
echo "Branch release_stats exists." | |
else | |
echo "Branch release_stats does not exist. Creating branch." | |
git checkout -b release_stats | |
git push origin release_stats | |
# 6. Checkout the "release_stats" branch | |
- name: Checkout "release_stats" branch | |
run: git checkout release_stats | |
# 7. Run the Python script to fetch and append download stats | |
- name: Run Python script to fetch and append download stats | |
run: python .github/scripts/fetch_and_append_stats.py | |
# 8. Configure Git for committing | |
- name: Configure Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "SapMachine Github Actions Bot" | |
# 9. Commit and push changes to the "release_stats" branch | |
- name: Commit and push changes | |
run: | | |
git add stats/release_stats*.csv | |
git commit -m "Add nightly snapshot for $(date +'%Y-%m-%d %H:%M:%S')" || echo "No changes to commit" | |
git push origin release_stats || { echo "Push failed, please check the logs"; exit 1; } |