Skip to content

Commit

Permalink
add auto versioning support
Browse files Browse the repository at this point in the history
  • Loading branch information
umutozel committed Feb 9, 2025
1 parent 48cdfb2 commit 0909807
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ jobs:
with:
dotnet-version: '9.0'

- name: Update .csproj version
if: startsWith(github.ref, 'refs/tags/v')
run: |
$VERSION = $env:GITHUB_REF -replace 'refs/tags/v', ''
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Updating .csproj version to: $VERSION"
[xml]$xml = Get-Content src\DynamicQueryable\DynamicQueryable.csproj
$propertyGroup = $xml.Project.PropertyGroup | Where-Object { $_.Version }
if ($propertyGroup) {
echo "Existing <Version> found. Updating..."
$propertyGroup.Version = $VERSION
} else {
echo "No existing <Version> tag. Creating new one..."
$newPropertyGroup = $xml.CreateElement("PropertyGroup")
$versionElement = $xml.CreateElement("Version")
$versionElement.InnerText = $VERSION
$newPropertyGroup.AppendChild($versionElement) | Out-Null
$xml.Project.AppendChild($newPropertyGroup) | Out-Null
}
$xml.Save("src/DynamicQueryable/DynamicQueryable.csproj")
echo "Updated .csproj version:"
Get-Content src/DynamicQueryable/DynamicQueryable.csproj
shell: pwsh

- name: Restore dependencies
run: dotnet restore

Expand All @@ -51,14 +79,6 @@ jobs:
curl -s https://codecov.io/bash > codecov
bash codecov -f opencoverCoverage.xml -t ${{ secrets.CODECOV_TOKEN }}
- name: Set version from tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
$VERSION = $env:GITHUB_REF -replace 'refs/tags/v', ''
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Version set to: $VERSION"
shell: pwsh

- name: Pack NuGet package
if: startsWith(github.ref, 'refs/tags/v')
run: dotnet pack src\DynamicQueryable\DynamicQueryable.csproj --configuration Release --output "${{ github.workspace }}\packages"
Expand Down

0 comments on commit 0909807

Please sign in to comment.