1- # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
21name : publish
2+
33on :
4- workflow_dispatch : # Allow running the workflow manually from the GitHub UI
4+ workflow_dispatch :
55 push :
6- branches :
7- - " master" # Run the workflow when pushing to the main branch
6+ branches : [ master ]
87 pull_request :
9- branches :
10- - " *" # Run the workflow for all pull requests
8+ branches : [ '*' ]
119 release :
12- types :
13- - published # Run the workflow when a new GitHub release is published
10+ types : [ published ]
11+
1412env :
1513 DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1
1614 DOTNET_NOLOGO : true
17- NuGetDirectory : ${{ github.workspace}}/nuget
15+ NuGetDirectory : ${{ github.workspace }}/nuget
16+
1817defaults :
1918 run :
2019 shell : pwsh
20+
2121jobs :
22- build_and_pack :
23- name : Build & Test & Pack
24- runs-on : ubuntu-latest # Use Linux runner
25- permissions :
26- contents : write # Needed for gh release create step to upload assets
22+ build_test_and_pack :
23+ name : Build, Test, and Pack
24+ runs-on : ubuntu-latest
2725 steps :
28- - name : Checkout code
29- uses : actions/checkout@v4
30- with :
31- fetch-depth : 0 # Get all history to allow automatic versioning using MinVer
32- - name : Setup .NET 9 SDK
33- uses : actions/setup-dotnet@v4
34- with :
35- dotnet-version : ' 9.x' # Use the .NET 9 SDK
36- - name : Restore dependencies
37- run : dotnet restore TTSTextNormalization.sln # Restore for the whole solution
38- - name : Build Library
39- # Build the specific library project in Release config
40- run : dotnet build TTSTextNormalization/TTSTextNormalization.csproj --configuration Release --no-restore
41-
42- # --- New Test Step ---
43- - name : Run Unit Tests
44- # Run tests for the entire solution in Release config
45- # --no-build assumes the previous build step was successful
46- run : dotnet test TTSTextNormalization.sln --configuration Release --verbosity normal
47-
48- - name : Pack Library
49- # Pack the specific library project
50- # Use Release config
51- # Output packages to an 'artifacts' directory
52- run : dotnet pack TTSTextNormalization/TTSTextNormalization.csproj --configuration Release --no-build --output ${{ env.NuGetDirectory }}
53- - uses : actions/upload-artifact@v4
54- with :
55- name : nuget
56- if-no-files-found : error
57- retention-days : 7
58- path : ${{ env.NuGetDirectory }}/*.nupkg
26+ - name : Checkout Repository
27+ uses : actions/checkout@v4
28+ with :
29+ fetch-depth : 0
30+
31+ - name : Setup .NET SDK
32+ uses : actions/setup-dotnet@v4
33+ with :
34+ dotnet-version : |
35+ 10.x
36+ 9.x
37+
38+ - name : Restore Dependencies
39+ run : dotnet restore TTSTextNormalization.sln
40+
41+ - name : Build Solution
42+ run : dotnet build TTSTextNormalization.sln --configuration Release --no-restore
43+
44+ - name : Run Tests for .NET 10.0
45+ run : dotnet test TTSTextNormalization.Tests/TTSTextNormalization.Tests.csproj --configuration Release --framework net10.0 --no-build --report-trx --report-trx-filename test-results-net10.trx
46+
47+ - name : Run Tests for .NET 9.0
48+ run : dotnet test TTSTextNormalization.Tests/TTSTextNormalization.Tests.csproj --configuration Release --framework net9.0 --no-build --report-trx --report-trx-filename test-results-net9.trx
49+
50+ - name : Upload Test Results
51+ if : always()
52+ uses : actions/upload-artifact@v4
53+ with :
54+ name : test-results
55+ path : ' **/*.trx'
56+ retention-days : 7
57+
58+ - name : Pack Library
59+ run : dotnet pack TTSTextNormalization/TTSTextNormalization.csproj --configuration Release --no-build --output ${{ env.NuGetDirectory }}
60+
61+ - name : Upload NuGet Packages Artifact
62+ uses : actions/upload-artifact@v4
63+ with :
64+ name : nuget-packages
65+ if-no-files-found : error
66+ retention-days : 7
67+ path : ${{ env.NuGetDirectory }}/*.nupkg
5968
6069 deploy :
61- # Publish only when creating a GitHub Release
62- # https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
63- # You can update this logic if you want to manage releases differently
64- if : github.event_name == 'release'
70+ name : Deploy Packages to NuGet.org
71+ if : github.event_name == 'release' && github.event.action == 'published'
6572 runs-on : ubuntu-latest
66- needs : [build_and_pack] # Depends on the job that now includes testing
73+ needs : [build_test_and_pack]
74+ environment :
75+ name : nuget.org
76+ url : https://www.nuget.org/packages/Agash.TTSTextNormalization
77+ permissions :
78+ contents : read
6779 steps :
68- # Download the NuGet package created in the previous job
69- - uses : actions/download-artifact@v4
70- with :
71- name : nuget
72- path : ${{ env.NuGetDirectory }}
73- # Install the .NET SDK indicated in the global.json file
74- - name : Setup .NET Core
75- uses : actions/setup-dotnet@v4
76- # Publish all NuGet packages to NuGet.org
77- # Use --skip-duplicate to prevent errors if a package with the same version already exists.
78- # If you retry a failed workflow, already published packages will be skipped without error.
79- - name : Publish NuGet package
80- run : |
81- foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
82- dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
83- }
80+ - name : Download NuGet Packages Artifact
81+ uses : actions/download-artifact@v4
82+ with :
83+ name : nuget-packages
84+ path : ${{ env.NuGetDirectory }}
85+
86+ - name : Setup .NET SDK
87+ uses : actions/setup-dotnet@v4
88+ with :
89+ dotnet-version : 10.x
90+
91+ - name : Publish NuGet Packages
92+ env :
93+ NUGET_API_KEY : ${{ secrets.NUGET_APIKEY }}
94+ run : |
95+ Get-ChildItem "${{ env.NuGetDirectory }}" -Filter *.nupkg | ForEach-Object {
96+ Write-Host "Pushing $($_.FullName)..."
97+ dotnet nuget push $_.FullName --api-key "$env:NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
98+ }
0 commit comments