Skip to content

Commit 8fff8a4

Browse files
committed
Allow publishing explicit PSGraph.Common versions
1 parent 5c99e3e commit 8fff8a4

1 file changed

Lines changed: 40 additions & 25 deletions

File tree

.github/workflows/publishCommon.yml

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ name: Publish PSGraph.Common NuGet Package
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Package version without prerelease suffix, e.g. 2.5.0'
8+
required: true
9+
default: '2.5.0'
10+
prerelease:
11+
description: 'Optional prerelease label, e.g. beta3'
12+
required: false
13+
default: 'beta3'
514

615
jobs:
716
build-and-publish:
@@ -16,37 +25,43 @@ jobs:
1625
with:
1726
dotnet-version: '9.0.x'
1827

28+
- name: Resolve package version
29+
id: version
30+
shell: pwsh
31+
run: |
32+
$version = '${{ github.event.inputs.version }}'
33+
$prerelease = '${{ github.event.inputs.prerelease }}'
34+
if ($version -notmatch '^[0-9]+\.[0-9]+\.[0-9]+$') {
35+
Write-Error 'Version must be X.Y.Z.'
36+
exit 1
37+
}
38+
39+
$isPrerelease = -not [string]::IsNullOrWhiteSpace($prerelease)
40+
$packageVersion = if ($isPrerelease) { "$version-$prerelease" } else { $version }
41+
$configuration = if ($isPrerelease) { 'Debug' } else { 'Release' }
42+
43+
"packageVersion=$packageVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
44+
"configuration=$configuration" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
45+
1946
- name: Restore dependencies
2047
run: dotnet restore PSGraph.Common/PSGraph.Common.csproj
2148

22-
- name: Set Version Suffix for Pre-release
23-
if: github.ref == 'refs/heads/dev'
24-
run: |
25-
VERSION_SUFFIX="beta-$(date +%Y%m%d%H%M%S)"
26-
echo "VERSION_SUFFIX=$VERSION_SUFFIX" >> $GITHUB_ENV
27-
28-
- name: Build (Debug on dev, Release on main)
49+
- name: Build package
2950
run: |
30-
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then
31-
dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Debug --no-restore
32-
else
33-
dotnet build PSGraph.Common/PSGraph.Common.csproj --configuration Release --no-restore
34-
fi
51+
dotnet build PSGraph.Common/PSGraph.Common.csproj \
52+
--configuration ${{ steps.version.outputs.configuration }} \
53+
--no-restore \
54+
-p:Version=${{ steps.version.outputs.packageVersion }} \
55+
-p:PackageVersion=${{ steps.version.outputs.packageVersion }}
3556
36-
- name: Pack (Debug/pre-release on dev, Release on main)
57+
- name: Pack package
3758
run: |
38-
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then
39-
dotnet pack PSGraph.Common/PSGraph.Common.csproj \
40-
--configuration Debug \
41-
--no-build \
42-
--output ./nupkg \
43-
--version-suffix $VERSION_SUFFIX
44-
else
45-
dotnet pack PSGraph.Common/PSGraph.Common.csproj \
46-
--configuration Release \
47-
--no-build \
48-
--output ./nupkg
49-
fi
59+
dotnet pack PSGraph.Common/PSGraph.Common.csproj \
60+
--configuration ${{ steps.version.outputs.configuration }} \
61+
--no-build \
62+
--output ./nupkg \
63+
-p:Version=${{ steps.version.outputs.packageVersion }} \
64+
-p:PackageVersion=${{ steps.version.outputs.packageVersion }}
5065
5166
- name: Publish to NuGet
5267
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

0 commit comments

Comments
 (0)