1- name : Publish
1+ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
22
3+ name : publish
34on :
5+ workflow_dispatch : # Allow running the workflow manually from the GitHub UI
46 push :
5- branches : [ master ]
7+ branches :
8+ - ' master' # Run the workflow when pushing to the master branch
9+ pull_request :
10+ branches :
11+ - ' *' # Run the workflow for all pull requests
12+ release :
13+ types :
14+ - published # Run the workflow when a new GitHub release is published
15+
16+ env :
17+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1
18+ DOTNET_NOLOGO : true
19+ NuGetDirectory : ${{ github.workspace}}/nuget
20+
21+ defaults :
22+ run :
23+ shell : pwsh
624
725jobs :
8- build :
26+ create_nuget :
27+ runs-on : ubuntu-latest
28+ steps :
29+ - uses : actions/checkout@v3
30+ with :
31+ fetch-depth : 0 # Get all history to allow automatic versioning using MinVer
932
33+ # Install the .NET SDK indicated in the global.json file
34+ - name : Setup .NET
35+ uses : actions/setup-dotnet@v4
36+
37+ # Create the NuGet package in the folder from the environment variable NuGetDirectory
38+ - run : dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
39+
40+ # Publish the NuGet package as an artifact, so they can be used in the following jobs
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+ validate_nuget :
1049 runs-on : ubuntu-latest
50+ needs : [ create_nuget ]
51+ steps :
52+ # Install the .NET SDK indicated in the global.json file
53+ - name : Setup .NET
54+ uses : actions/setup-dotnet@v4
1155
56+ # Download the NuGet package created in the previous job
57+ - uses : actions/download-artifact@v4
58+ with :
59+ name : nuget
60+ path : ${{ env.NuGetDirectory }}
61+
62+ - name : Install nuget validator
63+ run : dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
64+
65+ # Validate metadata and content of the NuGet package
66+ # https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
67+ # If some rules are not applicable, you can disable them
68+ # using the --excluded-rules or --excluded-rule-ids option
69+ - name : Validate package
70+ run : meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
71+
72+ run_test :
73+ runs-on : ubuntu-latest
1274 steps :
13- - uses : actions/checkout@v2
14- - name : Setup .NET Core
75+ - uses : actions/checkout@v3
76+ - name : Setup .NET
1577 uses : actions/setup-dotnet@v4
16- with :
17- dotnet-version : 9.0.100
18- - name : Install dependencies
19- run : dotnet restore
20- - name : Build
21- run : dotnet build --configuration Release --no-restore
22- - name : Test
23- run : dotnet test --no-restore --verbosity normal
24- - name : Publish PlainBytes.System.Extensions
25- uses : brandedoutcast/publish-nuget@v2.5.2
26- with :
27- PROJECT_FILE_PATH : source/PlainBytes.System.Extensions/PlainBytes.System.Extensions.csproj
28- NUGET_KEY : ${{secrets.NUGET_API_KEY}}
78+ - name : Run tests
79+ run : dotnet test --configuration Release
80+
81+ deploy :
82+ # Publish only when creating a GitHub Release
83+ # https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
84+ # You can update this logic if you want to manage releases differently
85+ if : github.event_name == 'release'
86+ runs-on : ubuntu-latest
87+ needs : [ validate_nuget, run_test ]
88+ steps :
89+ # Download the NuGet package created in the previous job
90+ - uses : actions/download-artifact@v4
91+ with :
92+ name : nuget
93+ path : ${{ env.NuGetDirectory }}
94+
95+ # Install the .NET SDK indicated in the global.json file
96+ - name : Setup .NET Core
97+ uses : actions/setup-dotnet@v4
98+
99+ # Publish all NuGet packages to NuGet.org
100+ # Use --skip-duplicate to prevent errors if a package with the same version already exists.
101+ # If you retry a failed workflow, already published packages will be skipped without error.
102+ - name : Publish NuGet package
103+ run : |
104+ foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
105+ dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
106+ }
0 commit comments