Update Download Count on Release #43
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 Release | |
on: | |
#schedule: | |
# - cron: '0 * * * *' # Runs every Day | |
workflow_dispatch: # Allows manual triggering | |
release: | |
types: [published] # when a new release is made | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Fetch Download Count | |
id: fetch_downloads | |
run: | | |
#release_data=$(curl -s https://api.github.com/repos/shupershuff/diablo2rloader/releases/latest) # Latest Release | |
releases=$(curl -s https://api.github.com/repos/shupershuff/diablo2rloader/releases) | |
release_data=$(echo "$releases" | jq '.[1]') # Select the second release # Get Previous release details | |
download_count=$(echo "$release_data" | jq '[.assets[].download_count] | add') | |
echo "$download_count" | |
echo "download_count=$download_count" >> $GITHUB_OUTPUT | |
- name: Update JSON File | |
run: | | |
echo '{ | |
"schemaVersion": 1, | |
"label": "Downloads", | |
"message": "'${{ steps.fetch_downloads.outputs.download_count }}'", | |
"color": "blue" | |
}' > .github/previous-release-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 .github/previous-release-download-count.json | |
git diff --cached --exit-code || git commit -m 'Update download count' || echo "No changes to commit" | |
git push https://$TOKEN@github.com/shupershuff/Diablo2RLoader.git HEAD:main || echo "No changes to push" |