|
| 1 | +name: Package |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - synchronize |
| 8 | + - reopened |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + release: |
| 13 | + types: |
| 14 | + - published |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +env: |
| 18 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 19 | + DOTNET_NOLOGO: true |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + packages: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + name: Build |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v5 |
| 31 | + with: |
| 32 | + fetch-depth: '0' |
| 33 | + |
| 34 | + - name: Setup .NET Core SDK |
| 35 | + uses: actions/setup-dotnet@v4 |
| 36 | + with: |
| 37 | + global-json-file: global.json |
| 38 | + cache: 'true' |
| 39 | + cache-dependency-path: '**/packages.lock.json' |
| 40 | + |
| 41 | + - name: Set Default TAG |
| 42 | + run: echo "TAG=v0.0.0" >> $GITHUB_ENV |
| 43 | + |
| 44 | + - name: Set TAG variable from tag |
| 45 | + run: echo "TAG=${{ github.event.release.tag_name }}" >> $GITHUB_ENV |
| 46 | + if: ${{ github.event_name == 'release' && github.event.action == 'published' }} |
| 47 | + |
| 48 | + - name: Set VERSION variable |
| 49 | + run: echo "VERSION=${TAG#v}" >> $GITHUB_ENV |
| 50 | + |
| 51 | + - name: Restore .NET Packages |
| 52 | + run: dotnet restore --locked-mode |
| 53 | + |
| 54 | + - name: Build .NET Solution |
| 55 | + run: dotnet build --configuration Release --no-restore /p:Version=${VERSION} |
| 56 | + |
| 57 | + - name: Test .NET Solution |
| 58 | + run: dotnet test --configuration Release --no-build --filter="Category=UnitTest|Category=IntegrationTest" --logger "trx;LogFilePrefix=test-results" |
| 59 | + |
| 60 | + - uses: actions/upload-artifact@v4 |
| 61 | + if: always() |
| 62 | + with: |
| 63 | + name: test-results |
| 64 | + path: "**/test-results*.trx" |
| 65 | + |
| 66 | + - name: Pack .NET Solution |
| 67 | + run: dotnet pack --configuration Release --no-build --output pack/ /p:PackageVersion=${VERSION} |
| 68 | + if: ${{ github.event_name == 'release' && github.event.action == 'published' }} |
| 69 | + |
| 70 | + - name: Publish .NET Solution to GitHub Packages |
| 71 | + run: dotnet nuget push pack/*.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --skip-duplicate |
| 72 | + if: ${{ github.event_name == 'release' && github.event.action == 'published' }} |
| 73 | + |
| 74 | + - name: Store .NET Package |
| 75 | + uses: actions/upload-artifact@v4 |
| 76 | + with: |
| 77 | + name: nuget |
| 78 | + if-no-files-found: error |
| 79 | + retention-days: 7 |
| 80 | + path: pack/*.nupkg |
| 81 | + if: ${{ github.event_name == 'release' && github.event.action == 'published' }} |
| 82 | + |
| 83 | + - name: Publish .NET Solution to NuGet.org |
| 84 | + env: |
| 85 | + apikey: ${{ secrets.NUGET_ORG_KEY }} |
| 86 | + run: dotnet nuget push pack/*.nupkg --api-key ${{ secrets.NUGET_ORG_KEY }} --source nuget --skip-duplicate |
| 87 | + if: ${{ env.apikey != '' && github.event_name == 'release' && github.event.action == 'published' }} |
0 commit comments