diff --git a/.github/workflows/gen-index.yml b/.github/workflows/gen-index.yml new file mode 100644 index 0000000..d265af6 --- /dev/null +++ b/.github/workflows/gen-index.yml @@ -0,0 +1,42 @@ +name: Generate Plugin Index + +on: + push: + +jobs: + + build: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: List files + run: ls + + - name: Install Index Generator + run: | + Invoke-WebRequest -Uri https://github.com/ClassIsland/ClassIsland.PluginIndexGenerator/releases/download/latest/ClassIsland.PluginIndexGenerator.zip -OutFile ClassIsland.PluginIndexGenerator.zip + Expand-Archive -Path ClassIsland.PluginIndexGenerator.zip -DestinationPath . + + - name: Generate Plugin Index + run: | + mkdir out/source/ + ./ClassIsland.PluginIndexGenerator.exe index out/source/index.json -b base.json + 7z a "./out/index.zip" ./out/source/* -r -mx=9 + rm -r -Force out/source/ + + - name: Generate MD5 + run: | + pwsh -ep Bypass -c .\tools\generate-md5.ps1 ./out + + - name: Upload to release + uses: ncipollo/release-action@v1 + with: + tag: latest + artifacts: ./out/*.zip,./out/*.md5sum + bodyFile: ./out/checksums.md + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/tools/generate-index.ps1 b/tools/generate-index.ps1 deleted file mode 100644 index 711a006..0000000 --- a/tools/generate-index.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -param($inputPath,$outputPath,$basePath,$customClassIslandPath) - -function Wait-Task { - param( - [Parameter(Mandatory, ValueFromPipeline)] - [System.Threading.Tasks.Task[]]$Task - ) - - Begin { - $Tasks = @() - } - - Process { - $Tasks += $Task - } - - End { - While (-not [System.Threading.Tasks.Task]::WaitAll($Tasks, 200)) {} - $Tasks.ForEach( { $_.GetAwaiter().GetResult() }) - } -} - -Set-Alias -Name await -Value Wait-Task -Force - -# TODO: 从 AppVeyor 下载 ClassIsland 实例 - -Import-Module $customClassIslandPath - -await ([ClassIsland.Core.Helpers.PluginMarketHelper]::GeneratePluginIndexFromManifests($inputPath, $outputPath, $basePath)) diff --git a/tools/generate-md5.ps1 b/tools/generate-md5.ps1 new file mode 100644 index 0000000..b7028bf --- /dev/null +++ b/tools/generate-md5.ps1 @@ -0,0 +1,36 @@ +param($path) + +echo $path +rm $path/*.md5sum +$files = Get-ChildItem $path +$hashes = [ordered]@{} +$summary = " +> [!important] +> 下载时请注意核对文件MD5是否正确。 + +| 文件名 | MD5 | +| --- | --- | +" + +foreach ($i in $files) { + $name = $i.Name + $hash = Get-FileHash $i -Algorithm MD5 + $hashString = $hash.Hash + $hashes.Add($name, $hashString) + Write-Output $hash.Hash > "${i}.md5sum" + $summary += "| $name | ``${hashString}`` |`n" +} + +echo $hashes + +$json = ConvertTo-Json $hashes -Compress + +$summary += "`n" +echo $summary > "$path/checksums.md" +Write-Host "MD5 Summary:" -ForegroundColor Gray +Write-Host $summary -ForegroundColor Gray +Write-Host "----------" -ForegroundColor Gray + +#if (-not $GITHUB_ACTION -eq $null) { +# 'MD5_SUMMARY=' + $summary.Replace("`n", "<<") | Out-File -FilePath $env:GITHUB_ENV -Append +#}