Skip to content

Commit aa678d7

Browse files
authored
Add live tests to release, main and new live-test workflows (#137)
1 parent 58f93c8 commit aa678d7

File tree

3 files changed

+124
-45
lines changed

3 files changed

+124
-45
lines changed

.github/workflows/live-test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow is triggered by the user and runs live tests on the codebase.
2+
name: Live Test
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
types:
8+
- labeled
9+
10+
jobs:
11+
test:
12+
name: Live Test
13+
runs-on: ubuntu-latest
14+
if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'live test')
15+
environment: Live Testing
16+
env:
17+
version_suffix_args: ${{ format('--version-suffix="alpha.{0}"', github.run_number) }}
18+
steps:
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v3
21+
with:
22+
dotnet-version: '8.x'
23+
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Run live tests
28+
run: dotnet test
29+
--configuration Release
30+
--filter="TestCategory!=Smoke&TestCategory!=Images&TestCategory!=Moderations&TestCategory!=Manual"
31+
--logger "trx;LogFilePrefix=live"
32+
--results-directory ${{github.workspace}}/artifacts/test-results
33+
${{ env.version_suffix_args }}
34+
env:
35+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
36+
37+
- name: Upload artifact
38+
uses: actions/upload-artifact@v2
39+
if: ${{ !cancelled() }}
40+
with:
41+
name: test-artifacts
42+
path: ${{github.workspace}}/artifacts

.github/workflows/main.yml

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
name: Build and Test
1+
# This worflow is triggered on push to main, pull request, or by manual invocation.
2+
# It builds and unit tests the codebase.
3+
name: Build and Unit Test
24

35
on:
46
workflow_dispatch:
@@ -10,51 +12,35 @@ on:
1012

1113
jobs:
1214
build: # Test, pack and publish the Open AI nuget package as a build artifact
15+
name: Build
1316
runs-on: ubuntu-latest
1417
env:
1518
version_suffix_args: ${{ format('--version-suffix="alpha.{0}"', github.run_number) }}
1619
steps:
1720
- name: Setup .NET
18-
uses: actions/setup-dotnet@v1
21+
uses: actions/setup-dotnet@v3
1922
with:
20-
dotnet-version: 8.x
23+
dotnet-version: '8.x'
2124

2225
- name: Checkout code
2326
uses: actions/checkout@v2
2427

25-
- name: Build and Pack
28+
- name: Build and pack
2629
run: dotnet pack
2730
--configuration Release
2831
--output "${{github.workspace}}/artifacts/packages"
2932
${{ env.version_suffix_args }}
3033

31-
- name: Test
34+
- name: Run unit tests
3235
run: dotnet test
3336
--configuration Release
34-
--filter="TestCategory~${{ github.event_name == 'pull_request' && 'Offline' || 'Online' }}|TestCategory~Smoke"
35-
--logger "trx;LogFileName=${{github.workspace}}/artifacts/test-results/full.trx"
36-
env:
37-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
37+
--filter="TestCategory=Smoke&TestCategory!=Manual"
38+
--logger "trx;LogFilePrefix=smoke"
39+
--results-directory ${{github.workspace}}/artifacts/test-results
3840

