-
-
Notifications
You must be signed in to change notification settings - Fork 11
91 lines (74 loc) · 3.66 KB
/
GetDownloadCount.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Update Download Count on Release
on:
schedule:
- cron: '0 0 * * 0' # Runs once a week at midnight.
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: |
# Fetch the releases
releases=$(curl -s https://api.github.com/repos/shupershuff/diablo2rloader/releases)
# Debug: Print raw JSON to check the response
#echo "Raw releases data:"
#echo "$releases" | tee releases.json # Also output to a file for inspection
# Validate JSON format and check for errors
if ! echo "$releases" | jq empty > /dev/null 2>&1; then
echo "Error: Invalid JSON response."
exit 1
fi
# Initialize variables for max downloads
max_download_count=0
release_with_max_downloads=""
# Convert JSON to a simpler format for iteration
releases_info=$(echo "$releases" | jq -r '.[] | "\(.tag_name) \(.assets[].download_count // 0)"')
# Iterate through each release information
while IFS= read -r line; do
release_name=$(echo "$line" | awk '{print $1}')
download_count=$(echo "$line" | awk '{print $2}')
# Convert download_count to integer
download_count=${download_count:-0} # Default to 0 if empty
# Log the release name and download count for debugging
echo "Release: $release_name, Download Count: $download_count"
# Update the max_download_count and release_with_max_downloads if applicable
if [ "$download_count" -gt "$max_download_count" ]; then
max_download_count=$download_count
release_with_max_downloads=$release_name
echo "New max downloads: $max_download_count for release: $release_with_max_downloads"
fi
done <<< "$releases_info"
# Log the final result for debugging
echo "Final Max downloads: $max_download_count for release: $release_with_max_downloads"
# Assign to GitHub output
echo "download_count=$max_download_count" >> $GITHUB_OUTPUT
echo "release_with_max_downloads=$release_with_max_downloads" >> $GITHUB_OUTPUT
- name: Update JSON File
run: |
# Ensure the release version and download count are available
if [ -z "${{ steps.fetch_downloads.outputs.release_with_max_downloads }}" ] || [ -z "${{ steps.fetch_downloads.outputs.download_count }}" ]; then
echo "Error: Missing release version or download count."
exit 1
fi
# Create the JSON content with version and download count
echo '{
"schemaVersion": 1,
"label":"'${{ steps.fetch_downloads.outputs.release_with_max_downloads }}'",
"message":"'${{ steps.fetch_downloads.outputs.download_count }}'",
"color": "blue"
}' > .github/max-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/max-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"