name: Game Resource Update on: schedule: - cron: "*/20 * * * *" # Runs every 20 minutes workflow_dispatch: inputs: commit_message: description: "Commit Message" type: string required: false jobs: clone-resources-official: name: Download Official Resources if: github.repository_owner == 'MaaAssistantArknights' runs-on: ubuntu-latest steps: - name: Clone ArknightsGameResource for Official uses: actions/checkout@v6 with: show-progress: false repository: yuanyan3060/ArknightsGameResource ref: main path: ./Official sparse-checkout-cone-mode: false sparse-checkout: | /levels.json /item /building_skill /gamedata/excel/item_table.json /gamedata/excel/building_data.json /gamedata/excel/range_table.json /gamedata/excel/character_table.json /gamedata/excel/gacha_table.json /gamedata/excel/roguelike_topic_table.json /gamedata/excel/activity_table.json - name: Upload Official resources uses: actions/upload-artifact@v6 with: name: official path: ./Official compression-level: 0 clone-resources-overseas: name: Download Overseas Resources if: github.repository_owner == 'MaaAssistantArknights' runs-on: ubuntu-latest steps: - name: Clone ArknightsGameResource_Yostar for Overseas uses: actions/checkout@v6 with: show-progress: false repository: ArknightsAssets/ArknightsGamedata ref: master path: ./Overseas sparse-checkout-cone-mode: false sparse-checkout: | /en/gamedata/excel/item_table.json /en/gamedata/excel/building_data.json /en/gamedata/excel/range_table.json /en/gamedata/excel/character_table.json /en/gamedata/excel/gacha_table.json /en/gamedata/excel/roguelike_topic_table.json /en/gamedata/excel/activity_table.json /jp/gamedata/excel/item_table.json /jp/gamedata/excel/building_data.json /jp/gamedata/excel/range_table.json /jp/gamedata/excel/character_table.json /jp/gamedata/excel/gacha_table.json /jp/gamedata/excel/roguelike_topic_table.json /jp/gamedata/excel/activity_table.json /kr/gamedata/excel/item_table.json /kr/gamedata/excel/building_data.json /kr/gamedata/excel/range_table.json /kr/gamedata/excel/character_table.json /kr/gamedata/excel/gacha_table.json /kr/gamedata/excel/roguelike_topic_table.json /kr/gamedata/excel/activity_table.json - name: Upload Overseas resources uses: actions/upload-artifact@v6 with: name: overseas path: ./Overseas compression-level: 0 clone-resources-txwy: name: Download Taiwan Resources if: github.repository_owner == 'MaaAssistantArknights' runs-on: ubuntu-latest steps: - name: Clone arknights-toolbox-update for Taiwan uses: actions/checkout@v6 with: show-progress: false repository: arkntools/arknights-data-tw-for-maa ref: main path: ./excel - name: Download stages.json from Penguin Stats run: | cd "./excel" baseUrl="https://penguin-stats.io/PenguinStats/api/v2/stages?server=" parameters=("CN" "US" "JP" "KR") pids=() for param in "${parameters[@]}"; do { if curl -f -s -o "stages_${param}.json" "${baseUrl}${param}"; then echo "Successfully fetched data for ${param}" else echo "Failed to fetch data for ${param}" >&2 exit 1 fi } & pids+=($!) done failed=0 for pid in "${pids[@]}"; do if ! wait "$pid"; then failed=1 fi done if [ $failed -ne 0 ]; then echo "One or more downloads failed" >&2 exit 1 fi - name: Upload Taiwan resources uses: actions/upload-artifact@v6 with: name: txwy path: ./excel compression-level: 0 update-game-resources: name: Update Game Resources if: github.repository_owner == 'MaaAssistantArknights' runs-on: macos-latest steps: - name: Checkout repository uses: actions/checkout@v6 with: # TL;DR https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/9872#issuecomment-2251378371 # actions/checkout uses ${{ secrets.GITHUB_TOKEN }} by default, meaning all steps will inherit it persist-credentials: false # Needed to bypass protection rules in Push changes show-progress: false fetch-depth: 3 - name: Fetch submodules run: | git submodule update --init --depth 1 src/MaaUtils - name: Restore ResourceUpdater from cache id: resupd-cache uses: actions/cache/restore@v5 continue-on-error: true with: key: ResourceUpdater-${{ runner.os }}-${{ hashFiles('tools/ResourceUpdater/main.cpp') }} path: | ./tools/ResourceUpdater/libopencv_world4.4.11.0.dylib ./tools/ResourceUpdater/res_updater - name: Cache MaaDeps if: steps.resupd-cache.outputs.cache-hit != 'true' id: maadeps-cache uses: actions/cache@v5 continue-on-error: true with: path: | ./src/MaaUtils/MaaDeps key: ${{ runner.os }}-arm64-maadeps-${{ hashFiles('tools/maadeps-download.py') }} - name: Bootstrap MaaDeps if: steps.resupd-cache.outputs.cache-hit != 'true' && steps.maadeps-cache.outputs.cache-hit != 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | python3 tools/maadeps-download.py arm64-osx - name: Config, Build & Install ResourceUpdater if: steps.resupd-cache.outputs.cache-hit != 'true' run: | cd tools/ResourceUpdater cmake --preset res-updater-macos-arm64 cmake --build --preset res-updater-macos-arm64 --parallel $(sysctl -n hw.logicalcpu) cmake --install build --config Release - name: Save ResourceUpdater to cache if: always() && steps.resupd-cache.outputs.cache-hit != 'true' uses: actions/cache/save@v5 continue-on-error: true with: key: ResourceUpdater-${{ runner.os }}-${{ hashFiles('tools/ResourceUpdater/main.cpp') }} path: | ./tools/ResourceUpdater/libopencv_world4.4.11.0.dylib ./tools/ResourceUpdater/res_updater - name: Wait for resource cloning uses: yogeshlonkar/wait-for-jobs@v0 with: ignore-skipped: 'false' jobs: | Download Official Resources Download Overseas Resources Download Taiwan Resources ttl: 15 - name: Download txwy uses: actions/download-artifact@v7 with: name: txwy path: ./tools/ResourceUpdater/Overseas/tw/gamedata/excel - name: Download Overseas uses: actions/download-artifact@v7 with: name: overseas path: ./tools/ResourceUpdater/Overseas - name: Download Official uses: actions/download-artifact@v7 with: name: official path: ./tools/ResourceUpdater/Official - name: Update resources run: | ./tools/ResourceUpdater/res_updater - name: Sort tasks id: task_sorting run: | python3 tools/TaskSorter/TaskSorter.py echo "gitdiff=$(echo $(git diff --name-only --diff-filter=ACM 2>/dev/null | grep '\.json$'))" >> $GITHUB_OUTPUT - name: Run prettier uses: Nerixyz/actionsx-prettier@v3-adj with: args: -w ${{ steps.task_sorting.outputs.gitdiff }} - name: Update version.json date if necessary id: update_version run: | sh ./tools/ResourceUpdater/version.sh - name: Setup python if: steps.update_version.outputs.contains_png == 'True' uses: actions/setup-python@v6 with: python-version: "3.11" - name: Cache python packages if: always() && steps.update_version.outputs.contains_png == 'True' id: cache_python uses: actions/cache@v5 continue-on-error: true with: path: ${{ env.pythonLocation }}/Lib/site-packages key: ${{ runner.os }}-pip-optimize-templates-${{ hashFiles('./tools/OptimizeTemplates/requirements.txt') }} - name: Install dependencies if: steps.cache_python.outputs.cache-hit != 'true' && steps.update_version.outputs.contains_png == 'True' run: | pip install -r tools/OptimizeTemplates/requirements.txt - name: Setup oxipng if: steps.update_version.outputs.contains_png == 'True' uses: baptiste0928/cargo-install@v3 with: crate: oxipng - name: Optimize png images if: steps.update_version.outputs.contains_png == 'True' run: | python3 tools/OptimizeTemplates/optimize_templates.py --no-cleanup -p resource/template/items/ resource/template/infrast/ - name: Commit changes if: steps.update_version.outputs.changes == 'True' id: add_files run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add . commit_msg="${{ github.event.inputs.commit_message }}" if [ -z "$commit_msg" ]; then commit_msg="chore: Auto Update Game Resources - $(date '+%Y-%m-%d')" else commit_msg=$(echo "$commit_msg" | xargs) # Trim whitespace fi run_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" git commit -m "$commit_msg" -m "$run_url" -m "[skip changelog]" if [ $? -eq 0 ]; then echo "have_commits=True" >> $GITHUB_OUTPUT fi git pull origin ${{ github.ref_name }} --rebase - name: Push changes if: steps.add_files.outputs.have_commits == 'True' uses: ad-m/github-push-action@master with: branch: ${{ github.ref }} github_token: ${{ secrets.MAA_RESOURCE_SYNC }} # - name: Update OTA resource # if: steps.update_version.outputs.update_resources == 'True' # env: # GH_TOKEN: ${{ secrets.MISTEOWORKFLOW }} # run: | # gh workflow --repo MaaAssistantArknights/MaaRelease run update-resource.yml - name: Add cancelled status if: steps.update_version.outputs.changes != 'True' || steps.add_files.outputs.have_commits != 'True' uses: andymckay/cancel-action@0.5 # - name: Release # ref: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow # if: steps.add_files.outputs.have_commits == 'True' # run: | # gh workflow run release-nightly-ota.yml -f release_body="Auto Release of Resource Updates" - name: Upsert failure comment (single active) if: failure() && github.ref == 'refs/heads/dev' run: | run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" latest_id=$(gh api --paginate repos/${{ github.repository }}/issues/14493/comments | jq -r '.[] | select(.user.login=="github-actions[bot]") | .id' | tail -n 1) if [ -n "$latest_id" ]; then body=$(gh api repos/${{ github.repository }}/issues/comments/$latest_id --jq '.body') if echo "$body" | grep -q '/actions/runs/'; then # Count existing run URLs count=$(echo "$body" | grep -o 'https://github.com/[^[:space:]]*' | wc -l) # Collapse existing content old_content=$(echo "$body" | sed 's|https://github.com/[^[:space:]]*|
\n⚠️ Previous failures ('"$count"')\n\n###### &\n\n
|g') new_body="$run_url @MistEO @ABA2396 @Constrat $old_content" gh api repos/${{ github.repository }}/issues/comments/$latest_id -X PATCH -f body="$new_body" || echo "Patch failed" exit 0 fi fi # Create new failure comment if none suitable gh issue comment 14493 -R ${{ github.repository }} --body "$run_url @MistEO @ABA2396 @Constrat" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Minimize failure comment on success/cancelled if: ${{ !failure() && github.ref == 'refs/heads/dev' }} run: | latest_node=$(gh api --paginate repos/${{ github.repository }}/issues/14493/comments | jq -r '.[] | select(.user.login=="github-actions[bot]") | .node_id' | tail -n 1) if [ -n "$latest_node" ]; then gh api graphql -f query='mutation { minimizeComment(input: {subjectId: "'"$latest_node"'", classifier: OUTDATED}) { minimizedComment { isMinimized } } }' || true fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}