GitHub 自动构建 Nuget 包

工作流程

  1. 用户git push
  2. 触发github action
  3. 执行用户配置的yml脚本

如何配置?

  1. 首先要得到两个凭证

    • Nuget Api Key

      • 点击创建 Create

      • 配置下 Copy 凭证 [找地方存起来]

    • Github Token

      • 进入github官网 https://github.com 并登录

      • 选中Settings

      • 选中Developer settings

      • 选中Personal access token

      • 点击Generate new token

      • 配置一下生成

      • 复制后[找地方存起来]

  2. 配置项目中

    如下图所示配置凭证

  3. 添加Actions

    dotnet-core.yml

    name: .NET Core
    
    on:
      push:
        branches: [ master ]
      pull_request:
        branches: [ master ]
    
    jobs:
      build:
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v2
        - name: 建立.netcore环境
          uses: actions/setup-dotnet@v1
          with:
            dotnet-version: 3.1.301
        - name: 安装依赖
          run: dotnet restore
        - name: 构建
          run: dotnet build --configuration Release --no-restore
        - name: 添加github仓库
          run: |
            nuget sources add -name github -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GitHubToken }}
        - name: 安装nuget 
          uses: nuget/setup-nuget@v1
          with:        
            nuget-version: '5.x'
        - name: 发布生成包到github和nuget
          run: |
            nuget push ./bin/Release/*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} -NoSymbol
            nuget push ./bin/Release/*.nupkg -Source github -SkipDuplicate
    
    
posted @ 2020-11-03 20:17  林一怂儿  阅读(605)  评论(0)    收藏  举报