Auto Cache Software Release JSONs #3831
This file contains hidden or 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
| # | |
| # 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@v6 | |
| - 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@v3 | |
| 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' |