Skip to content

Commit 9698b37

Browse files
authored
Create publish-to-nuget.yml
1 parent c1fbb36 commit 9698b37

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: publish-to.nuget
4+
on:
5+
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
6+
push:
7+
branches:
8+
- 'master' # Run the workflow when pushing to the main branch
9+
10+
env:
11+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
12+
DOTNET_NOLOGO: true
13+
NuGetDirectory: ${{ github.workspace}}/nuget
14+
15+
defaults:
16+
run:
17+
shell: pwsh
18+
19+
jobs:
20+
create_nuget:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: checkout
24+
uses: actions/checkout@v3
25+
26+
# Install the .NET SDK indicated in the global.json file
27+
- name: Setup .NET
28+
uses: actions/setup-dotnet@v4
29+
30+
# Create the NuGet package in the folder from the environment variable NuGetDirectory
31+
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
32+
33+
# Publish the NuGet package as an artifact, so they can be used in the following jobs
34+
- uses: actions/upload-artifact@v3
35+
with:
36+
name: nuget
37+
if-no-files-found: error
38+
retention-days: 7
39+
path: ${{ env.NuGetDirectory }}/*.nupkg
40+
41+
validate_nuget:
42+
runs-on: ubuntu-latest
43+
needs: [ create_nuget ]
44+
steps:
45+
# Install the .NET SDK indicated in the global.json file
46+
- name: Setup .NET
47+
uses: actions/setup-dotnet@v4
48+
49+
# Download the NuGet package created in the previous job
50+
- uses: actions/download-artifact@v3
51+
with:
52+
name: nuget
53+
path: ${{ env.NuGetDirectory }}
54+
55+
- name: Install nuget validator
56+
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
57+
58+
# Validate metadata and content of the NuGet package
59+
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
60+
# If some rules are not applicable, you can disable them
61+
# using the --excluded-rules or --excluded-rule-ids option
62+
- name: Validate package
63+
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
64+
65+
run_test:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v3
69+
- name: Setup .NET
70+
uses: actions/setup-dotnet@v4
71+
- name: Run tests
72+
run: dotnet test --configuration Release
73+
74+
deploy:
75+
runs-on: ubuntu-latest
76+
needs: [ validate_nuget, run_test ]
77+
steps:
78+
# Download the NuGet package created in the previous job
79+
- uses: actions/download-artifact@v3
80+
with:
81+
name: nuget
82+
path: ${{ env.NuGetDirectory }}
83+
84+
# Install the .NET SDK indicated in the global.json file
85+
- name: Setup .NET Core
86+
uses: actions/setup-dotnet@v4
87+
88+
# Publish all NuGet packages to NuGet.org
89+
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
90+
# If you retry a failed workflow, already published packages will be skipped without error.
91+
- name: Publish NuGet package
92+
run: |
93+
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
94+
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
95+
}

0 commit comments

Comments
 (0)