Skip to content

feat(Utils): 更新应用数据目录名称并增强目录创建逻辑 #27

feat(Utils): 更新应用数据目录名称并增强目录创建逻辑

feat(Utils): 更新应用数据目录名称并增强目录创建逻辑 #27

Workflow file for this run

name: Build
on:
push:
branches: [ "main" ]
tags:
- 'v*'
# 只有当项目代码更新时才触发
paths:
- '**/*.cs'
- '**/*.csproj'
- '**/*.xaml'
- '!.github/**'
pull_request:
branches: [ "main" ]
# 只有当项目代码更新时才触发
paths:
- '**/*.cs'
- '**/*.csproj'
- '**/*.xaml'
workflow_dispatch:
jobs:
build:
defaults:
run:
shell: pwsh
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: Cache build output
uses: actions/cache@v4
with:
path: |
**/bin
**/obj
key: ${{ runner.os }}-modbridge-${{ hashFiles('**/*.csproj') }}
- name: Get version
run: |
$date = Get-Date -Format "yyMMddHHmm"
echo "tag=$((git describe --tags --abbrev=0).Replace('v',''))" >> $env:GITHUB_ENV
echo "fileVersion=$env:tag.$date" >> $env:GITHUB_ENV
- 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))" `
-p:Version=$env:tag `
-p:FileVersion=$env:fileVersion
env:
CURSEFORGEAPIKEY: ${{ secrets.CURSEFORGEAPIKEY }}
- name: Rename exe with version and platform
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 }}