Update Download Count on Release #3
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: Update Download Count | |
on: | |
schedule: | |
#- cron: '0 0 * * *' # Runs daily at midnight | |
- cron: '0 * * * *' # Runs every hour | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Fetch Release Data | |
id: fetch_release | |
run: | | |
release_data=$(curl -s https://api.github.com/repos/shupershuff/diablo2rloader/releases/latest) | |
echo "Fetched release data: $release_data" | |
#echo "release_data=${release_data}" >> $GITHUB_OUTPUT | |
- name: Calculate Download Count | |
id: calculate_downloads | |
run: | | |
echo "Release data JSON: ${{ steps.fetch_release.outputs.release_data }}" | |
download_count=$('${{ steps.fetch_release.outputs.release_data }}' | jq '[.assets[].download_count] | add') | |
if [ -z "$download_count" ]; then | |
#echo "No download count found, setting to 0" | |
download_count=0 | |
fi | |
echo "Download count: $download_count" | |
echo "::set-output name=download_count::${download_count}" | |
echo "download_count=$download_count" >> $GITHUB_OUTPUT | |
- name: Update JSON File | |
run: | | |
echo '{ | |
"schemaVersion": 1, | |
"label": "downloads", | |
"message": "'${{ steps.calculate_downloads.outputs.download_count }}'", | |
"color": "blue" | |
}' > download-count.json | |
git config --global user.name 'github-actions' | |
git config --global user.email 'github-actions@github.com' | |
git add download-count.json | |
git commit -m 'Update download count' | |
git push |