Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .config/dotnet-tools.json

This file was deleted.

124 changes: 115 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -45,24 +46,76 @@ 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"

- 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' }}
Expand Down Expand Up @@ -192,4 +245,57 @@ jobs:
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'
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.`n`n> [!TIP]`n> Close and reopen this pull request to run status checks."

$pattern = '(?<left>^\s*\<VersionPrefix\>)[^>]+(?<right>\<\/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 with commit message:`n$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
27 changes: 25 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -385,6 +383,7 @@ FodyWeavers.xsd
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
/.vscode/settings.json

# Local History for Visual Studio Code
.history/
Expand All @@ -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/*
8 changes: 2 additions & 6 deletions src/Steeltoe.NetCoreTool.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<PackageType>Template</PackageType>
<PackageVersion>0.0.0</PackageVersion>
<PackageId>Steeltoe.NetCoreTool.Templates</PackageId>
<VersionPrefix>1.4.5</VersionPrefix>
<VersionSuffix>pre</VersionSuffix>
<Title>Steeltoe .NET Project Templates</Title>
<Authors>Broadcom</Authors>
<Description>Templates for creating .NET projects with Steeltoe components.</Description>
Expand All @@ -12,7 +13,6 @@
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageIcon>icon.png</PackageIcon>
<PackageIconUrl>https://steeltoe.io/images/transparent.png</PackageIconUrl>
<NoDefaultExcludes>true</NoDefaultExcludes>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeContentInPack>true</IncludeContentInPack>
Expand All @@ -21,10 +21,6 @@
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<Content Include="Content\**\*" Exclude="Content\**\bin\**;Content\**\obj\**;Content\**\Directory.Build.props;**\*.user" />
<Compile Remove="**\*" />
Expand Down
15 changes: 0 additions & 15 deletions version.json

This file was deleted.

Loading