-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathAuto cache software release jsons.yml
More file actions
152 lines (127 loc) · 4.95 KB
/
Auto cache software release jsons.yml
File metadata and controls
152 lines (127 loc) · 4.95 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#
# Copyright (c) 2025-2026 LWB1978 <https://github.com/lwb1978>
# Description: Auto Cache Software Release JSONs
#
name: Auto Cache Software Release JSONs
on:
schedule:
- cron: '0 */2 * * *'
workflow_dispatch:
env:
TZ: Asia/Shanghai
permissions:
contents: write
actions: write
jobs:
cache_json:
outputs:
must_upload: ${{ steps.fetch.outputs.must_upload }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Initialization environment
run: |
sudo timedatectl set-timezone "$TZ"
- name: Install GitHub CLI
run: sudo apt-get update && sudo apt-get install -y gh
- name: Fetch GitHub release JSONs
id: fetch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p output old_json
MUST_UPLOAD=false
declare -A repos
repos["geoview"]="snowie2000/geoview"
repos["chinadns-ng"]="zfl9/chinadns-ng"
repos["xray"]="XTLS/Xray-core"
repos["sing-box"]="SagerNet/sing-box"
repos["hysteria"]="HyNetwork/hysteria"
echo "Downloading previous api-cache release assets (if exists)..."
gh release download api-cache --dir old_json --pattern "*.json" || echo "No previous release found"
for name in "${!repos[@]}"; do
repo="${repos[$name]}"
echo "Processing $name from $repo ..."
for t in release pre-release; do
old="old_json/${name}-${t}-api.json"
if [ -f "$old" ]; then
cp "$old" "output/${name}-${t}-api.json.bak"
else
echo "⚠️ Missing old file: $old"
MUST_UPLOAD=true
fi
done
curl -sL "https://api.github.com/repos/$repo/releases/latest" -o "output/${name}-release-api.json"
curl -sL "https://api.github.com/repos/$repo/releases?per_page=1" -o "output/${name}-pre-release-api.json"
for t in release pre-release; do
file="output/${name}-${t}-api.json"
TAG_NAME=$(grep -oP '"tag_name": "\K[^"]+' "$file" || true)
if [ -z "$TAG_NAME" ]; then
echo "❌ ${file} No tag_name, restore old files..."
rm -f "$file"
if [ -f "${file}.bak" ]; then
mv "${file}.bak" "$file"
fi
else
if [ -f "${file}.bak" ]; then
OLD_TAG=$(grep -oP '"tag_name": "\K[^"]+' "${file}.bak" || true)
if [ "$OLD_TAG" != "$TAG_NAME" ]; then
echo "🔄 Version changed: $OLD_TAG → $TAG_NAME"
MUST_UPLOAD=true
else
echo "✔ Version unchanged: $TAG_NAME"
fi
fi
rm -f "${file}.bak"
fi
done
done
if [ -z "$(ls -A output 2>/dev/null)" ]; then
echo "⚠️ output directory is empty, force MUST_UPLOAD=false"
MUST_UPLOAD=false
fi
echo "MUST_UPLOAD=$MUST_UPLOAD"
echo "must_upload=$MUST_UPLOAD" >> $GITHUB_OUTPUT
- name: Check if upload is required
id: check_upload
run: |
if [ "${{ steps.fetch.outputs.must_upload }}" = "true" ]; then
echo "upload=true" >> $GITHUB_OUTPUT
echo "🚀 Upload required."
else
echo "upload=false" >> $GITHUB_OUTPUT
echo "✔ No changes detected, skip release."
fi
- name: Delete old release and tag
if: steps.check_upload.outputs.upload == 'true'
run: |
gh release delete api-cache --cleanup-tag -y || echo "No existing release to delete."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Wait a sec
run: sleep 3
- name: Upload to release
if: steps.check_upload.outputs.upload == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: api-cache
name: Software Release API Cache
files: output/*.json
draft: false
prerelease: true
body: |
This release contains cached GitHub Release API JSON data for several software projects.
It is used by the PassWall (and PassWall2) update component to reduce reliance on GitHub's rate-limited API (60 requests per IP per hour).
**Please do not download it – it is of no use to you.**
**请不要下载它,因为它对你没有任何用处。**
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@main
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 0
keep_minimum_runs: 5
delete_workflow_pattern: 'Auto Cache Software Release JSONs'