3941
- name: Upload artifact
4042
uses: actions/upload-artifact@v2
43+
if: ${{ !cancelled() }}
4144
with:
4245
name: build-artifacts
4346
path: ${{github.workspace}}/artifacts
44-
45-
- name: NuGet Autenticate
46-
if: github.event_name != 'pull_request'
47-
run: dotnet nuget add source
48-
"https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
49-
--name "github"
50-
--username ${{ github.actor }}
51-
--password ${{ secrets.GITHUB_TOKEN }}
52-
--store-password-in-clear-text
53-
54-
- name: Publish
55-
if: github.event_name != 'pull_request'
56-
run: dotnet nuget push
57-
${{github.workspace}}/artifacts/packages/*.nupkg
58-
--source "github"
59-
--api-key ${{ secrets.GITHUB_TOKEN }}
60-
--skip-duplicate

.github/workflows/release.yml

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,104 @@
1+
# This workflow is triggered by new releases and on a daily schedule.
2+
# It builds, unit tests, live tests and published the Open AI nuget package.
3+
# For daily runs, the package is published to the GitHub package registry.
4+
# For releases, the package is published to the NuGet package registry.
15
name: Release package
26

37
on:
48
release:
59
types: [published]
10+
schedule:
11+
# run every day at 00:00
12+
- cron: '0 0 * * *'
613

714
jobs:
8-
deploy:
15+
build:
16+
name: Build
917
runs-on: ubuntu-latest
18+
environment: Live Testing
19+
env:
20+
version_suffix_args: ${{ github.event_name == 'schedule' && format('--version-suffix="alpha.{0}"', github.run_number) || '' }}
1021
permissions:
1122
packages: write
1223
contents: write
1324
steps:
14-
- uses: actions/checkout@v4
15-
- uses: actions/setup-dotnet@v3
25+
- name: Setup .NET
26+
uses: actions/setup-dotnet@v3
1627
with:
17-
dotnet-version: '8.x' # SDK Version to use.
28+
dotnet-version: '8.x'
29+
30+
- name: Checkout code
31+
uses: actions/checkout@v2
1832

1933
# Pack the client nuget package and include url back to the repository and release tag
2034
- name: Build and Pack
2135
run: dotnet pack
2236
--configuration Release
23-
--output "${{github.workspace}}/artifacts/packages"
37+
--output "${{ github.workspace }}/artifacts/packages"
2438
/p:PackageProjectUrl="${{ github.server_url }}/${{ github.repository }}/tree/${{ github.event.release.tag_name }}"
2539
/p:PackageReleaseNotes="${{ github.server_url }}/${{ github.repository }}/blob/${{ github.event.release.tag_name }}/CHANGELOG.md"
40+
${{ env.version_suffix_args }}
2641

27-
- name: Test
42+
- name: Unit Test
43+
run: dotnet test
44+
--configuration Release
45+
--filter="TestCategory=Smoke&TestCategory!=Manual"
46+
--logger "trx;LogFileName=${{ github.workspace }}/artifacts/test-results/smoke.trx"
47+
${{ env.version_suffix_args }}
48+
49+
- name: Run Live Tests
2850
run: dotnet test
2951
--configuration Release
30-
--filter="TestCategory~Online"
31-
--logger "trx;LogFileName=${{github.workspace}}/artifacts/test-results/full.trx"
52+
--filter="TestCategory!=Smoke&TestCategory!=Images&TestCategory!=Moderations&TestCategory!=Manual"
53+
--logger "trx;LogFilePrefix=live"
54+
--results-directory ${{ github.workspace }}/artifacts/test-results
55+
${{ env.version_suffix_args }}
3256
env:
3357
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
3458

59+
- name: Upload artifact
60+
uses: actions/upload-artifact@v2
61+
if: ${{ !cancelled() }}
62+
with:
63+
name: build-artifacts
64+
path: ${{ github.workspace }}/artifacts
65+
66+
deploy:
67+
name: Publish Package
68+
needs: build
69+
runs-on: ubuntu-latest
70+
permissions:
71+
packages: write
72+
contents: write
73+
steps:
74+
- uses: actions/download-artifact@v2
75+
3576
# Append the nuget package to the github release that triggered this workflow
3677
- name: Upload release asset
78+
if: github.event_name == 'release'
3779
run: gh release upload ${{ github.event.release.tag_name }}
38-
${{github.workspace}}/artifacts/packages/*.*nupkg
80+
${{ github.workspace }}/build-artifacts/packages/*.*nupkg
3981
env:
4082
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4183

42-
- name: Upload artifact
43-
uses: actions/upload-artifact@v2
44-
with:
45-
name: build-artifacts
46-
path: ${{github.workspace}}/artifacts
84+
- name: NuGet authenticate
85+
run: dotnet nuget add source
86+
"https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
87+
--name "github"
88+
--username ${{ github.actor }}
89+
--password ${{ secrets.GITHUB_TOKEN }}
90+
--store-password-in-clear-text
91+
92+
- name: Publish package to local feed
93+
run: dotnet nuget push
94+
${{github.workspace}}/build-artifacts/packages/*.nupkg
95+
--source github
96+
--skip-duplicate
4797

48-
- name: Publish
98+
- name: Publish package to nuget.org
99+
if: github.event_name == 'release'
49100
run: dotnet nuget push
50-
${{github.workspace}}/artifacts/packages/*.nupkg
51-
--source https://api.nuget.org/v3/index.json
52-
--api-key ${{ secrets.NUGET_API_KEY }}
53-
--skip-duplicate
101+
${{github.workspace}}/build-artifacts/packages/*.nupkg
102+
--source https://api.nuget.org/v3/index.json
103+
--api-key ${{ secrets.NUGET_API_KEY }}
104+
--skip-duplicate

0 commit comments

Comments
 (0)