Skip to content

Update Download Count on Release #5

Update Download Count on Release

Update Download Count on Release #5

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 "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
- name: Commit and Push Changes
env:
TOKEN: ${{ secrets.ACTIONS_PUSH_TOKEN }}
run: |
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 https://$TOKEN@github.com/shupershuff/Diablo2RLoader.git HEAD:main