Update build.yml #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: [ "main" ] | |
tags: | |
- 'v*' | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: windows-latest | |
strategy: | |
matrix: | |
rid: [ win-x64, win-x86 ] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 8.0.x | |
- name: Restore | |
run: dotnet restore | |
- name: Publish (${{ matrix.rid }}) | |
run: | | |
dotnet publish -c Release ` | |
-r ${{ matrix.rid }} ` | |
-p:CurseForgeApiKey="$([System.Web.HttpUtility]::UrlEncode($env:CURSEFORGEAPIKEY))" | |
env: | |
CURSEFORGEAPIKEY: ${{ secrets.CURSEFORGEAPIKEY }} | |
- name: Rename exe with version and platform | |
shell: pwsh | |
run: | | |
$rid = "${{ matrix.rid }}" | |
$publishDir = Get-ChildItem -Path "bin/Release/net8.0-windows/$rid/publish" -Recurse | Where-Object { $_.Name -eq "ModBridge.exe" } | |
mkdir exe | |
if ($publishDir) { | |
$newName = "ModBridge-$rid.exe" | |
Rename-Item -Path $publishDir.FullName -NewName $newName | |
mv "bin/Release/net8.0-windows/$rid/publish/$newName" exe/$newName | |
} | |
- name: Upload Artifacts (${{ matrix.rid }}) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ModBridge-${{ matrix.rid }} | |
path: | | |
exe/*.exe | |
release: | |
needs: build | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') # 只有打 tag 时才执行 | |
steps: | |
- name: Download Artifacts | |
uses: actions/download-artifact@v5 | |
with: | |
path: dist | |
- name: Rename executables with version | |
run: | | |
ls -l dist | |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/} | |
else | |
VERSION=${GITHUB_SHA::7} # 取前7位提交哈希 | |
fi | |
echo "Using VERSION=$VERSION" | |
for file in dist/*/*.exe; do | |
BASENAME=$(basename "$file") | |
if [[ "$BASENAME" == *"x64"* ]]; then | |
PLATFORM="win-x64" | |
elif [[ "$BASENAME" == *"x86"* ]]; then | |
PLATFORM="win-x86" | |
else | |
PLATFORM="win" | |
fi | |
echo mv "$file" "dist/ModBridge-${VERSION}-${PLATFORM}.exe" | |
mv "$file" "dist/ModBridge-${VERSION}-${PLATFORM}.exe" | |
done | |
ls -l dist | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: dist/*.exe | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |