|
| 1 | +name: Action to build and publish the project as a nuget package to github package registry |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + outputs: |
| 11 | + Version: ${{ steps.gitversion.outputs.SemVer }} |
| 12 | + CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }} |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + with: |
| 17 | + fetch-depth: 0 #fetch-depth is needed for GitVersion |
| 18 | + |
| 19 | + #Install and calculate the new version with GitVersion |
| 20 | + - name: Install GitVersion |
| 21 | + uses: gittools/actions/gitversion/setup@v0.9.7 |
| 22 | + with: |
| 23 | + versionSpec: 5.x |
| 24 | + - name: Determine Version |
| 25 | + uses: gittools/actions/gitversion/execute@v0.9.7 |
| 26 | + id: gitversion # step id used as reference for output values |
| 27 | + - name: Display GitVersion outputs |
| 28 | + run: | |
| 29 | + echo "Version: ${{ steps.gitversion.outputs.SemVer }}" |
| 30 | + echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}" |
| 31 | + |
| 32 | + #Build/pack the project |
| 33 | + - name: Setup .NET |
| 34 | + uses: actions/setup-dotnet@v1 |
| 35 | + with: |
| 36 | + dotnet-version: 7.0.x |
| 37 | + - name: Build and Pack NuGet package |
| 38 | + run: dotnet pack IdentityServer7.EntityFramework.csproj -p:Version='${{ steps.gitversion.outputs.SemVer }}' -c Release |
| 39 | + - name: Upload NuGet package to GitHub |
| 40 | + uses: actions/upload-artifact@v2 |
| 41 | + with: |
| 42 | + name: nugetPackage |
| 43 | + path: bin/Release/ |
| 44 | + |
| 45 | + release: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: build |
| 48 | + steps: |
| 49 | + #Push NuGet package to GitHub packages |
| 50 | + - name: Download nuget package artifact |
| 51 | + uses: actions/download-artifact@v1.0.0 |
| 52 | + with: |
| 53 | + name: nugetPackage |
| 54 | + - name: Prep packages |
| 55 | + run: dotnet nuget add source --username fegomes --password ${{ secrets.NUGET_PACKAGE_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/fegomes/index.json" |
| 56 | + - name: Push package to GitHub packages |
| 57 | + if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change |
| 58 | + run: dotnet nuget push nugetPackage/*.nupkg --api-key ${{ secrets.NUGET_PACKAGE_TOKEN }} --source "github" |
| 59 | + |
| 60 | + #Create release |
| 61 | + - name: Create Release |
| 62 | + if: 1 == 0 #needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change |
| 63 | + uses: actions/create-release@v1 |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ secrets.NUGET_PACKAGE_TOKEN }} |
| 66 | + with: |
| 67 | + tag_name: ${{ needs.build.outputs.Version }} |
| 68 | + release_name: Release ${{ needs.build.outputs.Version }} |
| 69 | + - name: Create Release |
| 70 | + if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change |
| 71 | + uses: ncipollo/release-action@v1 |
| 72 | + with: |
| 73 | + tag: ${{ needs.build.outputs.Version }} |
| 74 | + name: Release ${{ needs.build.outputs.Version }} |
| 75 | + artifacts: "nugetPackage/*" |
| 76 | + token: ${{ secrets.NUGET_PACKAGE_TOKEN }} |
0 commit comments