-
Notifications
You must be signed in to change notification settings - Fork 7
120 lines (106 loc) · 5.14 KB
/
fetch_latest_release_info.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Fetch Latest GitHub Release Info
on:
repository_dispatch:
push:
branches:
- 'master'
paths:
- '.github/workflows/fetch_latest_release_info.yml'
pull_request:
branches:
- 'master'
paths:
- '.github/workflows/fetch_latest_release_info.yml'
jobs:
build:
concurrency: fetch-latest-release-info
name: 'Fetch Latest GitHub Release Info'
runs-on: ubuntu-latest
if: (github.event_name == 'repository_dispatch' && github.event.action == 'github_release_update') || github.event_name != 'repository_dispatch'
steps:
- uses: actions/checkout@v4
with:
ref: master
persist-credentials: false
- name: Download latest GitHub Release info
uses: past-due/fetch-release-info@master
with:
github_repo: 'Warzone2100/warzone2100'
github_token: '${{ secrets.GITHUB_TOKEN }}'
calculate_asset_info: true
output_directory: 'data/github_releases_info'
cache_directory: '_tmp_cache_data/github_releases_info'
- name: Install mktorrent
run: |
sudo apt-get update -y
sudo apt-get install -y mktorrent
- name: Generate .torrent files for latest release assets
id: generate-torrent
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tmp_dl_path="${HOME}/release_assets"
if [ ! -d "${tmp_dl_path}" ]; then
mkdir -p "${tmp_dl_path}"
fi
tag_name="$(cat "data/github_releases_info/latest.json" | jq -r '.tag_name')"
torrent_output_dir="static/download/wz"
if [ ! -d "${torrent_output_dir}" ]; then
mkdir -p "${torrent_output_dir}"
fi
cat "data/github_releases_info/latest.json" | jq -r '.assets[] | [.name, .url, .browser_download_url] | @tsv' |
while IFS=$'\t' read -r github_release_asset_name github_release_asset_url github_release_asset_browser_download_url; do
echo "********************************************"
echo "* [${github_release_asset_name}]"
echo "********************************************"
# Explicitly ignore release assets with "DEBUGSYMBOLS" in name
if [[ "${github_release_asset_name}" == *DEBUGSYMBOLS* ]]; then
echo "Skipping .torrent generation for release asset: ${github_release_asset_name} (reason: DEBUGSYMBOLS)"
continue
fi
asset_dl_path="${tmp_dl_path}/${github_release_asset_name}"
# Download release asset from GitHub
curl -H "Accept: application/octet-stream" -H "Authorization: token ${GITHUB_TOKEN}" -Lf -o "${asset_dl_path}" "${github_release_asset_url}"
CURL_RETURN_CODE=$?
if [ "${CURL_RETURN_CODE}" -ne 0 ]; then
echo "curl failed for: ${github_release_asset_name}"
continue
fi
# Get filesize in kb
filesize_in_kb=$(du -k "${asset_dl_path}" | cut -f1)
if [ "${filesize_in_kb}" -lt 25000 ]; then
# Ignore smaller release assets
echo "Skipping .torrent generation for release asset: ${github_release_asset_name} (reason: too small)"
rm "${asset_dl_path}"
continue
fi
# Calculate SourceForge alternative download URL
sf_webseed_url="https://downloads.sourceforge.net/project/warzone2100/releases/${tag_name}/${github_release_asset_name}"
echo "sf_webseed_url=${sf_webseed_url}"
# Generate torrent name
prefix="warzone2100_"
torrent_name=${github_release_asset_name#"$prefix"}
torrent_name="${prefix}${tag_name}_${torrent_name}"
echo "torrent_name=${torrent_name}"
torrent_output_file="${torrent_output_dir}/${github_release_asset_name}.torrent"
# Clear any old .torrent file by this name
if [ -f "${torrent_output_file}" ]; then
rm "${torrent_output_file}"
fi
# Generate .torrent file
env -u GITHUB_TOKEN mktorrent -v -a http://tracker.opentrackr.org:1337/announce -c "${github_release_asset_name} (${tag_name})" -n "${torrent_name}" --no-date -w "${github_release_asset_browser_download_url}" -w "${sf_webseed_url}" -o "${torrent_output_file}" "${asset_dl_path}"
# Remove the downloaded asset
rm "${asset_dl_path}"
done
- name: Commit any changes to data files
if: github.event_name == 'repository_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/master'))
env:
PUSH_PAT: ${{ secrets.WZ2100_PUSH_SECRET_TOKEN }} # use a PAT so that subsequent workflows are triggered on push
run: |
git config user.name "wzdev-ci"
git config user.email "[email protected]"
git add -A
timestamp=$(date -u)
git commit -m "Automated update of GitHub Releases data: ${timestamp}" || exit 0
git pull --rebase
git push "https://${PUSH_PAT}@github.com/Warzone2100/wz2100.net.git" master:master