|
| 1 | +name: Release (Stable) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - release/** |
| 7 | + - release |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + packages: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + working-directory: ${{ github.workspace }} |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Setup .NET |
| 26 | + uses: actions/setup-dotnet@v4 |
| 27 | + with: |
| 28 | + dotnet-version: 9.0.x |
| 29 | + |
| 30 | + - name: Install GitVersion |
| 31 | + uses: gittools/actions/gitversion/setup@v0.9.15 |
| 32 | + with: |
| 33 | + versionSpec: 5.x |
| 34 | + |
| 35 | + - name: Determine Version |
| 36 | + id: gitversion |
| 37 | + uses: gittools/actions/gitversion/execute@v0.9.15 |
| 38 | + with: |
| 39 | + useConfigFile: true |
| 40 | + |
| 41 | + - name: Display Version |
| 42 | + run: | |
| 43 | + echo "FullSemVer: ${{ steps.gitversion.outputs.FullSemVer }}" |
| 44 | + echo "NuGetVersionV2: ${{ steps.gitversion.outputs.NuGetVersionV2 }}" |
| 45 | + echo "IsPreRelease? ${{ steps.gitversion.outputs.PreReleaseTag != '' }}" |
| 46 | +
|
| 47 | + - name: Fail if Pre-release on main |
| 48 | + if: ${{ steps.gitversion.outputs.PreReleaseTag != '' }} |
| 49 | + run: | |
| 50 | + echo "Unexpected pre-release on main. Check GitVersion config." |
| 51 | + exit 1 |
| 52 | +
|
| 53 | + - name: Restore |
| 54 | + run: dotnet restore |
| 55 | + working-directory: '${{ env.working-directory }}' |
| 56 | + |
| 57 | + - name: Build |
| 58 | + run: dotnet build -c Release --no-restore |
| 59 | + working-directory: '${{ env.working-directory }}' |
| 60 | + |
| 61 | + - name: Test |
| 62 | + run: dotnet test -c Release --no-build |
| 63 | + working-directory: '${{ env.working-directory }}' |
| 64 | + |
| 65 | + - name: Pack Stable |
| 66 | + run: | |
| 67 | + dotnet pack src/MyLibrary/MyLibrary.csproj \ |
| 68 | + -c Release -o artifacts \ |
| 69 | + /p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }} |
| 70 | +
|
| 71 | + - name: Create Tag (if missing) |
| 72 | + run: | |
| 73 | + TAG="v${{ steps.gitversion.outputs.MajorMinorPatch }}" |
| 74 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 75 | + echo "Tag $TAG already exists." |
| 76 | + else |
| 77 | + git tag "$TAG" |
| 78 | + git push origin "$TAG" |
| 79 | + fi |
| 80 | +
|
| 81 | + - name: Add GitHub Packages Source |
| 82 | + run: | |
| 83 | + dotnet nuget add source \ |
| 84 | + --username $GITHUB_ACTOR \ |
| 85 | + --password ${{ secrets.GITHUB_TOKEN }} \ |
| 86 | + --store-password-in-clear-text \ |
| 87 | + --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" |
| 88 | +
|
| 89 | + - name: Publish to GitHub Packages |
| 90 | + run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate |
| 91 | + |
| 92 | + - name: Publish to NuGet |
| 93 | + if: ${{ startsWith(github.head_ref, 'release/')}} |
| 94 | + env: |
| 95 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 96 | + run: | |
| 97 | + dotnet nuget push "artifacts/*.nupkg" \ |
| 98 | + --api-key "$NUGET_API_KEY" \ |
| 99 | + --source https://api.nuget.org/v3/index.json \ |
| 100 | + --skip-duplicate |
0 commit comments