|
| 1 | +name: Publish NuGet Packages |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'Package version (e.g. 3.1.0, 3.1.0-preview.1). Leave empty to derive from tag or branch.' |
| 11 | + required: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + packages: write |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + runs-on: windows-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Setup .NET |
| 28 | + uses: actions/setup-dotnet@v4 |
| 29 | + with: |
| 30 | + dotnet-version: | |
| 31 | + 6.0.x |
| 32 | + 8.0.x |
| 33 | +
|
| 34 | + - name: Determine version |
| 35 | + id: version |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + if [[ -n "${{ github.event.inputs.version }}" ]]; then |
| 39 | + VERSION="${{ github.event.inputs.version }}" |
| 40 | + elif [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 41 | + # Strip leading 'v' from tag (v3.1.0 -> 3.1.0) |
| 42 | + VERSION="${{ github.ref_name }}" |
| 43 | + VERSION="${VERSION#v}" |
| 44 | + else |
| 45 | + # Fallback: use VersionPrefix from Global.props + short SHA for pre-release |
| 46 | + VERSION="3.0.0-dev.${{ github.run_number }}" |
| 47 | + fi |
| 48 | + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" |
| 49 | + echo "Resolved version: $VERSION" |
| 50 | +
|
| 51 | + - name: Restore dependencies |
| 52 | + run: dotnet restore |
| 53 | + |
| 54 | + - name: Build |
| 55 | + run: dotnet build --configuration Release --no-restore /p:Version=${{ steps.version.outputs.VERSION }} |
| 56 | + |
| 57 | + - name: Run tests |
| 58 | + run: dotnet test --configuration Release --no-build --verbosity normal |
| 59 | + |
| 60 | + - name: Pack NuGet packages |
| 61 | + run: dotnet pack --configuration Release --no-build --output ./nupkgs /p:Version=${{ steps.version.outputs.VERSION }} |
| 62 | + |
| 63 | + - name: Push to GitHub Packages |
| 64 | + run: dotnet nuget push "./nupkgs/*.nupkg" --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate |
| 65 | + env: |
| 66 | + DOTNET_NOLOGO: true |
| 67 | + |
| 68 | + - name: Upload packages as artifact |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: nuget-packages |
| 72 | + path: ./nupkgs/ |
| 73 | + retention-days: 30 |
0 commit comments