diff --git a/.github/workflows/Steeltoe.All.yml b/.github/workflows/Steeltoe.All.yml index ea38174144..6fcf039cbb 100644 --- a/.github/workflows/Steeltoe.All.yml +++ b/.github/workflows/Steeltoe.All.yml @@ -30,6 +30,7 @@ jobs: name: Build and Test timeout-minutes: 30 strategy: + fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] include: @@ -77,21 +78,12 @@ jobs: shell: bash run: echo "DOTNET_GENERATE_ASPNET_CERTIFICATE=false" >> $GITHUB_ENV - - name: Install Nerdbank.GitVersioning (macOS only) - if: ${{ matrix.os == 'macos-latest' }} - run: dotnet tool install --global nbgv - - name: Git checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Restore packages run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal - - name: Set package version - run: nbgv cloud - - name: Build solution run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal diff --git a/.github/workflows/component-shared-workflow.yml b/.github/workflows/component-shared-workflow.yml index ee58120980..fd4cb781d7 100644 --- a/.github/workflows/component-shared-workflow.yml +++ b/.github/workflows/component-shared-workflow.yml @@ -74,21 +74,12 @@ jobs: shell: bash run: echo "DOTNET_GENERATE_ASPNET_CERTIFICATE=false" >> $GITHUB_ENV - - name: Install Nerdbank.GitVersioning (macOS only) - if: ${{ inputs.OS == 'macos' }} - run: dotnet tool install --global nbgv - - name: Git checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Restore packages run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal - - name: Set package version - run: nbgv cloud - - name: Build solution run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 992d8c4574..6b6dffa26a 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,16 +8,284 @@ on: - '[0-9]+.x' - 'release/*' pull_request: + release: + types: + - published concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + +env: + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_NOLOGO: true + SOLUTION_FILE: 'src/Steeltoe.All.sln' + VERSION_FILE: 'shared-package.props' + jobs: - empty: - name: Empty job + build: + name: Build + timeout-minutes: 15 runs-on: ubuntu-latest steps: - - name: Empty step - run: echo "Packaging using GitHub Actions is not yet implemented." + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 8.0.* + 9.0.* + + - name: Git checkout + uses: actions/checkout@v4 + + - name: Restore packages + run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal + + - name: Calculate package version (for release) + if: ${{ github.event_name == 'release' }} + env: + TAG_NAME: ${{ github.ref_name }} + shell: pwsh + run: | + # Get the version suffix from the git tag. For example: '1.2.3-preview1-final' => 'preview1-final' + $tagSegments = '${{ env.TAG_NAME }}' -split '-' + $versionPrefix = $tagSegments[0] + $versionSuffix = $tagSegments.Length -eq 1 ? '' : $tagSegments[1..$($tagSegments.Length - 1)] -join '-' + + [xml]$xml = Get-Content $env:VERSION_FILE + $configuredVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1 + + if ($configuredVersionPrefix -ne $versionPrefix) { + Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in $env:VERSION_FILE." + # To recover from this: + # - Delete the GitHub release + # - Run: git push --delete origin the-invalid-tag-name + # - Adjust VersionPrefix in file, commit and push + # - Recreate the GitHub release + } + + Write-Output "Using version suffix: $versionSuffix" + Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Calculate package version (for branch) + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} + env: + BRANCH_NAME: ${{ github.ref_name }} + shell: pwsh + run: | + # Get the version suffix from the branch name and auto-incrementing build number. For example: 'main' and '123' => 'main-00123' + $revision = "{0:D5}" -f ${{ github.run_number }} + $branchName = '${{ env.BRANCH_NAME }}' + $safeBranchName = $branchName -Replace '[^a-zA-Z0-9-]', '-' + $versionSuffix = "$safeBranchName-$revision" + + Write-Output "Using version suffix: $versionSuffix" + Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Calculate package version (for pr) + if: ${{ github.event_name == 'pull_request' }} + shell: pwsh + run: | + # Get the version suffix from the PR number and auto-incrementing build number. For example: '18' and '123' => 'pr18-00123' + $revision = "{0:D5}" -f ${{ github.run_number }} + $versionSuffix = "pr${{ github.event.number }}-$revision" + + Write-Output "Using version suffix: $versionSuffix" + Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Verify package version + if: ${{ !env.PACKAGE_VERSION_SUFFIX && github.event_name != 'release' }} + run: | + echo "Package version suffix is empty. This should never happen." + exit 1 + + - name: Build solution + run: dotnet build ${{ env.SOLUTION_FILE }} --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} + + - name: Collect packages + run: dotnet pack ${{ env.SOLUTION_FILE }} --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} + + - name: Upload unsigned packages + uses: actions/upload-artifact@v4 + with: + if-no-files-found: error + name: unsigned-packages + path: ${{ github.workspace }}/packages/**/*.nupkg + + sign: + name: Sign + if: ${{ github.event_name != 'pull_request' }} + timeout-minutes: 15 + needs: build + runs-on: windows-latest + environment: signing + permissions: + id-token: write + + steps: + - name: Download unsigned packages + uses: actions/download-artifact@v4 + with: + name: unsigned-packages + path: packages + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.* + + - name: Install code signing tool + run: dotnet tool install --global sign --prerelease + + - name: Azure login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Sign packages + run: >- + sign code azure-key-vault '**/*.nupkg' + --base-directory '${{ github.workspace }}/packages' + --azure-key-vault-managed-identity true + --azure-credential-type 'azure-cli' + --azure-key-vault-url '${{ secrets.AZURE_KEY_VAULT_URL }}' + --azure-key-vault-certificate '${{ secrets.AZURE_SIGN_CERTIFICATE_ID }}' + --publisher-name 'Steeltoe' + --description 'Steeltoe' + --description-url 'https://steeltoe.io/' + + - name: Upload signed packages + uses: actions/upload-artifact@v4 + with: + if-no-files-found: error + name: signed-packages + path: ${{ github.workspace }}/packages/**/*.nupkg + + dev-feed-deploy: + name: Deploy packages to development feed + timeout-minutes: 15 + needs: sign + if: ${{ github.event_name != 'pull_request' }} + environment: azdo + runs-on: ubuntu-latest + permissions: + id-token: write + env: + VSS_NUGET_URI_PREFIXES: https://pkgs.dev.azure.com/dotnet/ + + steps: + - name: Azure login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Download signed packages + uses: actions/download-artifact@v4 + with: + name: signed-packages + path: packages + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + source-url: ${{ vars.AZURE_ARTIFACTS_FEED_URL }} + env: + NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install credential provider for Azure Artifacts + run: sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)" + + - name: Extract access token + run: | + accessToken=$(az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv) + echo "::add-mask::$accessToken" + echo "ACCESS_TOKEN=$accessToken" >> $GITHUB_ENV + + - name: Configure authentication provider to use Azure DevOps token + run: echo "VSS_NUGET_ACCESSTOKEN=$ACCESS_TOKEN" >> $GITHUB_ENV + + - name: Push packages to Azure Artifacts + run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key 'azdo-placeholder' --source '${{ vars.AZURE_ARTIFACTS_FEED_URL }}' + + nuget-org-deploy: + name: Deploy packages to nuget.org + needs: sign + if: ${{ github.event_name == 'release' }} + environment: nuget.org + runs-on: ubuntu-latest + + steps: + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Download signed packages + uses: actions/download-artifact@v4 + with: + name: signed-packages + path: packages + + - name: Push packages to nuget.org + run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --api-key '${{ secrets.STEELTOE_NUGET_API_KEY }}' --source 'nuget.org' + + open_pr: + name: Open pull request to bump Steeltoe version after release + needs: nuget-org-deploy + timeout-minutes: 15 + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Git checkout + uses: actions/checkout@v4 + + - name: Calculate next package version + shell: pwsh + run: | + [xml]$xml = Get-Content $env:VERSION_FILE + $oldVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1 + + $versionSegments = $oldVersionPrefix.split('.') + ([int]$versionSegments[-1])++ + $newVersionPrefix = $versionSegments -join('.') + + Write-Output "OLD_PACKAGE_VERSION_PREFIX=$oldVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "NEW_PACKAGE_VERSION_PREFIX=$newVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Open pull request + env: + GH_TOKEN: ${{ github.token }} + shell: pwsh + run: | + $oldVersionPrefix = '${{ env.OLD_PACKAGE_VERSION_PREFIX }}' + $newVersionPrefix = '${{ env.NEW_PACKAGE_VERSION_PREFIX }}' + $prBranchName = "bump-version-to-$newVersionPrefix-${{ github.run_number }}" + $commitMessage = "Bump Steeltoe version from $oldVersionPrefix to $newVersionPrefix." + + $pattern = '(?^\s*\)[^>]+(?\<\/VersionPrefix\>)\s*$' + $fileContent = Get-Content $env:VERSION_FILE + $fileContent = $fileContent -Replace $pattern,"`${left}$newVersionPrefix`${right}" + Set-Content $fileContent -Path $env:VERSION_FILE + + Write-Output "Creating pull request for commit: $commitMessage" + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git checkout -b $prBranchName + git add -A + git commit -m $commitMessage + git push --set-upstream origin $prBranchName + + Write-Output "Opening pull request to merge $prBranchName." + gh pr create --head $prBranchName --title 'Bump Steeltoe version' --body $commitMessage diff --git a/.github/workflows/sonarcube.yml b/.github/workflows/sonarcube.yml index 493d9e5b2b..16fd24aae3 100644 --- a/.github/workflows/sonarcube.yml +++ b/.github/workflows/sonarcube.yml @@ -67,9 +67,6 @@ jobs: - name: Restore packages run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal - - name: Set package version - run: nbgv cloud - - name: Begin Sonar .NET scanner id: sonar_begin env: diff --git a/.github/workflows/verify-code-style.yml b/.github/workflows/verify-code-style.yml index 2da29b7889..d156a08ebf 100644 --- a/.github/workflows/verify-code-style.yml +++ b/.github/workflows/verify-code-style.yml @@ -37,7 +37,7 @@ jobs: - name: Git checkout uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 2 - name: Restore tools run: dotnet tool restore --verbosity minimal @@ -45,9 +45,6 @@ jobs: - name: Restore packages run: dotnet restore ${{ env.SOLUTION_FILE }} --verbosity minimal - - name: Set package version - run: nbgv cloud - - name: CleanupCode (on PR diff) if: ${{ github.event_name == 'pull_request' }} shell: pwsh @@ -61,7 +58,7 @@ jobs: dotnet regitlint -s ${{ env.SOLUTION_FILE }} --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="Steeltoe Full Cleanup" --jb --properties:Configuration=Release --jb --properties:RunAnalyzers=false --jb --properties:NuGetAudit=false --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff - name: CleanupCode (on branch) - if: ${{ github.event_name == 'push' || github.event_name == 'release' }} + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'release' }} shell: pwsh run: | Write-Output "Running code cleanup on all files." diff --git a/README.md b/README.md index e479a694fc..b261d6d006 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ If you want to try the latest bits from the `main` branch, use the Steeltoe deve - + diff --git a/build/package.yml b/build/package.yml deleted file mode 100644 index 56b1c3e9cd..0000000000 --- a/build/package.yml +++ /dev/null @@ -1,96 +0,0 @@ -trigger: - branches: - include: - - main - - release/* - paths: - exclude: - - README.md - - roadmaps/* - -jobs: -- job: Steeltoe_Package - pool: - vmImage: windows-latest - variables: - DOTNET_NOLOGO: true - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - steps: - - checkout: self - fetchDepth: 0 - - task: UseDotNet@2 - displayName: Install .NET 8 - inputs: - version: 8.0.x - - task: UseDotNet@2 - displayName: Install .NET 9 - inputs: - version: 9.0.x - - task: PowerShell@2 - displayName: Set package version - env: - PackageVersionOverride: $(PackageVersionOverride) - inputs: - targetType: 'inline' - script: | - if ($env:PackageVersionOverride) { - Write-Host "Overriding package version with: $env:PackageVersionOverride" - Write-Warning "Always provide a 4-segment version (such as 1.2.3.0 or 1.2.3.0-rc1), to prevent an increment in patch number." - Write-Warning "The commit hash may still be added to the version, depending on the source branch or PR being built." - nbgv set-version $env:PackageVersionOverride - - Write-Host "Contents of version.json after update:" - get-content version.json - - git config --global user.email "cibuild@steeltoe.io" - git config --global user.name "steeltoe-cibuild" - git commit --allow-empty -m "Activating version override by locally committing changes to version.json." - } - - nbgv cloud - - task: DotNetCoreCLI@2 - displayName: dotnet restore - inputs: - command: restore - verbosityRestore: Minimal - projects: src/Steeltoe.All.sln - feedsToUse: config - nugetConfigPath: nuget.config - - task: DotNetCoreCLI@2 - displayName: dotnet build - inputs: - command: build - projects: src/Steeltoe.All.sln - arguments: --no-restore -c Release -v minimal - - task: DotNetCoreCLI@2 - displayName: dotnet pack - inputs: - command: pack - verbosityPack: Minimal - packagesToPack: src/Steeltoe.All.sln - configuration: Release - packDirectory: $(Build.ArtifactStagingDirectory)/packages - nobuild: true - - task: DotNetCoreCLI@2 - condition: and(succeeded(), not(eq(variables['build.reason'], 'PullRequest'))) - inputs: - command: custom - custom: tool - arguments: install --tool-path . sign --prerelease - displayName: Install code signing tool - - pwsh: | - .\sign code azure-key-vault "**/*.nupkg" ` - --base-directory "$(Build.ArtifactStagingDirectory)/packages" ` - --azure-key-vault-url "$(SignKeyVaultUrl)" ` - --azure-key-vault-tenant-id "$(SignTenantId)" ` - --azure-key-vault-client-id "$(SignClientId)" ` - --azure-key-vault-client-secret "$(SignClientSecret)" ` - --azure-key-vault-certificate "$(SignKeyVaultCertificate)" ` - --description "Steeltoe" ` - --description-url "https://github.com/SteeltoeOSS" - condition: and(succeeded(), not(eq(variables['build.reason'], 'PullRequest'))) - displayName: Sign packages - - publish: $(Build.ArtifactStagingDirectory)/packages - condition: succeeded() - displayName: Publish build artifacts - artifact: Packages diff --git a/shared-package.props b/shared-package.props index 21a8eaf032..721a23607d 100644 --- a/shared-package.props +++ b/shared-package.props @@ -12,6 +12,8 @@ + 4.0.0 + pre Broadcom PackageIcon.png https://steeltoe.io @@ -31,7 +33,7 @@ True - +