Skip to content

Build and Release

Build and Release #13

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: '版本号 (例如: 1.0.0)'
required: true
default: '1.0.0'
type: string
create_release:
description: '是否创建GitHub Release'
required: false
default: true
type: boolean
prerelease:
description: '是否为预发布版本'
required: false
default: false
type: boolean
permissions:
contents: write
packages: write
actions: read
jobs:
build-and-release:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# 自包含版本 (包含.NET运行时)
- runtime: win-x64
self_contained: true
suffix: "self-contained"
- runtime: linux-x64
self_contained: true
suffix: "self-contained"
- runtime: osx-x64
self_contained: true
suffix: "self-contained"
- runtime: linux-arm64
self_contained: true
suffix: "self-contained"
- runtime: osx-arm64
self_contained: true
suffix: "self-contained"
# 框架依赖版本 (需要安装.NET运行时)
- runtime: win-x64
self_contained: false
suffix: "framework-dependent"
- runtime: linux-x64
self_contained: false
suffix: "framework-dependent"
- runtime: osx-x64
self_contained: false
suffix: "framework-dependent"
- runtime: linux-arm64
self_contained: false
suffix: "framework-dependent"
- runtime: osx-arm64
self_contained: false
suffix: "framework-dependent"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version from tag or input
id: get_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION="dev-$(date +%Y%m%d%H%M%S)"
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Yarn
run: npm install -g yarn
- name: Cache node modules
uses: actions/cache@v4
with:
path: web/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('web/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install frontend dependencies
working-directory: web
run: |
yarn install
npm install --force
- name: Build frontend
working-directory: web
run: yarn run build
- name: Restore .NET dependencies
run: dotnet restore src/Console.Service/Console.Service.csproj
- name: Build .NET application
run: dotnet build src/Console.Service/Console.Service.csproj -c Release --no-restore
- name: Publish .NET application
run: |
dotnet publish src/Console.Service/Console.Service.csproj \
-c Release \
-r ${{ matrix.runtime }} \
--self-contained ${{ matrix.self_contained }} \
-p:PublishSingleFile=false \
-p:PublishTrimmed=false \
-p:Version=${{ steps.get_version.outputs.VERSION }} \
-p:AssemblyVersion=${{ steps.get_version.outputs.VERSION }} \
-p:FileVersion=${{ steps.get_version.outputs.VERSION }} \
-o ./publish/${{ matrix.runtime }}-${{ matrix.suffix }}
- name: Copy frontend to wwwroot
run: |
mkdir -p ./publish/${{ matrix.runtime }}-${{ matrix.suffix }}/wwwroot
cp -r web/dist/* ./publish/${{ matrix.runtime }}-${{ matrix.suffix }}/wwwroot/
- name: Create archive
run: |
cd publish
ARCHIVE_NAME="Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}-${{ matrix.suffix }}"
if [[ "${{ matrix.runtime }}" == win-* ]]; then
zip -r ../${ARCHIVE_NAME}.zip ${{ matrix.runtime }}-${{ matrix.suffix }}
else
tar -czf ../${ARCHIVE_NAME}.tar.gz ${{ matrix.runtime }}-${{ matrix.suffix }}
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}-${{ matrix.suffix }}
path: |
Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}-${{ matrix.suffix }}.*
retention-days: 30
create-release:
needs: build-and-release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && github.event.inputs.create_release == 'true')
steps:
- name: Get version from tag or input
id: get_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: List downloaded artifacts (debug)
run: |
echo "=== Artifacts structure ==="
find ./artifacts -type f -name "*.zip" -o -name "*.tar.gz" | sort
echo "=========================="
- name: Prepare release files
run: |
mkdir -p ./release-files
find ./artifacts -name "*.zip" -exec cp {} ./release-files/ \;
find ./artifacts -name "*.tar.gz" -exec cp {} ./release-files/ \;
echo "=== Release files ==="
ls -la ./release-files/
echo "===================="
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ steps.get_version.outputs.VERSION }}
tag_name: ${{ steps.get_version.outputs.VERSION }}
files: ./release-files/*
draft: false
prerelease: ${{ github.event.inputs.prerelease == 'true' || false }}
generate_release_notes: true
body: |
## 🚀 Console Release ${{ steps.get_version.outputs.VERSION }}
### 📦 版本说明
#### 🔹 自包含版本 (Self-Contained) - 推荐
包含完整的.NET运行时,无需预装.NET环境,文件较大但兼容性最好:
- **Windows x64**: `Console-${{ steps.get_version.outputs.VERSION }}-win-x64-self-contained.zip`
- **Linux x64**: `Console-${{ steps.get_version.outputs.VERSION }}-linux-x64-self-contained.tar.gz`
- **macOS x64**: `Console-${{ steps.get_version.outputs.VERSION }}-osx-x64-self-contained.tar.gz`
- **Linux ARM64**: `Console-${{ steps.get_version.outputs.VERSION }}-linux-arm64-self-contained.tar.gz`
- **macOS ARM64**: `Console-${{ steps.get_version.outputs.VERSION }}-osx-arm64-self-contained.tar.gz`
#### 🔸 框架依赖版本 (Framework-Dependent) - 轻量
需要预装.NET 9.0运行时,文件较小:
- **Windows x64**: `Console-${{ steps.get_version.outputs.VERSION }}-win-x64-framework-dependent.zip`
- **Linux x64**: `Console-${{ steps.get_version.outputs.VERSION }}-linux-x64-framework-dependent.tar.gz`
- **macOS x64**: `Console-${{ steps.get_version.outputs.VERSION }}-osx-x64-framework-dependent.tar.gz`
- **Linux ARM64**: `Console-${{ steps.get_version.outputs.VERSION }}-linux-arm64-framework-dependent.tar.gz`
- **macOS ARM64**: `Console-${{ steps.get_version.outputs.VERSION }}-osx-arm64-framework-dependent.tar.gz`
### ✨ 特性
- 包含完整的前端和后端集成
- 修复Entity Framework兼容性问题
- 支持多平台部署
- 提供两种部署方式选择
### 🔧 使用方法
#### 自包含版本:
1. 下载对应平台的自包含版本压缩包
2. 解压到目标目录
3. 直接运行可执行文件即可启动服务
#### 框架依赖版本:
1. 确保已安装 [.NET 9.0 Runtime](https://dotnet.microsoft.com/download/dotnet/9.0)
2. 下载对应平台的框架依赖版本压缩包
3. 解压到目标目录
4. 运行可执行文件即可启动服务
### 📋 系统要求
- **自包含版本**: 无需预装任何依赖
- **框架依赖版本**: 需要安装.NET 9.0 Runtime
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}