Skip to content

Commit c505b22

Browse files
Create publish.yml
1 parent 71af33c commit c505b22

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/publish.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: PublishRelease
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
env:
9+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
10+
DOTNET_NOLOGO: true
11+
NuGetDirectory: ${{ github.workspace}}/nuget
12+
TAG: ${{ github.ref_name }}
13+
14+
defaults:
15+
run:
16+
shell: pwsh
17+
18+
jobs:
19+
create_nuget:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Set Version Variable
23+
run: |
24+
$version = $env:TAG -replace '^v', ''
25+
echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
26+
27+
- name: checkout
28+
uses: actions/checkout@v4
29+
30+
# Install the .NET SDK
31+
- name: Setup .NET
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: 9.0.x
35+
36+
# Create the NuGet package in the folder from the environment variable NuGetDirectory
37+
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }} /p:Version=${{ env.VERSION }} /p:PackageVersion=${{ env.VERSION }}
38+
39+
# Publish the NuGet package as an artifact, so they can be used in the following jobs
40+
- name: uploadArtifacts
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: nuget
44+
if-no-files-found: error
45+
retention-days: 7
46+
path: ${{ env.NuGetDirectory }}/*.nupkg
47+
48+
deploy:
49+
runs-on: ubuntu-latest
50+
needs: [ create_nuget ]
51+
steps:
52+
# Download the NuGet package created in the previous job
53+
- name: downloadArtifacts
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: nuget
57+
path: ${{ env.NuGetDirectory }}
58+
59+
# Install the .NET SDK
60+
- name: Setup .NET Core
61+
uses: actions/setup-dotnet@v4
62+
with:
63+
dotnet-version: 9.0.x
64+
65+
# Publish all NuGet packages to NuGet.org
66+
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
67+
# If you retry a failed workflow, already published packages will be skipped without error.
68+
- name: Publish NuGet package
69+
run: |
70+
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
71+
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
72+
}

0 commit comments

Comments
 (0)