安装多个版本 #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish NuGet Package | |
on: | |
push: | |
branches: | |
- main # 触发工作流的分支 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet: [ '8.x', '9.x' ] | |
env: | |
PROJECT_DIR: EfCore.NamingConverter # 定义环境变量 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ matrix.dotnet }} # 使用矩阵中的 .NET 版本 | |
- name: Restore dependencies | |
run: dotnet restore | |
working-directory: ${{ env.PROJECT_DIR }} # 使用环境变量指定工作目录 | |
- name: Build | |
run: dotnet build --configuration Release --no-restore | |
working-directory: ${{ env.PROJECT_DIR }} # 使用环境变量指定工作目录 | |
- name: Pack | |
run: dotnet pack --configuration Release --no-build --output ./nupkg | |
working-directory: ${{ env.PROJECT_DIR }} # 使用环境变量指定工作目录 | |
- name: Publish to NuGet | |
if: github.ref == 'refs/heads/main' # 仅在推送到 main 分支时发布 | |
env: | |
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} # 从 GitHub Secrets 中获取 NuGet API 密钥 | |
run: dotnet nuget push ./nupkg/*.nupkg --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json | |
working-directory: ${{ env.PROJECT_DIR }} # 使用环境变量指定工作目录 |