-
Notifications
You must be signed in to change notification settings - Fork 1
69 lines (58 loc) · 2.39 KB
/
Copy pathpublishCommon.yml
File metadata and controls
69 lines (58 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Publish PSGraph.Common NuGet Package
on:
workflow_dispatch:
inputs:
version:
description: 'Package version without prerelease suffix, e.g. 2.5.0'
required: true
default: '2.5.0'
prerelease:
description: 'Optional prerelease label, e.g. beta5'
required: false
default: 'beta5'
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Resolve package version
id: version
shell: pwsh
run: |
$version = '${{ github.event.inputs.version }}'
$prerelease = '${{ github.event.inputs.prerelease }}'
if ($version -notmatch '^[0-9]+\.[0-9]+\.[0-9]+$') {
Write-Error 'Version must be X.Y.Z.'
exit 1
}
$isPrerelease = -not [string]::IsNullOrWhiteSpace($prerelease)
$packageVersion = if ($isPrerelease) { "$version-$prerelease" } else { $version }
$configuration = if ($isPrerelease) { 'Debug' } else { 'Release' }
"packageVersion=$packageVersion" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"configuration=$configuration" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Restore dependencies
run: dotnet restore PSGraph.Common/PSGraph.Common.csproj
- name: Build package
run: |
dotnet build PSGraph.Common/PSGraph.Common.csproj \
--configuration ${{ steps.version.outputs.configuration }} \
--no-restore \
-p:Version=${{ steps.version.outputs.packageVersion }} \
-p:PackageVersion=${{ steps.version.outputs.packageVersion }}
- name: Pack package
run: |
dotnet pack PSGraph.Common/PSGraph.Common.csproj \
--configuration ${{ steps.version.outputs.configuration }} \
--no-build \
--output ./nupkg \
-p:Version=${{ steps.version.outputs.packageVersion }} \
-p:PackageVersion=${{ steps.version.outputs.packageVersion }}
- name: Publish to NuGet
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}