From 055cd711b3a17d54ff4f817e3c4692ae28c6405f Mon Sep 17 00:00:00 2001 From: ZekerZhayard Date: Thu, 21 May 2026 14:42:44 +0800 Subject: [PATCH] Move actions/checkout from composite actions to workflow level --- .github/actions/build/action.yml | 8 ++--- .github/actions/publish/action.yml | 34 +++---------------- .../{Publish-Json.ps1 => Publish-Files.ps1} | 28 ++++++++------- .github/workflows/beta.yml | 8 +++-- .github/workflows/pull-request.yml | 2 ++ .github/workflows/release.yml | 10 ++++-- 6 files changed, 39 insertions(+), 51 deletions(-) rename .github/scripts/{Publish-Json.ps1 => Publish-Files.ps1} (75%) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 2777143..d80ea9f 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -1,4 +1,4 @@ -# Composite action: checkout, setup JDK, build with Gradle, upload artifact +# Composite action: setup JDK, build with Gradle, upload artifact name: Build description: Build project with Gradle and upload artifact @@ -14,9 +14,7 @@ inputs: runs: using: composite steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: distribution: temurin java-version: '25' @@ -28,7 +26,7 @@ runs: IS_SNAPSHOT: ${{ inputs.is-snapshot }} run: ./gradlew clean build --info --stacktrace - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 with: name: ${{ inputs.artifact-name }} path: Bootstrap/build/libs/ diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml index d923918..c9a3a8c 100644 --- a/.github/actions/publish/action.yml +++ b/.github/actions/publish/action.yml @@ -13,42 +13,18 @@ inputs: runs: using: composite steps: - - uses: actions/checkout@v4 - with: - clean: false # preserve artifact files already downloaded before this action - - # Upload jars to R2 (S3-compatible, mods/ prefix) - - uses: michaelliao/sync-s3-compatible-action@v1 - with: - SYNC_DIR: ${{ inputs.artifact-dir }} - BUCKET_URL: ${{ env.R2_BASE_URL }} - BUCKET_NAME: ${{ env.R2_BUCKET }} - AWS_ACCESS_KEY_ID: ${{ env.R2_SECRET_ID }} - AWS_SECRET_ACCESS_KEY: ${{ env.R2_SECRET_KEY }} - TARGET_PATH: mods/ - - # Upload jars to COS (qcloud mode, mods/ prefix) - - uses: michaelliao/sync-s3-compatible-action@v1 - with: - SYNC_TYPE: qcloud - SYNC_DIR: ${{ inputs.artifact-dir }} - BUCKET_NAME: ${{ env.COS_BUCKET }} - AWS_ACCESS_KEY_ID: ${{ env.COS_SECRET_ID }} - AWS_SECRET_ACCESS_KEY: ${{ env.COS_SECRET_KEY }} - BUCKET_REGION: ap-shanghai - TARGET_PATH: mods/ - # Generate JSON metadata, upload to R2/COS root, and output CDN URLs - name: Generate and upload JSON metadata - id: publish-json + id: publish-files shell: pwsh - run: .github/scripts/Publish-Json.ps1 -ArtifactDir '${{ inputs.artifact-dir }}' -Type '${{ inputs.type }}' + run: ./.github/scripts/Publish-Files.ps1 -ArtifactDir '${{ inputs.artifact-dir }}' -Type '${{ inputs.type }}' # Refresh Tencent Cloud CDN cache for the JSON files - name: Refresh CDN - uses: tencentcloud/cdn-refresh-action@v1 + uses: linrongda/tencent-cdn-action@v2 with: - urls: ${{ steps.publish-json.outputs.cdn-urls }} secret-id: ${{ env.COS_SECRET_ID }} secret-key: ${{ env.COS_SECRET_KEY }} + action: purgeUrls + paths: ${{ steps.publish-files.outputs.cdn-urls }} continue-on-error: true diff --git a/.github/scripts/Publish-Json.ps1 b/.github/scripts/Publish-Files.ps1 similarity index 75% rename from .github/scripts/Publish-Json.ps1 rename to .github/scripts/Publish-Files.ps1 index f647f98..39e8ff3 100644 --- a/.github/scripts/Publish-Json.ps1 +++ b/.github/scripts/Publish-Files.ps1 @@ -5,11 +5,6 @@ param( $ErrorActionPreference = "Stop" -# ---- Validate required env vars ---- -foreach ($var in @('R2_SECRET_ID', 'R2_SECRET_KEY', 'R2_BUCKET', 'R2_BASE_URL')) { - if (-not $env:$var) { throw "Missing required env: $var" } -} - $suffix = if ($Type -eq "beta") { "-beta" } else { "" } # ---- Find the built jar ---- @@ -34,7 +29,7 @@ if ($isSnapshot) { $mcVersions = ((Get-Content "gradle.properties" | Select-String "^minecraft_major_versions=") -replace "^.*=", "").Trim() $mcVersionList = $mcVersions -split "," | ForEach-Object { $_.Trim() } -$baseUrl = $env:R2_BASE_URL.TrimEnd('/') +$baseUrl = "_BASE_URL_" # ---- Generate latest(-beta).json ---- $latestJson = @{ @@ -42,32 +37,42 @@ $latestJson = @{ downloads = @{ Universal = "$baseUrl/$jarKey" } launchermeta = @{} } | ConvertTo-Json -Depth 10 -Set-Content -Path "$ArtifactDir/latest$suffix.json" -Value $latestJson -NoNewline # ---- Generate detail(-beta).json ---- $details = [ordered]@{} foreach ($mcVer in $mcVersionList) { - $details[$mcVer] = @{ Universal = "$baseUrl/$jarKey" } + $details[$mcVer] = @{ + Fabric = "$baseUrl/$jarKey" + Forge = "$baseUrl/$jarKey" + NeoForge = "$baseUrl/$jarKey" + Quilt = "$baseUrl/$jarKey" + } } $detailJson = @{ version = $shortVersion timestamp = [System.DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() details = $details } | ConvertTo-Json -Depth 10 -Set-Content -Path "$ArtifactDir/detail$suffix.json" -Value $detailJson -NoNewline -# ---- Upload JSON files to R2 ---- +# ---- Upload files to R2 ---- $env:AWS_ACCESS_KEY_ID = $env:R2_SECRET_ID $env:AWS_SECRET_ACCESS_KEY = $env:R2_SECRET_KEY $env:AWS_DEFAULT_REGION = "auto" +aws s3 cp "$ArtifactDir/$jarFilename" "s3://$env:R2_BUCKET/$jarKey" --endpoint-url $($env:R2_BASE_URL.TrimEnd('/')) +$latestJson -replace $baseUrl, "https://csl.3-3.dev" | Set-Content -Path "$ArtifactDir/latest$suffix.json" -NoNewline +$detailJson -replace $baseUrl, "https://csl.3-3.dev" | Set-Content -Path "$ArtifactDir/detail$suffix.json" -NoNewline aws s3 cp "$ArtifactDir/latest$suffix.json" "s3://$env:R2_BUCKET/latest$suffix.json" --endpoint-url $($env:R2_BASE_URL.TrimEnd('/')) aws s3 cp "$ArtifactDir/detail$suffix.json" "s3://$env:R2_BUCKET/detail$suffix.json" --endpoint-url $($env:R2_BASE_URL.TrimEnd('/')) -# ---- Upload JSON files to COS ---- +# ---- Upload files to COS ---- +$cdnBase = "https://csl.littleservice.cn" try { pip install coscmd -q --disable-pip-version-check coscmd config -a $env:COS_SECRET_ID -s $env:COS_SECRET_KEY -b $env:COS_BUCKET -r ap-shanghai + coscmd upload "$ArtifactDir/$jarFilename" "$jarKey" + $latestJson -replace $baseUrl, $cdnBase | Set-Content -Path "$ArtifactDir/latest$suffix.json" -NoNewline + $detailJson -replace $baseUrl, $cdnBase | Set-Content -Path "$ArtifactDir/detail$suffix.json" -NoNewline coscmd upload "$ArtifactDir/latest$suffix.json" "latest$suffix.json" coscmd upload "$ArtifactDir/detail$suffix.json" "detail$suffix.json" } catch { @@ -75,7 +80,6 @@ try { } # ---- Output CDN URLs for subsequent refresh step ---- -$cdnBase = "https://csl.littleservice.cn" "cdn-urls<