4141jobs :
4242 build :
4343 if : ${{ !github.event_name == 'pull_request' || !github.event.pull_request.draft }}
44- env :
45- PACKAGE_VERSION : ' '
46- COVERAGE_FILE_PATH : ' '
4744 runs-on : ubuntu-latest
48-
45+ defaults :
46+ run :
47+ shell : pwsh
4948 steps :
50- - uses : actions/checkout@v4
49+ - uses : actions/checkout@v6
5150 with :
5251 fetch-depth : 0
5352
54- - uses : actions/setup-dotnet@v4
53+ - uses : actions/setup-dotnet@v5
5554 with :
5655 dotnet-version : ${{ env.DOTNET_VERSION }}
5756
5857 - run : dotnet restore
59-
6058 - run : dotnet build --configuration Release --no-restore
6159
60+ - name : Get Version
61+ id : version
62+ run : |
63+ $projectPath = "${{ github.workspace }}\OpenAI-DotNet\OpenAI-DotNet.csproj"
64+
65+ if (-Not (Test-Path $projectPath)) {
66+ Write-Host "Project file not found at $projectPath"
67+ exit 1
68+ }
69+
70+ [xml]$csproj = Get-Content $projectPath
71+
72+ if ($csproj -eq $null) {
73+ Write-Host "Failed to load csproj file."
74+ exit 1
75+ }
76+
77+ $version = $csproj.Project.PropertyGroup.Version
78+
79+ if ([string]::IsNullOrEmpty($version)) {
80+ Write-Host "Version not found in csproj."
81+ exit 1
82+ }
83+
84+ Write-Host "Project Version: $version"
85+ echo "PACKAGE_VERSION=$version" >> $GITHUB_OUTPUT
86+
6287 - name : Test Packages
6388 if : ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' }}
6489 run : dotnet test --configuration Release --collect:"XPlat Code Coverage" --logger:trx --no-build --no-restore --results-directory ./test-results
@@ -68,83 +93,82 @@ jobs:
6893
6994 - name : Publish Test Results
7095 if : ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
71- uses : EnricoMi/publish-unit-test-result-action@v2
96+ uses : EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2.11.0
7297 with :
7398 files : test-results/**/*.trx
7499 comment_mode : off
75100 report_individual_runs : true
76101 compare_to_earlier_commit : false
102+ large_files : true
77103
78104 - name : Determine Coverage File Path
79105 if : ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
106+ id : coverage-path
80107 shell : bash
81108 run : |
82109 COVERAGE_FILE_PATH=$(find ./test-results -name 'coverage.cobertura.xml' | head -n 1)
83- echo "COVERAGE_FILE_PATH=$COVERAGE_FILE_PATH" >> $GITHUB_ENV
110+ echo "COVERAGE_FILE_PATH=$COVERAGE_FILE_PATH" >> $GITHUB_OUTPUT
84111
85112 - name : Code Coverage Summary Report
86113 if : ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
87- uses : irongut/CodeCoverageSummary@v1.3.0
114+ uses : irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
88115 with :
89- filename : ${{ env .COVERAGE_FILE_PATH }}
116+ filename : ${{ steps.coverage-path.outputs .COVERAGE_FILE_PATH }}
90117 badge : true
91- format : ' markdown'
92- output : ' both'
118+ format : markdown
119+ output : both
93120
94121 - name : Write Coverage Job Summary
95122 if : ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
123+ shell : bash
96124 run : cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
97125
98126 - name : Pack and Publish NuGet Package
99127 run : |
100128 $projectPath = "${{ github.workspace }}\OpenAI-DotNet"
101129 $proxyProjectPath = "${{ github.workspace }}\OpenAI-DotNet-Proxy"
102-
130+
103131 # pack OpenAI-DotNet
104132 dotnet pack $projectPath --configuration Release --include-symbols
105133 $out = "$projectPath\bin\Release"
106134 $packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue
107-
135+
108136 if ($packagePath) {
109137 Write-Host Package path: $packagePath
110138 } else {
111139 Write-Host Failed to find package at $out
112140 exit 1
113141 }
114-
142+
115143 # pack OpenAI-DotNet-Proxy
116144 dotnet pack $proxyProjectPath --configuration Release --include-symbols
117145 $proxyOut = "$proxyProjectPath\bin\Release"
118146 $proxyPackagePath = Get-ChildItem -Path $proxyOut -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue
119-
147+
120148 if ($proxyPackagePath) {
121149 Write-Host Package path: $proxyPackagePath
122150 } else {
123151 Write-Host Failed to find package at $proxyOut
124152 exit 1
125153 }
126-
154+
127155 $isRelease = "${{ github.ref == 'refs/heads/main' }}"
128-
156+
129157 if ($isRelease -eq 'true') {
130158 dotnet nuget push $packagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
131159 dotnet nuget push $proxyPackagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
132160 }
133161
134- $version = $packagePath.Name -replace "^OpenAI-DotNet.(.*).nupkg$",'$1'
135- echo "PACKAGE_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
136- shell : pwsh
137-
138- - uses : actions/upload-artifact@v4
162+ - uses : actions/upload-artifact@v6
139163 if : always()
140164 with :
141- name : OpenAI-DotNet.${{ env. PACKAGE_VERSION }}
165+ name : OpenAI-DotNet.${{ steps.version.outputs. PACKAGE_VERSION }}-artifacts
142166 path : |
143167 ${{ github.workspace }}/test-results
144- ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env .PACKAGE_VERSION }}.nupkg
145- ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env .PACKAGE_VERSION }}.symbols.nupkg
146- ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env .PACKAGE_VERSION }}.nupkg
147- ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env .PACKAGE_VERSION }}.symbols.nupkg
168+ ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ steps.version.outputs .PACKAGE_VERSION }}.nupkg
169+ ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ steps.version.outputs .PACKAGE_VERSION }}.symbols.nupkg
170+ ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ steps.version.outputs .PACKAGE_VERSION }}.nupkg
171+ ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ steps.version.outputs .PACKAGE_VERSION }}.symbols.nupkg
148172 if-no-files-found : ignore
149173
150174 docs :
@@ -154,25 +178,23 @@ jobs:
154178 name : github-pages
155179 url : ${{ steps.deployment.outputs.page_url }}
156180 runs-on : ubuntu-latest
157-
181+ defaults :
182+ run :
183+ shell : bash
158184 steps :
159- - uses : actions/checkout@v4
185+ - uses : actions/checkout@v6
160186 with :
161187 fetch-depth : 0
162-
163- - uses : actions/setup-dotnet@v4
188+ - uses : actions/setup-dotnet@v5
164189 with :
165190 dotnet-version : ${{ env.DOTNET_VERSION }}
166-
167191 - name : build docfx
168192 run : |
169193 dotnet tool update -g docfx
170194 docfx .docs/docfx.json
171-
172- - uses : actions/upload-pages-artifact@v3
195+ - uses : actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
173196 with :
174197 path : ' _site'
175-
176198 - name : Deploy to GitHub Pages
177199 id : deployment
178- uses : actions/deploy-pages@v4.0.3
200+ uses : actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
0 commit comments