diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json deleted file mode 100644 index 742ea6b..0000000 --- a/.config/dotnet-tools.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "version": 1, - "isRoot": true, - "tools": { - "nbgv": { - "version": "3.7.115", - "commands": [ - "nbgv" - ], - "rollForward": false - } - } -} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 540febf..163d085 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,6 +23,7 @@ permissions: env: DOTNET_CLI_TELEMETRY_OPTOUT: 1 DOTNET_NOLOGO: true + VERSION_FILE: 'src/Steeltoe.NetCoreTool.Templates.csproj' jobs: build-and-test: @@ -45,24 +46,77 @@ jobs: - name: Git checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Restore tools - run: dotnet tool restore - name: Restore packages run: dotnet restore --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 --no-restore --configuration Release --verbosity minimal + run: dotnet build --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} - - name: Test - run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true" +# TODO: Revert after testing +# - name: Test +# run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true" - name: Collect packages - shell: pwsh - run: dotnet pack src --no-build --configuration Release --output ${{ github.workspace }}/packages + run: dotnet pack src --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }} - name: Upload unsigned packages if: ${{ matrix.os == 'ubuntu-latest' }} @@ -104,17 +158,18 @@ jobs: 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/' +# TODO: Revert after testing +# - 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 @@ -169,8 +224,9 @@ jobs: - 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 }}' +# TODO: Revert after testing +# - 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 @@ -191,5 +247,59 @@ jobs: name: signed-packages path: packages - - name: Push packages to nuget.org - run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --skip-duplicate --api-key ${{ secrets.STEELTOE_NUGET_API_KEY }} --source 'nuget.org' +# TODO: Revert after testing +# - name: Push packages to nuget.org +# run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --skip-duplicate --api-key '${{ secrets.STEELTOE_NUGET_API_KEY }}' --source 'nuget.org' + + open_pr: + name: Open pull request to bump Templates version after stable release + if: ${{ github.event_name == 'release' && !contains(github.ref_name, '-') }} + 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 Templates 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 Templates version' --body $commitMessage diff --git a/.gitignore b/.gitignore index a4fe18b..ad55feb 100644 --- a/.gitignore +++ b/.gitignore @@ -82,8 +82,6 @@ StyleCopReport.xml *.pgc *.pgd *.rsp -# but not Directory.Build.rsp, as it configures directory-level build defaults -!Directory.Build.rsp *.sbr *.tlb *.tli @@ -385,6 +383,7 @@ FodyWeavers.xsd !.vscode/launch.json !.vscode/extensions.json *.code-workspace +/.vscode/settings.json # Local History for Visual Studio Code .history/ @@ -398,3 +397,27 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml + +############################################# +### Additions specific to this repository ### +############################################# + +# Mac DS_Store files +.DS_Store + +# JetBrains IDEs Rider/IntelliJ (based on https://intellij-support.jetbrains.com/hc/en-us/articles/206544839) +**/.idea/**/*.xml +**/.idea/**/*.iml +**/.idea/**/*.ids +**/.idea/**/*.ipr +**/.idea/**/*.iws +**/.idea/**/*.name +**/.idea/**/*.properties +**/.idea/**/*.ser +**/.idea/**/shelf/ +**/.idea/**/dictionaries/ +**/.idea/**/libraries/ +**/.idea/**/artifacts/ +**/.idea/**/httpRequests/ +**/.idea/**/dataSources/ +!**/.idea/**/codeStyles/* diff --git a/src/Steeltoe.NetCoreTool.Templates.csproj b/src/Steeltoe.NetCoreTool.Templates.csproj index b862dc3..f2faf1c 100644 --- a/src/Steeltoe.NetCoreTool.Templates.csproj +++ b/src/Steeltoe.NetCoreTool.Templates.csproj @@ -2,8 +2,9 @@ net8.0 Template - 0.0.0 Steeltoe.NetCoreTool.Templates + 1.4.1 + pre Steeltoe .NET Project Templates Broadcom Templates for creating .NET projects with Steeltoe components. @@ -12,7 +13,6 @@ Apache-2.0 false icon.png - https://steeltoe.io/images/transparent.png true true true @@ -21,10 +21,6 @@ true - - - - diff --git a/version.json b/version.json deleted file mode 100644 index a572105..0000000 --- a/version.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.4.1", - "publicReleaseRefSpec": [ - "^refs/heads/release/\\d+\\.\\d+$" - ], - "cloudBuild": { - "buildNumber": { - "enabled": true - } - }, - "release": { - "branchName": "release/{version}" - } -}