|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ['*'] |
| 7 | + pull_request: |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: build-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +env: |
| 15 | + DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 16 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 17 | + DOTNET_NOLOGO: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: windows-latest |
| 22 | + timeout-minutes: 30 |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up .NET |
| 28 | + uses: actions/setup-dotnet@v4 |
| 29 | + with: |
| 30 | + global-json-file: global.json |
| 31 | + |
| 32 | + # The tag is the version: tag 1.2.3 (or v1.2.3) builds 1.2.3. Other builds use the |
| 33 | + # Version in Directory.Build.props. |
| 34 | + - name: Resolve the version from the tag |
| 35 | + if: startsWith(github.ref, 'refs/tags/') |
| 36 | + shell: bash |
| 37 | + run: echo "VERSION_ARGUMENT=-p:Version=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" |
| 38 | + |
| 39 | + - name: Build |
| 40 | + run: dotnet build src --configuration Release ${{ env.VERSION_ARGUMENT }} |
| 41 | + |
| 42 | + - name: Test |
| 43 | + run: dotnet test src --configuration Release --no-build --no-restore |
| 44 | + |
| 45 | + - name: Upload received on failure |
| 46 | + if: failure() |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: received |
| 50 | + path: '**/*.received.*' |
| 51 | + if-no-files-found: ignore |
| 52 | + retention-days: 14 |
| 53 | + |
| 54 | + - name: Upload packages |
| 55 | + if: success() |
| 56 | + uses: actions/upload-artifact@v4 |
| 57 | + with: |
| 58 | + name: nupkgs |
| 59 | + path: nugets/**/*.nupkg |
| 60 | + if-no-files-found: warn |
| 61 | + retention-days: 30 |
| 62 | + |
| 63 | + # Trusted publishing: no stored API key. nuget.org validates GitHub's OIDC token against the |
| 64 | + # policy naming this repository and this workflow file, and returns a key good for an hour. |
| 65 | + publish: |
| 66 | + needs: build |
| 67 | + if: startsWith(github.ref, 'refs/tags/') |
| 68 | + runs-on: ubuntu-latest |
| 69 | + timeout-minutes: 10 |
| 70 | + permissions: |
| 71 | + contents: read |
| 72 | + id-token: write |
| 73 | + steps: |
| 74 | + - name: Download packages |
| 75 | + uses: actions/download-artifact@v4 |
| 76 | + with: |
| 77 | + name: nupkgs |
| 78 | + path: packages |
| 79 | + |
| 80 | + - name: NuGet login |
| 81 | + id: login |
| 82 | + uses: NuGet/login@v1 |
| 83 | + with: |
| 84 | + user: SimonCropp |
| 85 | + |
| 86 | + - name: Push to nuget.org |
| 87 | + run: > |
| 88 | + dotnet nuget push "packages/**/*.nupkg" |
| 89 | + --api-key ${{ steps.login.outputs.NUGET_API_KEY }} |
| 90 | + --source https://api.nuget.org/v3/index.json |
| 91 | + --skip-duplicate |
0 commit comments