|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - release/* |
| 7 | + - main |
| 8 | + workflow_dispatch: #option to manually trigger action |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + |
| 15 | + Build: |
| 16 | + if: "!contains(github.event.head_commit.message, 'nobuild')" |
| 17 | + runs-on: windows-latest |
| 18 | + |
| 19 | + outputs: |
| 20 | + gitversion_semver: ${{ steps.gitversion.outputs.semver }} |
| 21 | + gitversion_nugetversion: ${{ steps.gitversion.outputs.nugetversion }} |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout codegit v |
| 25 | + uses: actions/checkout@v4.1.7 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Setup GitVersion |
| 30 | + uses: gittools/actions/gitversion/setup@v1.2.0 |
| 31 | + with: |
| 32 | + versionSpec: '5.x' |
| 33 | + |
| 34 | + - name: Execute GitVersion |
| 35 | + id: gitversion |
| 36 | + uses: gittools/actions/gitversion/execute@v1.2.0 |
| 37 | + |
| 38 | + - name: Setup NuGet |
| 39 | + uses: NuGet/setup-nuget@v2.0.0 |
| 40 | + |
| 41 | + - name: NuGet restore |
| 42 | + run: nuget restore |
| 43 | + |
| 44 | + - name: Build DotNet |
| 45 | + run: dotnet build -c Release |
| 46 | + |
| 47 | + - name: Pack Projects |
| 48 | + run: dotnet pack --output artifacts --configuration Release /p:PackageVersion=${{ steps.gitversion.outputs.nugetversion }} |
| 49 | + |
| 50 | + - name: Publish NuGet Build Artifacts |
| 51 | + uses: actions/upload-artifact@v4.3.4 |
| 52 | + with: |
| 53 | + name: nuget |
| 54 | + path: ./artifacts/*.nupkg |
| 55 | + retention-days: 1 |
| 56 | + overwrite: true |
| 57 | + |
| 58 | + Deploy_GitHub_Packages: |
| 59 | + needs: Build |
| 60 | + runs-on: windows-latest |
| 61 | + |
| 62 | + steps: |
| 63 | + |
| 64 | + - name: Download a Build Artifact |
| 65 | + uses: actions/download-artifact@v4.1.8 |
| 66 | + with: |
| 67 | + name: nuget |
| 68 | + path: ./artifacts |
| 69 | + |
| 70 | + - name: Get Secrets |
| 71 | + uses: bitwarden/sm-action@v2 |
| 72 | + with: |
| 73 | + access_token: ${{ secrets.BW_ACCESSTOKEN }} |
| 74 | + base_url: https://vault.bitwarden.com |
| 75 | + secrets: | |
| 76 | + f8a86ea6-660e-47d2-917b-b1b800da920e > NUGETORG_API_KEY |
| 77 | + 23f1414f-95aa-4da0-bda7-b1c7015948a5 > GITHUB_PAT |
| 78 | +
|
| 79 | + - name: Push NuGet Packages |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + shopt -s globstar |
| 83 | + for PACKAGE_FILE in ./artifacts/*.nupkg; do |
| 84 | + echo "Pushing $PACKAGE_FILE" |
| 85 | + dotnet nuget push "$PACKAGE_FILE" --api-key ${{ env.GITHUB_PAT }} --source "https://nuget.pkg.github.com/bretleasure/index.json" |
| 86 | + done |
| 87 | +
|
| 88 | + Deploy_NuGet-org: |
| 89 | + needs: Build |
| 90 | + runs-on: windows-latest |
| 91 | + |
| 92 | + steps: |
| 93 | + |
| 94 | + - name: Download a Build Artifact |
| 95 | + uses: actions/download-artifact@v4.1.8 |
| 96 | + with: |
| 97 | + name: nuget |
| 98 | + path: ./artifacts |
| 99 | + |
| 100 | + - name: Get Secrets |
| 101 | + uses: bitwarden/sm-action@v2 |
| 102 | + with: |
| 103 | + access_token: ${{ secrets.BW_ACCESSTOKEN }} |
| 104 | + base_url: https://vault.bitwarden.com |
| 105 | + secrets: | |
| 106 | + f8a86ea6-660e-47d2-917b-b1b800da920e > NUGETORG_API_KEY |
| 107 | + 23f1414f-95aa-4da0-bda7-b1c7015948a5 > GITHUB_PAT |
| 108 | +
|
| 109 | + - name: Push NuGet Packages |
| 110 | + shell: bash |
| 111 | + run: | |
| 112 | + shopt -s globstar |
| 113 | + for PACKAGE_FILE in ./artifacts/*.nupkg; do |
| 114 | + echo "Pushing $PACKAGE_FILE" |
| 115 | + dotnet nuget push "$PACKAGE_FILE" --api-key ${{ env.NUGETORG_API_KEY }} --source "https://api.nuget.org/v3/index.json" |
| 116 | + done |
| 117 | + |
| 118 | + Create_Release: |
| 119 | + needs: Build |
| 120 | + runs-on: windows-latest |
| 121 | + steps: |
| 122 | + - name: Get Secrets |
| 123 | + uses: bitwarden/sm-action@v2 |
| 124 | + with: |
| 125 | + access_token: ${{ secrets.BW_ACCESSTOKEN }} |
| 126 | + base_url: https://vault.bitwarden.com |
| 127 | + secrets: | |
| 128 | + f8a86ea6-660e-47d2-917b-b1b800da920e > NUGETORG_API_KEY |
| 129 | + 23f1414f-95aa-4da0-bda7-b1c7015948a5 > GITHUB_PAT |
| 130 | + |
| 131 | + - name: Create Tag |
| 132 | + uses: negz/create-tag@v1 |
| 133 | + with: |
| 134 | + token: ${{ env.GITHUB_PAT }} |
| 135 | + version: ${{ needs.Build.outputs.gitversion_semver }} |
| 136 | + message: ${{ needs.Build.outputs.gitversion_semver }} |
| 137 | + |
| 138 | + - name: Create GitHub Release |
| 139 | + if: github.ref == 'refs/heads/main' |
| 140 | + uses: ncipollo/release-action@v1 |
| 141 | + with: |
| 142 | + tag: ${{ needs.Build.outputs.gitversion_semver }} |
| 143 | + prerelease: false |
| 144 | + artifacts: "./artifacts/**.zip" |
| 145 | + generateReleaseNotes: true |
| 146 | + |
| 147 | + - name: Create GitHub Pre-Release |
| 148 | + if: github.ref != 'refs/heads/main' |
| 149 | + uses: ncipollo/release-action@v1 |
| 150 | + with: |
| 151 | + tag: ${{ needs.Build.outputs.gitversion_semver }} |
| 152 | + prerelease: true |
| 153 | + artifacts: "./artifacts/**.zip" |
| 154 | + generateReleaseNotes: true |
0 commit comments