feat: bypass update resources in formatting cases (#11867)

This commit is contained in:
Constrat
2025-02-12 12:59:16 +01:00
committed by GitHub
parent 969220dd82
commit bebfaef7f9
4 changed files with 122 additions and 19 deletions

View File

@@ -124,10 +124,47 @@ jobs:
path: ./excel
compression-level: 0
original-json:
if: github.repository_owner == 'MaaAssistantArknights'
runs-on: ubuntu-latest
steps:
- name: Initializization
run: |
urls=(
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/.prettierrc|.prettierrc"
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/tools/TaskSorter/TaskSorter.py|TaskSorter.py"
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/resource/tasks.json|tasks.json"
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/resource/global/txwy/resource/tasks.json|original/txwy.json"
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/resource/global/YoStarEN/resource/tasks.json|original/YoStarEN.json"
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/resource/global/YoStarJP/resource/tasks.json|original/YoStarJP.json"
"https://raw.githubusercontent.com/MaaAssistantArknights/MaaAssistantArknights/refs/heads/${{ github.ref_name }}/resource/global/YoStarKR/resource/tasks.json|original/YoStarKR.json"
)
mkdir -p original
printf "%s\n" "${urls[@]}" | xargs -P 6 -I {} bash -c '
url=$(echo "{}" | cut -d"|" -f1)
filename=$(echo "{}" | cut -d"|" -f2)
curl -s -o "$filename" "$url" && echo "Downloaded $filename" || echo "Failed to download $filename" >&2
'
python3 TaskSorter.py --cn tasks.json --overseas EN:original/YoStarEN.json,JP:original/YoStarJP.json,KR:original/YoStarKR.json,TW:original/txwy.json
- name: Prettify original JSON
uses: Nerixyz/actionsx-prettier@v3-adj
with:
args: -w original/YoStarEN.json original/YoStarJP.json original/YoStarKR.json original/txwy.json
- name: Upload Original
uses: actions/upload-artifact@v4
with:
name: original
path: ./original
compression-level: 0
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]
# needs: [clone-resources-official, clone-resources-overseas, clone-resources-txwy, original-json]
if: github.repository_owner == 'MaaAssistantArknights'
runs-on: windows-latest
steps:
@@ -183,6 +220,13 @@ jobs:
./tools/ResourceUpdater/x64/Release/opencv_world4_maa.dll
./tools/ResourceUpdater/x64/Release/ResourceUpdater.exe
- name: Download original JSON
id: download-original
uses: actions/download-artifact@v4.1.8
with:
name: original
path: ./original
- name: Download txwy
id: download-txwy
uses: actions/download-artifact@v4.1.8
@@ -324,7 +368,7 @@ jobs:
github_token: ${{ secrets.MAA_RESOURCE_SYNC }}
- name: Update OTA resource
if: steps.add_files.outputs.have_commits == 'True'
if: steps.add_files.outputs.update_resources == 'True'
env:
GH_TOKEN: ${{ secrets.MAA_RESOURCE_SYNC }}
run: |

4
.gitignore vendored
View File

@@ -457,3 +457,7 @@ tools/RoguelikeRecruitmentTool/output
# MaaDeps
/MaaDeps/*
# ResourceUpdater workflow
/original/*

View File

@@ -1,8 +1,5 @@
Push-Location
# Stage changes otherwise git diff doesn't work
git add .
# Change to the root directory of the repository
Set-Location -Path (git rev-parse --show-toplevel)
@@ -13,6 +10,9 @@ Write-Output $gitStatus
Write-Output "-------------------------------------------------------------------------------------------"
# Stage changes otherwise git diff doesn't work
git add .
# Start to diff the file changes
Write-Output "Start to diff the file changes..."
$gitdiff = git diff --numstat HEAD 2>$null | findstr -i resource
@@ -108,10 +108,53 @@ foreach ($server in $listPerServer.Keys) {
Write-Output "-------------------------------------------------------------------------------------------"
}
$updateResources = $false
if (git diff --name-only HEAD 2>$null | Where-Object { $_ -notmatch 'tasks\.json$|version\.json$' }) {
Write-Output "Differences detected in other files, RUN UPDATE RESOURCES."
$updateResources = $true
}
else {
$taskFiles = @(
"resource/global/txwy/resource/tasks.json",
"resource/global/YoStarEN/resource/tasks.json",
"resource/global/YoStarJP/resource/tasks.json",
"resource/global/YoStarKR/resource/tasks.json"
)
$originalFiles = @(
"original/txwy.json",
"original/YoStarEN.json",
"original/YoStarJP.json",
"original/YoStarKR.json"
)
foreach ($i in 0..($taskFiles.Length - 1)) {
$taskFile = $taskFiles[$i]
$originalFile = $originalFiles[$i]
$taskJson = Get-Content -Path $taskFile
$originalJson = Get-Content -Path $originalFile
if (Compare-Object -ReferenceObject $taskJson -DifferenceObject $originalJson) {
Write-Output "Differences detected in $taskFile, RUN UPDATE RESOURCES."
$updateResources = $true
}
else {
Write-Output "No substantial changes in $taskFile."
}
}
}
if (Test-Path -Path "original") { Remove-Item "original" -Recurse -Force }
Write-Output "Diff check result:"
Write-Output "hasPngDiff: $hasPngDiff"
Write-Output "diff: $diff"
Write-Output "update: $updateResources"
Write-Output "contains_png=$hasPngDiff" >> $env:GITHUB_OUTPUT
Write-Output "changes=$diff" >> $env:GITHUB_OUTPUT
Write-Output "update_resources=$updateResources" >> $env:GITHUB_OUTPUT
Pop-Location

View File

@@ -1,10 +1,9 @@
import json
import re
import argparse
from pathlib import Path
def sort_tasks(res: dict[str, any]):
# 暂时只对 Roguelike 和 Reclamation 任务进行类字典序排序,其他任务保持原有相对顺序
classified_lists = {
"UseSupportUnit...": [],
"...@UseSupportUnit...": [],
@@ -53,26 +52,17 @@ def sort_tasks(res: dict[str, any]):
sorted(target_list)
for target_list in classified_lists.values()], [])}
if __name__ == '__main__':
resource_dir = Path(__file__).parents[2] / "resource"
cn_task_file = resource_dir / "tasks.json"
def main(cn_task_file, global_resources):
with open(cn_task_file, "r", encoding="utf8") as f:
cn_tasks = json.load(f)
cn_tasks = sort_tasks(cn_tasks)
order = list(cn_tasks.keys())
with open(cn_task_file, "w", encoding="utf8") as f:
with open(cn_task_file, "w", encoding="utf8", newline="\n") as f:
json.dump(cn_tasks, f, ensure_ascii=False, indent=4)
print("CN:", str(len(order)).rjust(4, " "), "tasks")
global_resources = {
"EN": resource_dir / "global/YoStarEN/resource/tasks.json",
"JP": resource_dir / "global/YoStarJP/resource/tasks.json",
"KR": resource_dir / "global/YoStarKR/resource/tasks.json",
"TW": resource_dir / "global/txwy/resource/tasks.json"
}
for server, path in global_resources.items():
with open(path, "r", encoding="utf8") as f:
tasks = json.load(f)
@@ -86,6 +76,28 @@ if __name__ == '__main__':
for k in sorted(tasks.keys(), key=lambda k: order.index(k) if k in order else -1)
}
with open(path, "w", encoding="utf8") as f:
with open(path, "w", encoding="utf8", newline="\n") as f:
json.dump(tasks, f, ensure_ascii=False, indent=4)
print(server + ":", str(len(tasks)).rjust(4, " "), "tasks")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Sort tasks in JSON files.")
parser.add_argument("--cn", type=str, help="Path to the CN tasks JSON file.")
parser.add_argument("--overseas", type=str, help="Comma-separated paths to the global tasks JSON files in the format 'EN:path,JP:path,KR:path,TW:path'.")
args = parser.parse_args()
resource_dir = Path(__file__).parents[2] / "resource"
cn_task_file = args.cn if args.cn else resource_dir / "tasks.json"
default_global_resources = {
"EN": resource_dir / "global/YoStarEN/resource/tasks.json",
"JP": resource_dir / "global/YoStarJP/resource/tasks.json",
"KR": resource_dir / "global/YoStarKR/resource/tasks.json",
"TW": resource_dir / "global/txwy/resource/tasks.json"
}
global_resources = default_global_resources
if args.overseas:
global_resources = {k: Path(v) for k, v in (item.split(':') for item in args.overseas.split(','))}
main(cn_task_file, global_resources)