Files
MikuSB/.github/workflows/release.yml
2026-04-29 22:34:14 +08:00

112 lines
3.7 KiB
YAML

name: release
on:
push:
paths:
- version.txt
workflow_dispatch:
permissions:
contents: write
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
build-release:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Read version
id: version
shell: pwsh
run: |
$line = (Get-Content version.txt | Select-Object -First 1).Trim()
$version = $line -replace '^v=', ''
if ([string]::IsNullOrWhiteSpace($version)) { throw 'version.txt is empty.' }
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"tag=v$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Publish server
run: dotnet publish .\MikuSB\MikuSB.csproj -c Release -p:PublishProfile=MikuSB-Win64-MultiFile -o .\artifacts\publish\MikuSB
- name: Assemble release package
shell: pwsh
run: |
$packageDir = ".\artifacts\package\MikuSB-win-x64"
New-Item -ItemType Directory -Force -Path $packageDir | Out-Null
Copy-Item .\artifacts\publish\MikuSB\* $packageDir -Recurse -Force
if (-not (Test-Path "$packageDir\MikuSB.Updater.exe")) { throw 'MikuSB.Updater.exe was not bundled into the publish output.' }
Copy-Item .\version.txt $packageDir -Force
Compress-Archive -Path "$packageDir\*" -DestinationPath .\artifacts\MikuSB-win-x64.zip -Force
$hash = (Get-FileHash .\artifacts\MikuSB-win-x64.zip -Algorithm SHA256).Hash.ToLowerInvariant()
"$hash MikuSB-win-x64.zip" | Set-Content .\artifacts\MikuSB-win-x64.zip.sha256
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
generate_release_notes: true
files: |
artifacts/MikuSB-win-x64.zip
artifacts/MikuSB-win-x64.zip.sha256
build-release-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Publish server
run: |
dotnet publish ./MikuSB/MikuSB.csproj -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true --property:PublishDir=../artifacts/dist
- name: Read version
id: version
shell: bash
run: |
line=$(head -n 1 version.txt | xargs)
VERSION=${line#v=}
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
if [ -z "$VERSION" ]; then
echo "version.txt is empty."
VERSION=${SHORT_HASH}
fi
if [[ "${{ env.BRANCH_NAME }}" == "main" ]]; then
echo "tag=v${VERSION}" >> $GITHUB_OUTPUT
else
SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
echo "tag=${SAFE_NAME}-v${VERSION}-${SHORT_HASH}" >> $GITHUB_OUTPUT
fi
- name: Assemble release package
run: |
packageDir="./artifacts/dist/"
zipFile="MikuSB-linux-x64.zip"
cp ./version.txt ${packageDir}
pushd ${packageDir}
zip -r ../${zipFile} .
popd
sha256sum ./artifacts/${zipFile} > ./artifacts/${zipFile}.sha256
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
generate_release_notes: true
files: |
./artifacts/MikuSB-linux-x64.zip
./artifacts/MikuSB-linux-x64.zip.sha256