Skip to content

Commit fff9cf0

Browse files
bart-vmwareTimHess
authored andcommitted
Replace nbgv with simplified versioning, sync up .gitignore
1 parent 103ae24 commit fff9cf0

File tree

5 files changed

+142
-45
lines changed

5 files changed

+142
-45
lines changed

.config/dotnet-tools.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ permissions:
2323
env:
2424
DOTNET_CLI_TELEMETRY_OPTOUT: 1
2525
DOTNET_NOLOGO: true
26+
VERSION_FILE: 'src/Steeltoe.NetCoreTool.Templates.csproj'
2627

2728
jobs:
2829
build-and-test:
@@ -45,24 +46,76 @@ jobs:
4546
4647
- name: Git checkout
4748
uses: actions/checkout@v4
48-
with:
49-
fetch-depth: 0
50-
51-
- name: Restore tools
52-
run: dotnet tool restore
5349

5450
- name: Restore packages
5551
run: dotnet restore --verbosity minimal
5652

53+
- name: Calculate package version (for release)
54+
if: ${{ github.event_name == 'release' }}
55+
env:
56+
TAG_NAME: ${{ github.ref_name }}
57+
shell: pwsh
58+
run: |
59+
# Get the version suffix from the git tag. For example: '1.2.3-preview1-final' => 'preview1-final'
60+
$tagSegments = '${{ env.TAG_NAME }}' -split '-'
61+
$versionPrefix = $tagSegments[0]
62+
$versionSuffix = $tagSegments.Length -eq 1 ? '' : $tagSegments[1..$($tagSegments.Length - 1)] -join '-'
63+
64+
[xml]$xml = Get-Content $env:VERSION_FILE
65+
$configuredVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
66+
67+
if ($configuredVersionPrefix -ne $versionPrefix) {
68+
Write-Error "Version prefix from git release tag '$versionPrefix' does not match version prefix '$configuredVersionPrefix' stored in $env:VERSION_FILE."
69+
# To recover from this:
70+
# - Delete the GitHub release
71+
# - Run: git push --delete origin the-invalid-tag-name
72+
# - Adjust VersionPrefix in file, commit and push
73+
# - Recreate the GitHub release
74+
}
75+
76+
Write-Output "Using version suffix: $versionSuffix"
77+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
78+
79+
- name: Calculate package version (for branch)
80+
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
81+
env:
82+
BRANCH_NAME: ${{ github.ref_name }}
83+
shell: pwsh
84+
run: |
85+
# Get the version suffix from the branch name and auto-incrementing build number. For example: 'main' and '123' => 'main-00123'
86+
$revision = "{0:D5}" -f ${{ github.run_number }}
87+
$branchName = '${{ env.BRANCH_NAME }}'
88+
$safeBranchName = $branchName -Replace '[^a-zA-Z0-9-]', '-'
89+
$versionSuffix = "$safeBranchName-$revision"
90+
91+
Write-Output "Using version suffix: $versionSuffix"
92+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
93+
94+
- name: Calculate package version (for pr)
95+
if: ${{ github.event_name == 'pull_request' }}
96+
shell: pwsh
97+
run: |
98+
# Get the version suffix from the PR number and auto-incrementing build number. For example: '18' and '123' => 'pr18-00123'
99+
$revision = "{0:D5}" -f ${{ github.run_number }}
100+
$versionSuffix = "pr${{ github.event.number }}-$revision"
101+
102+
Write-Output "Using version suffix: $versionSuffix"
103+
Write-Output "PACKAGE_VERSION_SUFFIX=$versionSuffix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
104+
105+
- name: Verify package version
106+
if: ${{ !env.PACKAGE_VERSION_SUFFIX && github.event_name != 'release' }}
107+
run: |
108+
echo "Package version suffix is empty. This should never happen."
109+
exit 1
110+
57111
- name: Build solution
58-
run: dotnet build --no-restore --configuration Release --verbosity minimal
112+
run: dotnet build --no-restore --configuration Release --verbosity minimal /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
59113

60114
- name: Test
61115
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --logger "GitHubActions;summary.includeSkippedTests=true"
62116

63117
- name: Collect packages
64-
shell: pwsh
65-
run: dotnet pack src --no-build --configuration Release --output ${{ github.workspace }}/packages
118+
run: dotnet pack src --no-build --configuration Release --output ${{ github.workspace }}/packages /p:VersionSuffix=${{ env.PACKAGE_VERSION_SUFFIX }}
66119

67120
- name: Upload unsigned packages
68121
if: ${{ matrix.os == 'ubuntu-latest' }}
@@ -192,4 +245,57 @@ jobs:
192245
path: packages
193246

