.github/workflows/dotnet-core.yml
name: Build and Publish
on:
create:
tags:
- '*'
push:
tags:
- '*'
branches: [ master ]
pull_request:
branches: [ master ]
env:
GITHUB_REPOSITORY_OWNER: 'gmarokov'
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup .NET Core - 5.0.x
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '5.0.x'
- name: Setup .NET Core - 3.1.x
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '3.1.x'
- name: Setup .NET Core - 2.2.x
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '2.2.x'
- name: Setup .NET Core - 2.1.x
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: '2.1.x'
- run: dotnet --info
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Pack
run: dotnet pack --configuration Release --no-restore --output artifacts
- name: Add NuGet sources
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
run: |
dotnet nuget add source https://nuget.pkg.github.com/${{ env.GITHUB_REPOSITORY_OWNER }}/index.json --name github
- name: NuGet push on GitHub
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
run: dotnet nuget push "**/*.nupkg" --source github --api-key ${{ secrets.GH_PAT }} --skip-duplicate
- name: NuGet push on NuGet
if: startsWith(github.ref, 'refs/tags/')
run: dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
- name: Upload a Build Artifact
uses: actions/upload-artifact@v2
with:
name: artifacts
path: artifacts/*