Skip to content

Updates patch version #45

Updates patch version

Updates patch version #45

Workflow file for this run

name: NuGet Package Pipeline
on:
workflow_dispatch:
push:
branches:
- main
- release/**
pull_request:
branches:
- main
env:
MAJOR: 1
MINOR: 0
PATCH: 6
LABEL: preview
SOLUTION_PATH: 'OpenApiExampleApp.sln'
jobs:
calculate_version:
name: Determine Package Version
runs-on: ubuntu-latest
outputs:
version_prefix: ${{ steps.version.outputs.version_prefix }}
version_suffix: ${{ steps.version.outputs.version_suffix }}
steps:
- name: Calculate Version
id: version
shell: pwsh
run: |
$major = "${{ env.MAJOR }}"
$minor = "${{ env.MINOR }}"
$patch = "${{ env.PATCH }}"
$label = "${{ env.LABEL }}"
$timestamp = (Get-Date -Format "yyyyMMddHHmmss")
$branch = "${{ github.ref_name }}"
$fullVersion = ""
if ($branch -eq "main") {
$fullVersion = "$major.$minor.$patch-$label.$timestamp"
}
elseif ($branch -like "release/*") {
$fullVersion = "$major.$minor.$patch"
}
else {
$fullVersion = "$major.$minor.$patch-local.$timestamp"
}
$versionParts = $fullVersion -split "-"
$versionPrefix = $versionParts[0]
$versionSuffix = if ($versionParts.Count -gt 1) { $versionParts[1] } else { "" }
Write-Output "version_prefix=$versionPrefix" >> $env:GITHUB_OUTPUT
Write-Output "version_suffix=$versionSuffix" >> $env:GITHUB_OUTPUT
Write-Output "Generated version: $fullVersion"
build:
name: Build and Package
needs: calculate_version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 10.0.x
- name: Build Solution
run: |
dotnet build ${{ env.SOLUTION_PATH }} \
--configuration Release \
-p:VersionPrefix=${{ needs.calculate_version.outputs.version_prefix }} \
-p:VersionSuffix=${{ needs.calculate_version.outputs.version_suffix }}
- name: Run Tests
run: |
dotnet test ${{ env.SOLUTION_PATH }} \
--configuration Release \
--verbosity normal \
--logger "trx;LogFileName=test-results.trx"
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: '**/test-results.trx'
retention-days: 7
- name: Create NuGet Package
run: |
dotnet pack ${{ env.SOLUTION_PATH }} \
--configuration Release \
-p:VersionPrefix=${{ needs.calculate_version.outputs.version_prefix }} \
-p:VersionSuffix=${{ needs.calculate_version.outputs.version_suffix }} \
--output nupkgs \
--include-symbols \
--include-source
- name: Upload Test Artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: nupkgs/*.nupkg
retention-days: 3
validate:
name: Validate Package
needs: build
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
publish:
name: Publish to NuGet
needs: [calculate_version, build]
runs-on: ubuntu-latest
environment:
name: Production
url: https://www.nuget.org/packages/
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: nuget-package
- name: Push to NuGet.org
run: |
dotnet nuget push *.nupkg \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json