194247
- name: Push packages to nuget.org
195-
run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --skip-duplicate --api-key ${{ secrets.STEELTOE_NUGET_API_KEY }} --source 'nuget.org'
248+
run: dotnet nuget push '${{ github.workspace }}/packages/*.nupkg' --skip-duplicate --api-key '${{ secrets.STEELTOE_NUGET_API_KEY }}' --source 'nuget.org'
249+
250+
open_pr:
251+
name: Open pull request to bump templates version after stable release
252+
if: ${{ github.event_name == 'release' && !contains(github.ref_name, '-') }}
253+
needs: nuget-org-deploy
254+
timeout-minutes: 15
255+
runs-on: ubuntu-latest
256+
permissions:
257+
contents: write
258+
pull-requests: write
259+
260+
steps:
261+
- name: Git checkout
262+
uses: actions/checkout@v4
263+
264+
- name: Calculate next package version
265+
shell: pwsh
266+
run: |
267+
[xml]$xml = Get-Content $env:VERSION_FILE
268+
$oldVersionPrefix = $xml.Project.PropertyGroup.VersionPrefix | Select-Object -First 1
269+
270+
$versionSegments = $oldVersionPrefix.split('.')
271+
([int]$versionSegments[-1])++
272+
$newVersionPrefix = $versionSegments -join('.')
273+
274+
Write-Output "OLD_PACKAGE_VERSION_PREFIX=$oldVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
275+
Write-Output "NEW_PACKAGE_VERSION_PREFIX=$newVersionPrefix" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
276+
277+
- name: Open pull request
278+
env:
279+
GH_TOKEN: ${{ github.token }}
280+
shell: pwsh
281+
run: |
282+
$oldVersionPrefix = '${{ env.OLD_PACKAGE_VERSION_PREFIX }}'
283+
$newVersionPrefix = '${{ env.NEW_PACKAGE_VERSION_PREFIX }}'
284+
$prBranchName = "bump-version-to-$newVersionPrefix-${{ github.run_number }}"
285+
$commitMessage = "Bump templates version from $oldVersionPrefix to $newVersionPrefix.`n`n> [!TIP]`n> Close and reopen this pull request to run status checks."
286+
287+
$pattern = '(?<left>^\s*\<VersionPrefix\>)[^>]+(?<right>\<\/VersionPrefix\>)\s*$'
288+
$fileContent = Get-Content $env:VERSION_FILE
289+
$fileContent = $fileContent -Replace $pattern,"`${left}$newVersionPrefix`${right}"
290+
Set-Content $fileContent -Path $env:VERSION_FILE
291+
292+
Write-Output "Creating pull request with commit message:`n$commitMessage"
293+
git config --local user.name "github-actions[bot]"
294+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
295+
git checkout -b $prBranchName
296+
git add -A
297+
git commit -m $commitMessage
298+
git push --set-upstream origin $prBranchName
299+
300+
Write-Output "Opening pull request to merge $prBranchName."
301+
gh pr create --head $prBranchName --title 'Bump templates version' --body $commitMessage

.gitignore

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ StyleCopReport.xml
8282
*.pgc
8383
*.pgd
8484
*.rsp
85-
# but not Directory.Build.rsp, as it configures directory-level build defaults
86-
!Directory.Build.rsp
8785
*.sbr
8886
*.tlb
8987
*.tli
@@ -385,6 +383,7 @@ FodyWeavers.xsd
385383
!.vscode/launch.json
386384
!.vscode/extensions.json
387385
*.code-workspace
386+
/.vscode/settings.json
388387

389388
# Local History for Visual Studio Code
390389
.history/
@@ -398,3 +397,27 @@ FodyWeavers.xsd
398397

399398
# JetBrains Rider
400399
*.sln.iml
400+
401+
#############################################
402+
### Additions specific to this repository ###
403+
#############################################
404+
405+
# Mac DS_Store files
406+
.DS_Store
407+
408+
# JetBrains IDEs Rider/IntelliJ (based on https://intellij-support.jetbrains.com/hc/en-us/articles/206544839)
409+
**/.idea/**/*.xml
410+
**/.idea/**/*.iml
411+
**/.idea/**/*.ids
412+
**/.idea/**/*.ipr
413+
**/.idea/**/*.iws
414+
**/.idea/**/*.name
415+
**/.idea/**/*.properties
416+
**/.idea/**/*.ser
417+
**/.idea/**/shelf/
418+
**/.idea/**/dictionaries/
419+
**/.idea/**/libraries/
420+
**/.idea/**/artifacts/
421+
**/.idea/**/httpRequests/
422+
**/.idea/**/dataSources/
423+
!**/.idea/**/codeStyles/*

src/Steeltoe.NetCoreTool.Templates.csproj

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<PackageType>Template</PackageType>
5-
<PackageVersion>0.0.0</PackageVersion>
65
<PackageId>Steeltoe.NetCoreTool.Templates</PackageId>
6+
<VersionPrefix>1.4.5</VersionPrefix>
7+
<VersionSuffix>pre</VersionSuffix>
78
<Title>Steeltoe .NET Project Templates</Title>
89
<Authors>Broadcom</Authors>
910
<Description>Templates for creating .NET projects with Steeltoe components.</Description>
@@ -12,7 +13,6 @@
1213
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1314
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1415
<PackageIcon>icon.png</PackageIcon>
15-
<PackageIconUrl>https://steeltoe.io/images/transparent.png</PackageIconUrl>
1616
<NoDefaultExcludes>true</NoDefaultExcludes>
1717
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1818
<IncludeContentInPack>true</IncludeContentInPack>
@@ -21,10 +21,6 @@
2121
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
2222
</PropertyGroup>
2323

24-
<ItemGroup>
25-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="All" />
26-
</ItemGroup>
27-
2824
<ItemGroup>
2925
<Content Include="Content\**\*" Exclude="Content\**\bin\**;Content\**\obj\**;Content\**\Directory.Build.props;**\*.user" />
3026
<Compile Remove="**\*" />

version.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)