Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dotnet] Add dotnet build workflow #946

Merged
merged 19 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/dotnet/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: dotnet-ci

on:
pull_request:
branches: [ "main" ]
paths:
- 'dotnet/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

permissions:
contents: read

jobs:
build:
name: CI
runs-on: ubuntu-latest
defaults:
run:
working-directory: dotnet
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
global-json-file: global.json
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Unit Test
run: dotnet test --no-build --verbosity normal
53 changes: 53 additions & 0 deletions .github/workflows/dotnet/run_openai_test_and_notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: run-openai-test-and-notebooks

on:
pull_request_target:
branches: [ "main" ]
paths:
- 'dotnet/**'
env:
BUILD_CONFIGURATION: Release # set this to the appropriate build configuration

jobs:
build:
environment: openai1
LittleLittleCloud marked this conversation as resolved.
Show resolved Hide resolved
name: run-openai-test-and-notebooks
runs-on: ubuntu-latest
defaults:
run:
working-directory: dotnet
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
global-json-file: global.json

- name: Restore dependencies
run: dotnet restore
- name: Restore tool
run: dotnet tool restore
- name: Build
run: dotnet build --no-restore -p:VersionSuffix=$GITHUB_RUN_ID --configuration '${{ env.BUILD_CONFIGURATION }}'
- name: Pack
run: dotnet pack --no-restore -p:VersionSuffix=$GITHUB_RUN_ID --no-build --configuration '${{ env.BUILD_CONFIGURATION }}' --output ./artifacts
- name: run all tests
run: dotnet test --no-restore --no-build --configuration '${{ env.BUILD_CONFIGURATION }}'
env:
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_GPT_35_MODEL_ID: ${{ secrets.AZURE_GPT_35_MODEL_ID }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

- name: Add local feed
run: dotnet nuget add source --name local artifacts --configfile NuGet.config
- name: Perform a Pester test from the .tools/run_all_notebooks.ps1
shell: pwsh
run: |
Invoke-Pester .tools/run_all_notebook.ps1 -Passthru
env:
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_GPT_35_MODEL_ID: ${{ secrets.AZURE_GPT_35_MODEL_ID }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

9 changes: 6 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ name: Code formatting

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on: # Trigger the workflow on push or pull request, but only for the main branch
ekzhu marked this conversation as resolved.
Show resolved Hide resolved
push:
branches: [main]
pull_request: {}
pull_request:
branches: [ "main" ]
ekzhu marked this conversation as resolved.
Show resolved Hide resolved
paths:
- '.pre-commit-config.yaml'
- 'autogen/**'
- 'samples/**'
sonichi marked this conversation as resolved.
Show resolved Hide resolved

defaults:
run:
Expand Down
12 changes: 12 additions & 0 deletions dotnet/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-repl": {
"version": "0.1.205",
"commands": [
"dotnet-repl"
]
}
}
}
64 changes: 64 additions & 0 deletions dotnet/.tools/run_all_notebook.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# cd to the directory of this script
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$rootPath = Split-Path -Parent $scriptPath
$outputFolder = "$rootPath/output"
if (Test-Path $outputFolder) {
Remove-Item $outputFolder -Recurse -Force
}
New-Item -ItemType Directory -Path $outputFolder

Set-Location $rootPath

# list all notebooks under notebook folder
$notebooks = Get-ChildItem -Path "$rootPath/notebook" -Recurse -Include *.ipynb | ForEach-Object { $_.FullName }
# skip those notebooks with the same name as the following
$skip_notebooks = @(
'TwoAgentChat_UserProxy.ipynb' # require user input
)

# for each notebook, run it using dotnet perl. Check the exit code and print out the result
# if the exit code is not 0, exit the script with exit code 1
$failNotebooks = @()
$exitCode = 0
$LASTEXITCODE = 0
foreach ($notebook in $notebooks) {
Write-Host "Running $notebook"
# get notebook name with extension
$name = Split-Path -Leaf $notebook

if ($skip_notebooks -contains $name) {
Write-Host "Skipping $name"
continue
}
Write-Host "Name: $name"
$notebookFolder = Split-Path -Parent $notebook
$outputPath = "$outputFolder\$notebookFolder"
Set-Location $notebookFolder
$proc = Start-Process -FilePath dotnet -ArgumentList "repl --run $name --exit-after-run" -PassThru -NoNewWindow
$timeout = $null
$proc | Wait-Process -Timeout 180 -ErrorAction SilentlyContinue -ErrorVariable $timeout
if ($timeout) {
Write-Host "Timeout when running $notebook"
$LASTEXITCODE = 1
}
else {
$LASTEXITCODE = $proc.ExitCode
}
Write-Host "Exit code: $LASTEXITCODE"
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to run $notebook"
$failNotebooks += $notebook
$exitCode = 1
}
else{
Write-Host "Successfully ran $notebook"
}
Set-Location $rootPath
}

Write-Host "Failed notebooks:"
foreach ($notebook in $failNotebooks) {
Write-Host $notebook
}

$failNotebooks | Should -BeNullOrEmpty