-
Notifications
You must be signed in to change notification settings - Fork 10
92 lines (77 loc) · 2.94 KB
/
nuget.yml
File metadata and controls
92 lines (77 loc) · 2.94 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: NuGet
on:
workflow_run:
workflows: ["Build and test"]
types:
- completed
branches:
- master
workflow_dispatch:
jobs:
pack:
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
runs-on: windows-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Restore
run: dotnet restore src/NLog.MailKit.sln
- name: Build
run: dotnet build src/NLog.MailKit.sln --configuration Release --no-restore
- name: Determine version suffix
id: version
shell: pwsh
run: |
$ref = "${{ github.ref }}"
if ($ref -eq "refs/heads/master") {
echo "suffix=" >> $env:GITHUB_OUTPUT
} else {
# For a PR: use head_ref (actual branch name), otherwise the ref name
$branchName = "${{ github.head_ref }}"
if ([string]::IsNullOrEmpty($branchName)) {
$branchName = "${{ github.ref_name }}"
}
# Sanitize: non-alphanumeric -> '-', multiple '-' -> one, trim '-'
$clean = $branchName -replace '[^a-zA-Z0-9]', '-' `
-replace '-+', '-' `
-replace '^-|-$', ''
# Truncate to max 40 characters and remove trailing '-'
$short = if ($clean.Length -gt 0) { $clean.Substring(0, [Math]::Min(40, $clean.Length)).TrimEnd('-') } else { "" }
# PR number prefix
$prNumber = "${{ github.event.pull_request.number }}"
$prPrefix = if ($prNumber) { "pr${prNumber}-" } else { "" }
# Build number
$build = "${{ github.run_number }}"
$suffix = "${prPrefix}${short}.${build}"
echo "suffix=$suffix" >> $env:GITHUB_OUTPUT
}
- name: Pack
shell: pwsh
run: |
$versionSuffix = "${{ steps.version.outputs.suffix }}"
if ($versionSuffix) {
dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts --version-suffix "$versionSuffix"
} else {
dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts
}
- name: Upload nuget package
uses: actions/upload-artifact@v4
with:
name: nupkg
path: artifacts/*pkg
- name: NuGet login
if: github.ref == 'refs/heads/master'
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}
- name: Push to NuGet.org
if: github.ref == 'refs/heads/master'
shell: pwsh
run: dotnet nuget push artifacts\*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate