Skip to content

Build and Release

Build and Release #4

Workflow file for this run

name: Build and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: '版本号 (例如: v1.0.0)'
required: true
default: 'v1.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:
runtime: [win-x64, linux-x64, osx-x64, linux-arm64, osx-arm64]
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 true \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
-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 }}
- name: Copy frontend to wwwroot
run: |
mkdir -p ./publish/${{ matrix.runtime }}/wwwroot
cp -r web/dist/* ./publish/${{ matrix.runtime }}/wwwroot/
- name: Create archive
run: |
cd publish
if [[ "${{ matrix.runtime }}" == win-* ]]; then
zip -r ../Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}.zip ${{ matrix.runtime }}
else
tar -czf ../Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}.tar.gz ${{ matrix.runtime }}
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}
path: |
Console-${{ steps.get_version.outputs.VERSION }}-${{ matrix.runtime }}.*
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 }}
### 📦 下载链接
- **Windows x64**: Console-${{ steps.get_version.outputs.VERSION }}-win-x64.zip
- **Linux x64**: Console-${{ steps.get_version.outputs.VERSION }}-linux-x64.tar.gz
- **macOS x64**: Console-${{ steps.get_version.outputs.VERSION }}-osx-x64.tar.gz
- **Linux ARM64**: Console-${{ steps.get_version.outputs.VERSION }}-linux-arm64.tar.gz
- **macOS ARM64**: Console-${{ steps.get_version.outputs.VERSION }}-osx-arm64.tar.gz
### ✨ 特性
- 包含完整的前端和后端集成
- 自包含可执行文件,无需安装.NET运行时
- 支持多平台部署
### 🔧 使用方法
1. 下载对应平台的压缩包
2. 解压到目标目录
3. 运行可执行文件即可启动服务
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}