diff --git a/.github/workflows/res-update-game.yml b/.github/workflows/res-update-game.yml index 87692de93a..9bf2439155 100644 --- a/.github/workflows/res-update-game.yml +++ b/.github/workflows/res-update-game.yml @@ -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 diff --git a/tools/ResourceUpdater/main.cpp b/tools/ResourceUpdater/main.cpp index fc04f15707..2e864d3479 100644 --- a/tools/ResourceUpdater/main.cpp +++ b/tools/ResourceUpdater/main.cpp @@ -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'; diff --git a/tools/ResourceUpdater/version.ps1 b/tools/ResourceUpdater/version.ps1 new file mode 100644 index 0000000000..2058a22008 --- /dev/null +++ b/tools/ResourceUpdater/version.ps1 @@ -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