JP loadingbg sync (state-cache, azl v4) #36
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
| name: JP loadingbg sync (state-cache, azl v4) | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install azlassets (v4.x) | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install "azlassets==4.0.0" | |
| azl --help | |
| # ============================= | |
| # 恢复 azlassets state cache(非常小) | |
| # ============================= | |
| - name: Restore azlassets state cache (if exists) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| API="https://api.github.com/repos/${{ github.repository }}/releases/tags/jp-loadingbg-latest" | |
| if curl -fsSL -H "Authorization: token $GITHUB_TOKEN" "$API" > release.json; then | |
| STATE_URL=$(jq -r '.assets[] | select(.name=="jp-client-state.tar") | .browser_download_url' release.json) | |
| if [ -n "$STATE_URL" ] && [ "$STATE_URL" != "null" ]; then | |
| echo "Restoring azlassets state cache..." | |
| curl -L -o jp-client-state.tar "$STATE_URL" | |
| tar -xf jp-client-state.tar | |
| else | |
| echo "No state cache found, cold-ish start." | |
| fi | |
| fi | |
| - name: Download JP assets (azl v4.0.0 with runtime patch) | |
| run: | | |
| python - <<'PY' | |
| import sys | |
| import azl | |
| import azlassets.classes as cls | |
| import azlassets.updater as updater | |
| # Patch 1: VersionType hash (原有) | |
| VT = getattr(cls, "VersionType", None) | |
| if VT is None: | |
| print("[patch] VersionType not found in azlassets.classes; continuing anyway.") | |
| else: | |
| if getattr(VT, "__hash__", None) is None: | |
| VT.__hash__ = lambda self: hash(str(self)) | |
| print("[patch] Patched VersionType.__hash__ to hash(str(self))") | |
| else: | |
| print("[patch] VersionType.__hash__ already present:", VT.__hash__) | |
| # Patch 2: remove_asset 支持目录删除(修复 IsADirectoryError) | |
| _orig_remove_asset = updater.remove_asset | |
| def _patched_remove_asset(assetpath): | |
| import pathlib | |
| p = pathlib.Path(assetpath.full) | |
| if p.is_dir(): | |
| import shutil | |
| shutil.rmtree(p) | |
| print(f"[patch] Removed directory: {assetpath.full}") | |
| else: | |
| _orig_remove_asset(assetpath) | |
| updater.remove_asset = _patched_remove_asset | |
| print("[patch] Patched updater.remove_asset to handle directories") | |
| # 让 azl 按 CLI 方式运行 download JP | |
| sys.argv = ["azl", "download", "JP"] | |
| azl.main() | |
| PY | |
| # ============================= | |
| # 恢复上次 loadingbg_full.zip → last_loadingbg(用于 diff) | |
| # ============================= | |
| - name: Restore last loadingbg snapshot (if exists) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| API="https://api.github.com/repos/${{ github.repository }}/releases/tags/jp-loadingbg-latest" | |
| if curl -fsSL -H "Authorization: token $GITHUB_TOKEN" "$API" > release.json; then | |
| FULL_URL=$(jq -r '.assets[] | select(.name=="loadingbg_full.zip") | .browser_download_url' release.json) | |
| if [ -n "$FULL_URL" ] && [ "$FULL_URL" != "null" ]; then | |
| curl -L -o loadingbg_full.zip "$FULL_URL" | |
| unzip -q loadingbg_full.zip | |
| if [ -d "last_loadingbg" ]; then | |
| rm -rf last_loadingbg | |
| fi | |
| mv current_loadingbg last_loadingbg | |
| fi | |
| fi | |
| # ============================= | |
| # 收集本次 loadingbg(若没更新可能不存在) | |
| # ============================= | |
| - name: Collect loadingbg | |
| run: | | |
| python scripts/collect_loadingbg.py | |
| # ============================= | |
| # diff + zip(你已修过:无 current_loadingbg 也能正常结束) | |
| # ============================= | |
| - name: Diff and zip | |
| run: | | |
| bash scripts/diff_and_zip.sh | |
| - name: Read diff status | |
| id: diffcheck | |
| run: | | |
| echo "has_diff=$(cat has_diff.flag)" >> $GITHUB_OUTPUT | |
| - name: Generate meta info | |
| run: | | |
| echo "client=JP" > meta.txt | |
| echo "generated_at=$(date -u)" >> meta.txt | |
| echo "has_diff=${{ steps.diffcheck.outputs.has_diff }}" >> meta.txt | |
| # ============================= | |
| # 打包 state cache(只保留逻辑状态,不含 AssetBundles) | |
| # ============================= | |
| - name: Pack azlassets client state | |
| run: | | |
| rm -rf state_tmp | |
| mkdir -p state_tmp/ClientAssets | |
| # 仅当 ClientAssets/JP 存在时才打包(防首次/异常) | |
| if [ -d "ClientAssets/JP" ]; then | |
| cp -r ClientAssets/JP state_tmp/ClientAssets/ | |
| rm -rf state_tmp/ClientAssets/JP/AssetBundles || true | |
| fi | |
| tar -cf jp-client-state.tar -C state_tmp ClientAssets | |
| # ============================= | |
| # 发布 Release | |
| # ============================= | |
| - name: Publish Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: jp-loadingbg-latest | |
| name: JP loadingbg latest | |
| body: | | |
| JP loadingbg sync (azlassets v4, state-cache). | |
| - jp-client-state.tar : azlassets logical state (safe cache) | |
| - loadingbg_full.zip : latest full snapshot | |
| - loadingbg_diff.zip : only when updated | |
| files: | | |
| jp-client-state.tar | |
| loadingbg_full.zip | |
| meta.txt | |
| ${{ steps.diffcheck.outputs.has_diff == 'true' && 'loadingbg_diff.zip' || '' }} |