|
8 | 8 | - '[0-9]+.x' |
9 | 9 | - 'release/*' |
10 | 10 | pull_request: |
| 11 | + release: |
| 12 | + types: |
| 13 | + - published |
11 | 14 |
|
12 | 15 | concurrency: |
13 | 16 | group: ${{ github.workflow }}-${{ github.ref }} |
14 | 17 | cancel-in-progress: true |
15 | 18 |
|
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +env: |
| 23 | + DOTNET_CLI_TELEMETRY_OPTOUT: 1 |
| 24 | + DOTNET_NOLOGO: true |
| 25 | + SOLUTION_FILE: 'src/Steeltoe.All.sln' |
| 26 | + VERSION_FILE: 'shared-package.props' |
| 27 | + |
16 | 28 | jobs: |
17 | | - empty: |
18 | | - name: Empty job |
| 29 | + build: |
| 30 | + name: Build |
| 31 | + timeout-minutes: 15 |
19 | 32 | runs-on: ubuntu-latest |
20 | 33 |
|
21 | 34 | steps: |
22 | | - - name: Empty step |
23 | | - run: echo "Packaging using GitHub Actions is not yet implemented." |
| 35 | + - name: Setup .NET |
| 36 | + uses: actions/setup-dotnet@v4 |
| 37 | + with: |
| 38 | + dotnet-version: | |
| 39 | + 8.0.* |
| 40 | + 9.0.* |
| 41 | +
|
| 42 | + - name: Git checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Restore packages |
| 46 | + run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal |
| 47 | + |
| 48 | + - name: Calculate package version (for release) |
| 49 | + if: ${{ github.event_name == 'release' }} |
| 50 | + env: |
| 51 | + TAG_NAME: ${{ github.ref_name }} |
| 52 | + shell: pwsh |
| 53 | + run: | |
| 54 | + # Get the version suffix from the git tag. For example: '1.2.3-preview1-final' => 'preview1-final' |
| 55 | + $tagSegments = '${{ env.TAG_NAME }}' -split '-' |
| 56 | + $versionPrefix = $tagSegments[0] |
| 57 | + $versionSuffix = $tagSegments.Length -eq 1 ? '' : $tagSegments[1..$($tagSegments.Length - 1)] -join '-' |
| 58 | +
|
| 59 | + [xml]$xml = Get-Content $env:VERSION_FILE |
| 60 | + $configuredVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1 |
| 61 | +
|
| 62 | + if ($configuredVersionPrefix -ne $versionPrefix) { |
| 63 | + Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in $env:VERSION_FILE." |
| 64 | + # To recover from this: |
| 65 | + # - Delete the GitHub release |
| 66 | + # - Run: git push --delete origin the-invalid-tag-name |
| 67 | + # - Adjust VersionPrefix in file, commit and push |
| 68 | + # - Recreate the GitHub release |
| 69 | + } |
| 70 | +
|
| 71 | + Write-Output "Using version suffix: $versionSuffix" |
| 72 | + Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 73 | +
|
| 74 | + - name: Calculate package version (for branch) |
| 75 | + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} |
| 76 | + env: |
| 77 | + BRANCH_NAME: ${{ github.ref_name }} |
| 78 | + shell: pwsh |
| 79 | + run: | |
| 80 | + # Get the version suffix from the branch name and auto-incrementing build number. For example: 'main' and '123' => 'main-00123' |
| 81 | + $revision = "{0:D5}" -f ${{ github.run_number }} |
| 82 | + $branchName = '${{ env.BRANCH_NAME }}' |
| 83 | + $safeBranchName = $branchName -Replace '[^a-zA-Z0-9-]', '-' |
| 84 | + $versionSuffix = "$safeBranchName-$revision" |
| 85 | +
|
| 86 | + Write-Output "Using version suffix: $versionSuffix" |
| 87 | + Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 88 | +
|
| 89 | + - name: Calculate package version (for pr) |
| 90 | + if: ${{ github.event_name == 'pull_request' }} |
| 91 | + shell: pwsh |
| 92 | + run: | |
| 93 | + # Get the version suffix from the PR number and auto-incrementing build number. For example: '18' and '123' => 'pr18-00123' |
| 94 | + $revision = "{0:D5}" -f ${{ github.run_number }} |
| 95 | + $versionSuffix = "pr${{ github.event.number }}-$revision" |
| 96 | +
|
| 97 | + Write-Output "Using version suffix: $versionSuffix" |
| 98 | + Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 99 | +
|
| 100 | + - name: Verify package version |
| 101 | + if: ${{ env.PACKAGE_VERSION_SUFFIX == '' && github.event_name != 'release' }} |
| 102 | + run: | |
| 103 | + echo "Package version suffix is empty. This should never happen." |
| 104 | + exit 1 |
| 105 | +
|
| 106 | + - name: Build solution |
| 107 | + run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} |
| 108 | + |
| 109 | + - name: Collect packages |
| 110 | + run: dotnet pack ${{ env.SOLUTION_FILE }} --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} |
| 111 | + |
| 112 | + - name: Upload unsigned packages |
| 113 | + uses: actions/upload-artifact@v4 |
| 114 | + with: |
| 115 | + if-no-files-found: error |
| 116 | + name: unsigned-packages |
| 117 | + path: ${{ github.workspace }}/packages/**/*.nupkg |
| 118 | + |
| 119 | + sign: |
| 120 | + name: Sign |
| 121 | + if: ${{ github.event_name != 'pull_request' }} |
| 122 | + timeout-minutes: 15 |
| 123 | + needs: build |
| 124 | + runs-on: windows-latest |
| 125 | + environment: signing |
| 126 | + permissions: |
| 127 | + id-token: write |
| 128 | + |
| 129 | + steps: |
| 130 | + - name: Download unsigned packages |
| 131 | + uses: actions/download-artifact@v4 |
| 132 | + with: |
| 133 | + name: unsigned-packages |
| 134 | + path: packages |
| 135 | + |
| 136 | + - name: Setup .NET |
| 137 | + uses: actions/setup-dotnet@v4 |
| 138 | + with: |
| 139 | + dotnet-version: 8.0.* |
| 140 | + |
| 141 | + - name: Install code signing tool |
| 142 | + run: dotnet tool install --global sign --prerelease |
| 143 | + |
| 144 | + - name: Azure login |
| 145 | + uses: azure/login@v2 |
| 146 | + with: |
| 147 | + client-id: ${{ secrets.AZURE_KEY_VAULT_CLIENT_ID }} |
| 148 | + tenant-id: ${{ secrets.AZURE_KEY_VAULT_TENANT_ID }} |
| 149 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 150 | + |
| 151 | + - name: Sign packages |
| 152 | + run: >- |
| 153 | + sign code azure-key-vault '**/*.nupkg' |
| 154 | + --base-directory '${{ github.workspace }}/packages' |
| 155 | + --azure-key-vault-managed-identity true |
| 156 | + --azure-credential-type 'azure-cli' |
| 157 | + --azure-key-vault-url '${{ secrets.AZURE_KEY_VAULT_URL }}' |
| 158 | + --azure-key-vault-certificate '${{ secrets.AZURE_KEY_VAULT_CERTIFICATE_ID }}' |
| 159 | + --publisher-name 'Steeltoe' |
| 160 | + --description 'Steeltoe' |
| 161 | + --description-url 'https://steeltoe.io/' |
| 162 | +
|
| 163 | + - name: Upload signed packages |
| 164 | + uses: actions/upload-artifact@v4 |
| 165 | + with: |
| 166 | + if-no-files-found: error |
| 167 | + name: signed-packages |
| 168 | + path: ${{ github.workspace }}/packages/**/*.nupkg |
| 169 | + |
| 170 | + dev-feed-deploy: |
| 171 | + name: Deploy packages to development feed |
| 172 | + timeout-minutes: 15 |
| 173 | + needs: sign |
| 174 | + if: ${{ github.event_name != 'pull_request' }} |
| 175 | + environment: azdo |
| 176 | + runs-on: ubuntu-latest |
| 177 | + permissions: |
| 178 | + id-token: write |
| 179 | + env: |
| 180 | + VSS_NUGET_URI_PREFIXES: https://pkgs.dev.azure.com/dotnet/ |
| 181 | + |
| 182 | + steps: |
| 183 | + - name: Azure login |
| 184 | + uses: azure/login@v2 |
| 185 | + with: |
| 186 | + client-id: ${{ secrets.AZURE_KEY_VAULT_CLIENT_ID }} |
| 187 | + tenant-id: ${{ secrets.AZURE_KEY_VAULT_TENANT_ID }} |
| 188 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 189 | + |
| 190 | + - name: Download signed packages |
| 191 | + uses: actions/download-artifact@v4 |
| 192 | + with: |
| 193 | + name: signed-packages |
| 194 | + path: packages |
| 195 | + |
| 196 | + - name: Setup .NET |
| 197 | + uses: actions/setup-dotnet@v4 |
| 198 | + with: |
| 199 | + dotnet-version: 8.0.x |
| 200 | + source-url: ${{ vars.AZURE_ARTIFACTS_FEED_URL }} |
| 201 | + env: |
| 202 | + NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 203 | + |
| 204 | + - name: Install credential provider for Azure Artifacts |
| 205 | + run: sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)" |
| 206 | + |
| 207 | + - name: Extract access token |
| 208 | + run: | |
| 209 | + accessToken=$(az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv) |
| 210 | + echo "::add-mask::$accessToken" |
| 211 | + echo "ACCESS_TOKEN=$accessToken" >> $GITHUB_ENV |
| 212 | +
|
| 213 | + - name: Configure authentication provider to use Azure DevOps token |
| 214 | + run: echo "VSS_NUGET_ACCESSTOKEN=$ACCESS_TOKEN" >> $GITHUB_ENV |
| 215 | + |
| 216 | + - name: Push packages to Azure Artifacts |
| 217 | + run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key 'azdo-placeholder' --source '${{ vars.AZURE_ARTIFACTS_FEED_URL }}' |
| 218 | + |
| 219 | + nuget-org-deploy: |
| 220 | + name: Deploy packages to nuget.org |
| 221 | + needs: sign |
| 222 | + if: ${{ github.event_name == 'release' }} |
| 223 | + environment: nuget.org |
| 224 | + runs-on: ubuntu-latest |
| 225 | + |
| 226 | + steps: |
| 227 | + - name: Setup .NET |
| 228 | + uses: actions/setup-dotnet@v4 |
| 229 | + with: |
| 230 | + dotnet-version: 8.0.x |
| 231 | + |
| 232 | + - name: Download signed packages |
| 233 | + uses: actions/download-artifact@v4 |
| 234 | + with: |
| 235 | + name: signed-packages |
| 236 | + path: packages |
| 237 | + |
| 238 | + - name: Push packages to nuget.org |
| 239 | + run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.STEELTOE_NUGET_API_KEY }}' --source 'nuget.org' |
| 240 | + |
| 241 | + open_pr: |
| 242 | + name: Open pull request to bump Steeltoe version after release |
| 243 | + needs: nuget-org-deploy |
| 244 | + timeout-minutes: 15 |
| 245 | + runs-on: ubuntu-latest |
| 246 | + permissions: |
| 247 | + contents: write |
| 248 | + pull-requests: write |
| 249 | + |
| 250 | + steps: |
| 251 | + - name: Git checkout |
| 252 | + uses: actions/checkout@v4 |
| 253 | + |
| 254 | + - name: Calculate next package version |
| 255 | + shell: pwsh |
| 256 | + run: | |
| 257 | + [xml]$xml = Get-Content $env:VERSION_FILE |
| 258 | + $oldVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1 |
| 259 | +
|
| 260 | + $versionSegments = $oldVersionPrefix.split('.') |
| 261 | + ([int]$versionSegments[-1])++ |
| 262 | + $newVersionPrefix = $versionSegments -join('.') |
| 263 | +
|
| 264 | + Write-Output "OLD_PACKAGE_VERSION_PREFIX=$oldVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 265 | + Write-Output "NEW_PACKAGE_VERSION_PREFIX=$newVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 266 | +
|
| 267 | + - name: Open pull request |
| 268 | + env: |
| 269 | + GH_TOKEN: ${{ github.token }} |
| 270 | + shell: pwsh |
| 271 | + run: | |
| 272 | + $oldVersionPrefix = '${{ env.OLD_PACKAGE_VERSION_PREFIX }}' |
| 273 | + $newVersionPrefix = '${{ env.NEW_PACKAGE_VERSION_PREFIX }}' |
| 274 | + $prBranchName = "bump-version-to-$newVersionPrefix-${{ github.run_number }}" |
| 275 | + $commitMessage = "Bump Steeltoe version from $oldVersionPrefix to $newVersionPrefix." |
| 276 | +
|
| 277 | + $pattern = '(?<left>^\s*\<VersionPrefix\>)[^>]+(?<right>\<\/VersionPrefix\>)\s*$' |
| 278 | + $fileContent = Get-Content $env:VERSION_FILE |
| 279 | + $fileContent = $fileContent -Replace $pattern,"`${left}$newVersionPrefix`${right}" |
| 280 | + Set-Content $fileContent -Path $env:VERSION_FILE |
| 281 | +
|
| 282 | + Write-Output "Creating pull request for commit: $commitMessage" |
| 283 | + git config --global user.name '${{ env.GIT_USERNAME }}' |
| 284 | + git config --global user.email '${{ env.GIT_USERNAME }}@noreply.github.com' |
| 285 | + git checkout -b $prBranchName |
| 286 | + git add -A |
| 287 | + git commit -m $commitMessage |
| 288 | + git push --set-upstream origin $prBranchName |
| 289 | +
|
| 290 | + Write-Output "Opening pull request to merge $prBranchName." |
| 291 | + gh pr create --head $prBranchName --title 'Bump Steeltoe version' --body $commitMessage |
0 commit comments