aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/dotnet.yml
blob: 106d92c9f6cebc7bd45d9f2b7cfff7bf58dce412 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: .NET

on:
  push:
    paths:
      - "**.cs"
      - "**.csproj"
      - "**.sln"
      - ".github/workflows/dotnet.yml"
  pull_request:
    paths:
      - "**.cs"
      - "**.csproj"
      - "**.sln"
      - ".github/workflows/dotnet.yml"

jobs:
  build-and-test:
    name: Build and Test
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup .NET
        uses: actions/setup-dotnet@v4
      - name: Install dependencies
        run: dotnet restore
      - name: Test
        run: dotnet test --no-restore

  publish-preview:
    name: Publish Preview NuGet to GitHub Packages
    needs: build-and-test
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          source-url: https://nuget.pkg.github.com/locusts-r-us/index.json
        env:
          NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Install dependencies
        run: dotnet restore
      - name: Build the package
        run: dotnet build --configuration Release --no-restore -p:SymbolPackageFormat=symbols.nupkg # GitHub Packages does not support snupkg
      - name: Publish the package
        run: dotnet nuget push src/bin/Release/*.symbols.nupkg

  publish-release:
    name: Publish Release NuGet to NuGet.org
    needs: build-and-test
    if: ${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/') }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        env:
          NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
      - name: Install dependencies
        run: dotnet restore
      - name: Build the package
        run: dotnet build --configuration Release --no-restore -p:SymbolPackageFormat=snupkg
      - name: Publish the package
        run: |
          dotnet nuget push src/bin/Release/*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_TOKEN }}