Skip to content

Commit 15875e4

Browse files
committed
Use Trusted publishing to nuget.org
1 parent 178817b commit 15875e4

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

.github/workflows/dotnetcore.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,39 @@ jobs:
4646
committer_name: GitHub Actions
4747
committer_email: actions@github.com
4848

49-
- name: Publish Beta
49+
publish:
50+
name: Publish NuGet package
51+
needs: build
52+
if: github.event_name == 'push' && (github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/stable')
53+
runs-on: windows-latest
54+
environment: nuget-publish
55+
permissions:
56+
contents: read
57+
id-token: write
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Setup .NET
62+
uses: actions/setup-dotnet@v4
63+
with:
64+
dotnet-version: '10.0.x'
65+
66+
- name: Pack Beta
5067
if: github.ref == 'refs/heads/beta'
51-
run: |
52-
dotnet pack src/Advanced.Algorithms/Advanced.Algorithms.csproj --version-suffix "beta"
53-
dotnet nuget push **/*.nupkg -s "nuget" -k "${{ secrets.NUGET_TOKEN }}"
68+
run: dotnet pack src/Advanced.Algorithms/Advanced.Algorithms.csproj --version-suffix "beta" --output artifacts
5469

55-
- name: Publish Stable
70+
- name: Pack Stable
5671
if: github.ref == 'refs/heads/stable'
72+
run: dotnet pack src/Advanced.Algorithms/Advanced.Algorithms.csproj --output artifacts
73+
74+
- name: NuGet login
75+
id: login
76+
uses: NuGet/login@v1
77+
with:
78+
user: ${{ secrets.NUGET_USER }}
79+
80+
- name: Publish package
5781
run: |
58-
dotnet pack src/Advanced.Algorithms/Advanced.Algorithms.csproj
59-
dotnet nuget push **/*.nupkg -s "nuget" -k "${{ secrets.NUGET_TOKEN }}"
82+
$package = Get-ChildItem artifacts -Filter *.nupkg | Select-Object -First 1
83+
if (-not $package) { throw "No NuGet package was produced." }
84+
dotnet nuget push $package.FullName --source "nuget" --api-key "${{ steps.login.outputs.NUGET_API_KEY }}"

src/Advanced.Algorithms/Advanced.Algorithms.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<DelaySign>False</DelaySign>
1010
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
1111
<LangVersion>latest</LangVersion>
12-
<VersionPrefix>1.0.0.0</VersionPrefix>
12+
<VersionPrefix>1.0.1</VersionPrefix>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)