-
-
Notifications
You must be signed in to change notification settings - Fork 148
169 lines (140 loc) · 5.35 KB
/
Publish-Nuget.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Build and Publish
on:
push:
branches:
- main
paths:
- OpenAI-DotNet/**
- OpenAI-DotNet-Proxy/**
pull_request:
branches:
- '*'
paths:
- OpenAI-DotNet/**
- OpenAI-DotNet-Proxy/**
types:
- opened
- synchronize
workflow_dispatch:
inputs:
dotnet-version:
description: ".NET version to use"
required: false
default: "6.0.x"
permissions:
contents: read
pages: write
checks: write
id-token: write
pull-requests: write
concurrency:
group: ${{ github.ref }}
cancel-in-progress: false
env:
DOTNET_VERSION: ${{ github.event.inputs.dotnet-version || '6.0.x' }}
PACKAGE_VERSION: ''
jobs:
build:
if: ${{ !github.event_name == 'pull_request' || !github.event.pull_request.draft }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- run: dotnet restore
- run: dotnet build --configuration Release --no-restore
- name: Test Packages
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' }}
run: dotnet test --configuration Release --collect:"XPlat Code Coverage" --logger:trx --no-build --no-restore --results-directory ./test-results
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_ORGANIZATION_ID: ${{ secrets.OPENAI_ORGANIZATION_ID }}
- name: Publish Test Results
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: test-results/**/*.trx
comment_mode: off
report_individual_runs: true
compare_to_earlier_commit: false
- name: Code Coverage Summary Report
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
uses: irongut/[email protected]
with:
filename: test-results/**/coverage.cobertura.xml
badge: true
format: 'markdown'
output: 'both'
- name: Write Coverage Job Summary
if: ${{ github.ref != 'refs/heads/main' && github.event_name != 'push' && always() }}
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Pack and Publish NuGet Package
run: |
$projectPath = "${{ github.workspace }}\OpenAI-DotNet"
$proxyProjectPath = "${{ github.workspace }}\OpenAI-DotNet-Proxy"
# pack OpenAI-DotNet
dotnet pack $projectPath --configuration Release --include-symbols
$out = "$projectPath\bin\Release"
$packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue
if ($packagePath) {
Write-Host Package path: $packagePath
} else {
Write-Host Failed to find package at $out
exit 1
}
# pack OpenAI-DotNet-Proxy
dotnet pack $proxyProjectPath --configuration Release --include-symbols
$proxyOut = "$proxyProjectPath\bin\Release"
$proxyPackagePath = Get-ChildItem -Path $proxyOut -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue
if ($proxyPackagePath) {
Write-Host Package path: $proxyPackagePath
} else {
Write-Host Failed to find package at $proxyOut
exit 1
}
$isRelease = "${{ github.ref == 'refs/heads/main' }}"
if ($isRelease -eq 'true') {
dotnet nuget push $packagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push $proxyPackagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
}
$version = $packagePath.Name -replace "^OpenAI-DotNet.(.*).nupkg$",'$1'
echo "PACKAGE_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh
- uses: actions/upload-artifact@v4
if: always()
with:
name: OpenAI-DotNet.${{ env.PACKAGE_VERSION }}
path: |
${{ github.workspace }}/test-results
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.symbols.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.symbols.nupkg
if-no-files-found: ignore
docs:
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: build docfx
run: |
dotnet tool update -g docfx
docfx .docs/docfx.json
- uses: actions/upload-pages-artifact@v3
with:
path: '_site'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected]