Files
LanMountainDesktop/docs/archive/Plugins develop/06-CI-CD与自动化/02-配置自动构建.md
2026-06-08 03:54:33 +08:00

2.4 KiB
Raw Blame History

02-配置自动构建

配置 GitHub Actions 自动构建插件项目。


🎯 完整构建工作流

# .github/workflows/build.yml
name: Build

on:
  push:
    branches: [main, master]
    paths-ignore:
      - '**.md'
      - '.gitignore'
  pull_request:
    branches: [main, master]

env:
  DOTNET_VERSION: '10.0.x'
  CONFIGURATION: 'Release'

jobs:
  build:
    runs-on: windows-latest
    
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      
      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}
      
      - name: Cache NuGet
        uses: actions/cache@v4
        with:
          path: ~/.nuget/packages
          key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
          restore-keys: |
            ${{ runner.os }}-nuget-
      
      - name: Restore
        run: dotnet restore
      
      - name: Build
        run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore
      
      - name: Test
        run: dotnet test --no-build --verbosity normal
      
      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: plugin-${{ github.run_number }}
          path: bin/${{ env.CONFIGURATION }}/net10.0/*.laapp

🔧 关键配置说明

路径过滤

on:
  push:
    paths-ignore:
      - '**.md'        # 忽略文档修改
      - '.gitignore'   # 忽略 gitignore 修改
      - 'docs/**'      # 忽略 docs 文件夹

环境变量

env:
  DOTNET_VERSION: '10.0.x'
  CONFIGURATION: 'Release'
  PLUGIN_NAME: 'MyPlugin'

构建步骤

steps:
  # 1. 检出
  - uses: actions/checkout@v4
  
  # 2. 设置 .NET
  - uses: actions/setup-dotnet@v4
    with:
      dotnet-version: ${{ env.DOTNET_VERSION }}
  
  # 3. 缓存
  - uses: actions/cache@v4
    with:
      path: ~/.nuget/packages
      key: nuget-${{ hashFiles('**/*.csproj') }}
  
  # 4. 还原
  - run: dotnet restore
  
  # 5. 构建
  - run: dotnet build -c ${{ env.CONFIGURATION }} --no-restore
  
  # 6. 测试
  - run: dotnet test --no-build
  
  # 7. 上传
  - uses: actions/upload-artifact@v4
    with:
      name: plugin
      path: bin/Release/net10.0/*.laapp

📚 参考资源


最后更新2026年4月