Files
MaaAssistantArknights/.github/workflows/res-update-game.yml
MistEO bcf93aeeca refactor: 集成 MaaUtils (#14578)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-31 14:56:56 +08:00

384 lines
13 KiB
YAML

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@v5
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@v5
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@v5
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@v5
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@v5
with:
show-progress: false
repository: arkntools/arknights-toolbox-update
ref: data-tw
path: ./excel
token: ${{ secrets.ARKNTOOLS_MAA_RESOURCE_UPDATER}}
- 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")
for param in "${parameters[@]}"; do
{
if curl -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
} &
done
wait
- name: Upload Taiwan resources
uses: actions/upload-artifact@v5
with:
name: txwy
path: ./excel
compression-level: 0
update-game-resources:
name: Update Game Resources
# In case of rate limitations on the runners/instances, add dependency, by removing the comment
# needs: [clone-resources-official, clone-resources-overseas, clone-resources-txwy]
if: github.repository_owner == 'MaaAssistantArknights'
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
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@v4
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@v4
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 cmake
if: steps.resupd-cache.outputs.cache-hit != 'true'
run: |
cd tools/ResourceUpdater
mkdir -p build
cmake -B build -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DMAADEPS_TRIPLET='maa-arm64-osx' \
-DWITH_HASH_VERSION=ON
- name: Build
if: steps.resupd-cache.outputs.cache-hit != 'true'
run: |
cmake --build tools/ResourceUpdater/build --config Release --parallel $(sysctl -n hw.logicalcpu)
- name: Install
if: steps.resupd-cache.outputs.cache-hit != 'true'
run: |
cmake --install tools/ResourceUpdater/build --prefix tools/ResourceUpdater --config Release
- name: Save ResourceUpdater to cache
if: always() && steps.resupd-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
key: ResourceUpdater-${{ runner.os }}-${{ hashFiles('tools/ResourceUpdater/main.cpp') }}
path: |
./tools/ResourceUpdater/libopencv_world4.4.11.0.dylib
./tools/ResourceUpdater/res_updater
- name: Download txwy
id: download-txwy
uses: actions/download-artifact@v6
continue-on-error: true
with:
name: txwy
path: ./tools/ResourceUpdater/Overseas/tw/gamedata/excel
- name: Delay for txwy
if: steps.download-txwy.outcome == 'failure'
run: |
sleep 30
- name: Re-download txwy
if: steps.download-txwy.outcome == 'failure'
uses: actions/download-artifact@v6
with:
name: txwy
path: ./tools/ResourceUpdater/Overseas/tw/gamedata/excel
- name: Download Overseas
id: download-overseas
uses: actions/download-artifact@v6
continue-on-error: true
with:
name: overseas
path: ./tools/ResourceUpdater/Overseas
- name: Delay for Overseas
if: steps.download-overseas.outcome == 'failure'
run: |
sleep 30
- name: Re-download Overseas
if: steps.download-overseas.outcome == 'failure'
uses: actions/download-artifact@v6
with:
name: overseas
path: ./tools/ResourceUpdater/Overseas
- name: Download Official
id: download-official
uses: actions/download-artifact@v6
continue-on-error: true
with:
name: official
path: ./tools/ResourceUpdater/Official
- name: Delay for Official
if: steps.download-official.outcome == 'failure'
run: |
sleep 30
- name: Re-download Official
if: steps.download-official.outcome == 'failure'
uses: actions/download-artifact@v6
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@v4
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 -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: Comment on issue if failed
if: failure() && github.ref == 'refs/heads/dev'
run: |
# Minimize old failure comments
comments=$(gh api repos/${{ github.repository }}/issues/14493/comments --jq '.[] | select(.user.login == "github-actions[bot]") | select(.body | contains("${{ github.server_url }}/${{ github.repository }}/actions/runs/")) | .node_id')
for node_id in $comments; do
gh api graphql -f query='
mutation {
minimizeComment(input: {subjectId: "'"$node_id"'", classifier: OUTDATED}) {
minimizedComment {
isMinimized
}
}
}'
done
# Add new failure comment
gh issue comment 14493 -R ${{ github.repository }} --body "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
@MistEO @ABA2396 @Constrat"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}