Backend/.gitea/workflows/develop.yml

88 lines
2.3 KiB
YAML
Raw Normal View History

2025-02-24 20:27:01 +08:00
name: Backend_develop # 工作流的名称
2025-02-24 20:42:35 +08:00
# 当有代码推送到仓库的 develop 分支时,这个 Actions 工作流会被触发并执行
2025-02-24 20:27:01 +08:00
on:
push:
branches:
- develop
jobs:
build:
runs-on: "backend_runner"
steps:
- name: test
shell: powershell
run: |
echo "Git clone_start"
2025-02-24 21:02:55 +08:00
# 設定變數
$projectPath = "D:\Code\Project\TCM"
$backendPath = "$projectPath\Backend"
$apiPath = "D:\Code\Server\TCM\API"
# 確保主資料夾存在
if (-not (Test-Path $projectPath)) {
echo "錯誤: 主資料夾 $projectPath 不存在"
exit 1
}
cd $projectPath
# 刪除原 Backend 資料夾
if (Test-Path $backendPath) {
Remove-Item -Recurse -Force $backendPath
}
# 確保目標資料夾存在
New-Item -Path $backendPath -ItemType Directory -Force | Out-Null
echo " Cloning repository..."
git clone -b develop http://leovip125.ddns.net:8418/TCM/Backend.git $backendPath
if ($LASTEXITCODE -ne 0) {
echo "錯誤: Git Clone 失敗"
exit 1
}
2025-02-24 20:27:01 +08:00
echo "Clone End"
2025-02-24 21:02:55 +08:00
# .NET 發布
2025-02-24 20:48:20 +08:00
echo "發布 start"
2025-02-24 20:58:04 +08:00
2025-02-24 21:02:55 +08:00
# 切換到 Backend 目錄
cd $backendPath
if ($LASTEXITCODE -ne 0) {
echo "錯誤: 無法切換到 Backend 目錄"
exit 1
}
# 還原與建置
dotnet restore
if ($LASTEXITCODE -ne 0) {
echo "錯誤: dotnet restore 失敗"
exit 1
}
dotnet build --configuration Release
if ($LASTEXITCODE -ne 0) {
echo "錯誤: dotnet build 失敗"
exit 1
}
# 移除舊的 API 發布資料夾
if (Test-Path $apiPath) {
Remove-Item -Recurse -Force $apiPath
}
# 確保目標資料夾存在
New-Item -Path $apiPath -ItemType Directory -Force | Out-Null
# 發布
dotnet publish -c Release -o $apiPath
if ($LASTEXITCODE -ne 0) {
echo "錯誤: dotnet publish 失敗"
exit 1
}
echo "發布 end"
2025-02-24 20:58:04 +08:00
2025-02-24 20:42:35 +08:00