Skip to content

Commit ff5456b

Browse files
Fix GitHub Actions NuGet publish: glob expansion, version number, PR pre-release versioning, and deterministic builds (#234)
* Initial plan * Fix version prefix and add PR version suffix to workflow Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Add VersionPrefix, FileVersion, and PR version suffix to workflow Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Rename build.yml to build-and-test.yml and move NuGet steps to nuget.yml Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Add deterministic build, SourceLink, and snupkg debug symbols support Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Remove redundant snupkg push (dotnet nuget push auto-pushes snupkg alongside nupkg) Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Update NuGet push command to use wildcard for packages --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
1 parent dcf63ca commit ff5456b

4 files changed

Lines changed: 109 additions & 57 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Build and test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
strategy:
13+
matrix:
14+
os: [windows-latest, ubuntu-latest]
15+
runs-on: ${{ matrix.os }}
16+
permissions:
17+
contents: read
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Setup .NET
23+
uses: actions/setup-dotnet@v4
24+
with:
25+
dotnet-version: '8.0.x'
26+
27+
- name: Restore
28+
run: dotnet restore src/NLog.MailKit.sln
29+
30+
- name: Build
31+
run: dotnet build src/NLog.MailKit.sln --configuration Release --no-restore
32+
33+
- name: Test
34+
run: dotnet test src/NLog.MailKit.sln --configuration Release --no-build

.github/workflows/build.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/nuget.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: NuGet
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
pack:
12+
runs-on: windows-latest
13+
permissions:
14+
contents: read
15+
id-token: write
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup .NET
21+
uses: actions/setup-dotnet@v4
22+
with:
23+
dotnet-version: '8.0.x'
24+
25+
- name: Restore
26+
run: dotnet restore src/NLog.MailKit.sln
27+
28+
- name: Build
29+
run: dotnet build src/NLog.MailKit.sln --configuration Release --no-restore
30+
31+
- name: Determine version suffix
32+
id: version
33+
shell: bash
34+
run: |
35+
if [[ "$GITHUB_REF" == "refs/heads/master" ]]; then
36+
echo "suffix=" >> $GITHUB_OUTPUT
37+
else
38+
CLEAN=$(echo "$GITHUB_REF_NAME" | sed 's/[^a-zA-Z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
39+
echo "suffix=$CLEAN" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Pack
43+
shell: bash
44+
run: |
45+
VERSION_SUFFIX="${{ steps.version.outputs.suffix }}"
46+
if [ -n "$VERSION_SUFFIX" ]; then
47+
dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts --version-suffix "$VERSION_SUFFIX"
48+
else
49+
dotnet pack src/NLog.MailKit.sln --no-build --configuration Release --output artifacts
50+
fi
51+
52+
- name: Upload nuget package
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: nupkg
56+
path: artifacts/*pkg
57+
58+
- name: NuGet login
59+
if: github.ref == 'refs/heads/master'
60+
uses: NuGet/login@v1
61+
id: login
62+
with:
63+
user: ${{ secrets.NUGET_USER }}
64+
65+
- name: Push to NuGet.org
66+
if: github.ref == 'refs/heads/master'
67+
shell: bash
68+
run: dotnet nuget push artifacts/* --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate

src/NLog.MailKit/NLog.MailKit.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ Changelog:
3636
See https://github.com/NLog/NLog.MailKit/releases
3737

3838
</PackageReleaseNotes>
39+
<VersionPrefix>6.0.5</VersionPrefix>
3940
<AssemblyVersion>6.0.0.0</AssemblyVersion>
41+
<FileVersion>$(VersionPrefix).0</FileVersion>
4042
<PackageReadmeFile>README.md</PackageReadmeFile>
43+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
44+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
45+
<IncludeSymbols>true</IncludeSymbols>
46+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
47+
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
4148

4249
<GenerateDocumentationFile>true</GenerateDocumentationFile>
4350
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

0 commit comments

Comments
 (0)