mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
feat: script to update version.json (#11875)
* chore: do not modify version.json time in cpp * feat: add version time updater script * chore: add version.ps1 to workflow * feat: implement previous logic from validator.ps1 * feat: add version bool for update-resources * fix: wrong condition on OTA step
This commit is contained in:
22
.github/workflows/res-update-game.yml
vendored
22
.github/workflows/res-update-game.yml
vendored
@@ -302,18 +302,18 @@ jobs:
|
||||
with:
|
||||
args: -w ${{ steps.task_sorting.outputs.gitdiff }}
|
||||
|
||||
- name: Check if only sorted and Templates
|
||||
id: check_sorted_templates
|
||||
run: pwsh tools/ResourceUpdater/validator.ps1
|
||||
- name: Update version.json date if necessary
|
||||
id: update_version
|
||||
run: pwsh tools/ResourceUpdater/version.ps1
|
||||
|
||||
- name: Setup python
|
||||
if: steps.check_sorted_templates.outputs.contains_png == 'True'
|
||||
if: steps.update_version.outputs.contains_png == 'True'
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Cache Python packages
|
||||
if: always() && steps.check_sorted_templates.outputs.contains_png == 'True'
|
||||
if: always() && steps.update_version.outputs.contains_png == 'True'
|
||||
id: cache_python
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -321,23 +321,23 @@ jobs:
|
||||
key: ${{ runner.os }}-pip-optimize-templates-${{ hashFiles('./tools/OptimizeTemplates/requirements.txt') }}
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.cache_python.outputs.cache-hit != 'true' && steps.check_sorted_templates.outputs.contains_png == 'True'
|
||||
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.check_sorted_templates.outputs.contains_png == 'True'
|
||||
if: steps.update_version.outputs.contains_png == 'True'
|
||||
uses: baptiste0928/cargo-install@v3
|
||||
with:
|
||||
crate: oxipng
|
||||
|
||||
- name: Run optimize_templates
|
||||
if: steps.check_sorted_templates.outputs.contains_png == 'True'
|
||||
if: steps.update_version.outputs.contains_png == 'True'
|
||||
run: |
|
||||
python3 tools/OptimizeTemplates/optimize_templates.py -p resource/template/items/ resource/template/infrast/
|
||||
|
||||
- name: Add files to git
|
||||
if: steps.check_sorted_templates.outputs.changes == 'True'
|
||||
if: steps.update_version.outputs.changes == 'True'
|
||||
id: add_files
|
||||
run: |
|
||||
git config user.name "github-actions[bot]"
|
||||
@@ -368,7 +368,7 @@ jobs:
|
||||
github_token: ${{ secrets.MAA_RESOURCE_SYNC }}
|
||||
|
||||
- name: Update OTA resource
|
||||
if: steps.add_files.outputs.update_resources == 'True'
|
||||
if: steps.update_version.outputs.update_resources == 'True'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.MAA_RESOURCE_SYNC }}
|
||||
run: |
|
||||
@@ -383,7 +383,7 @@ jobs:
|
||||
# gh cache delete
|
||||
|
||||
- name: Add cancelled status
|
||||
if: steps.check_sorted_templates.outputs.changes != 'True' || steps.add_files.outputs.have_commits != 'True'
|
||||
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
|
||||
|
||||
@@ -1431,8 +1431,8 @@ bool update_version_info(const fs::path& input_dir, const fs::path& output_dir)
|
||||
result["activity"]["time"] = time_var;
|
||||
result["activity"]["name"] = name;
|
||||
}
|
||||
static auto time = asst::utils::get_format_time();
|
||||
result["last_updated"] = time;
|
||||
auto version_opt = json::open(output_dir / "version.json");
|
||||
result["last_updated"] = version_opt->at("last_updated").as_string();
|
||||
|
||||
std::ofstream ofs(output_dir / "version.json", std::ios::out);
|
||||
ofs << result.format() << '\n';
|
||||
|
||||
46
tools/ResourceUpdater/version.ps1
Normal file
46
tools/ResourceUpdater/version.ps1
Normal file
@@ -0,0 +1,46 @@
|
||||
$hasChanges = $false
|
||||
$hasPngChanges = $false
|
||||
$hasVersionChanges = $false
|
||||
|
||||
git add .
|
||||
|
||||
$allModifiedFiles = git diff --name-only HEAD 2>$null
|
||||
|
||||
git reset .
|
||||
|
||||
if ($allModifiedFiles.Count -eq 0) {
|
||||
Write-Output "No files to update."
|
||||
}
|
||||
else {
|
||||
$hasChanges = $true
|
||||
|
||||
$modifiedFiles = $allModifiedFiles | Where-Object { $_ -notmatch 'tasks\.json$' } # Ignore only for version.json updates
|
||||
$directories = $modifiedFiles | ForEach-Object { Split-Path $_ } | Sort-Object -Unique
|
||||
|
||||
foreach ($dir in $directories) {
|
||||
$versionFile = Join-Path $dir "version.json"
|
||||
|
||||
if (Test-Path $versionFile) {
|
||||
$json = Get-Content -Path $versionFile | ConvertFrom-Json
|
||||
$json.last_updated = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss.fff")
|
||||
$jsonFormatted = $json | ConvertTo-Json -Depth 3
|
||||
|
||||
$jsonFormatted = $jsonFormatted -replace " ", " "
|
||||
$jsonFormatted | Set-Content -Path $versionFile
|
||||
|
||||
$hasVersionChanges = $true
|
||||
Write-Output "Updated: $versionFile"
|
||||
}
|
||||
}
|
||||
|
||||
# Check for PNG changes
|
||||
if ($allModifiedFiles | Where-Object { $_ -match '\.png$' }) {
|
||||
$hasPngChanges = $true
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output "Changes: $hasChanges"
|
||||
Write-Output "PNG Changes: $hasPngChanges"
|
||||
Write-Output "changes=$hasChanges" >> $env:GITHUB_OUTPUT
|
||||
Write-Output "contains_png=$hasPngChanges" >> $env:GITHUB_OUTPUT
|
||||
Write-Output "update_resources=$hasVersionChanges" >> $env:GITHUB_OUTPUT
|
||||
Reference in New Issue
Block a user