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

Add workflows for build and release #2

Merged
merged 9 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The workflows in this repository try to follow existing, basic samples with little customization.

## main.yml
We use a standard dotnet build/test/pack workflow
https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

- Build the solution using the dotnet cli
- Strong name the assemblies using a key stored in the repository
https://github.com/dotnet/runtime/blob/main/docs/project/strong-name-signing.md
- Test the built libraries
- In a PR run, only local tests are run.
- In a CI run, live tests are run using a repository secret containing an OpenAI token
https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions
- Package the built libraries
- Publish the package to a GitHub NuGet registry
https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry
- Publish a single build artifact containing test results and a nuget package

## release.yml
Releases are triggered by publishing a release in the GitHub repository. The release workflow will:

- Build the solution using the dotnet cli
- Strong name the assemblies using a key stored in the repository
- Test the built libraries
- Live tests are run using a repository secret containing an OpenAI token
- Package the built libraries
- Publish the package to public NuGet registry
- Publish a single build artifact containing test results and a nuget package
60 changes: 60 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build and Test

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]

jobs:
build: # Test, pack and publish the Open AI nuget package as a build artifact
runs-on: ubuntu-latest
env:
version_suffix_args: ${{ format('--version-suffix="alpha.{0}"', github.run_number) }}
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.x

- name: Checkout code
uses: actions/checkout@v2

- name: Build and Pack
run: dotnet pack
--configuration Release
--output "${{github.workspace}}/artifacts/packages"
${{ env.version_suffix_args }}

- name: Test
run: dotnet test
--configuration Release
--filter="TestCategory~${{ github.event_name == 'pull_request' && 'Offline' || 'Online' }}"
--logger "trx;LogFileName=${{github.workspace}}/artifacts/test-results/full.trx"
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
weshaggard marked this conversation as resolved.
Show resolved Hide resolved

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: ${{github.workspace}}/artifacts

- name: NuGet Autenticate
if: github.event_name != 'pull_request'
run: dotnet nuget add source
"https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
--name "github"
--username ${{ github.actor }}
--password ${{ secrets.GITHUB_TOKEN }}
--store-password-in-clear-text

- name: Publish
if: github.event_name != 'pull_request'
run: dotnet nuget push
${{github.workspace}}/artifacts/packages/*.nupkg
--source "github"
--api-key ${{ secrets.GITHUB_TOKEN }}
--skip-duplicate
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release package

on:
release:
types: [published]
weshaggard marked this conversation as resolved.
Show resolved Hide resolved

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x' # SDK Version to use.

# Pack the client nuget package and include urls back to the repository and release tag
- name: Build and Pack
run: dotnet pack
--configuration Release
--output "${{github.workspace}}/artifacts/packages"
/p:RepositoryUrl="${{ github.repository }}"
/p:PackageProjectUrl="${{ github.repository }}/tree/${{ github.event.release.tag_name }}"

- name: Test
run: dotnet test
--configuration Release
--filter="TestCategory~Online"
--logger "trx;LogFileName=${{github.workspace}}/artifacts/test-results/full.trx"
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

# Append the nuget package to the github release that triggered this workflow
- name: Upload release asset
run: gh release upload ${{ github.event.release.tag_name }}
${{github.workspace}}/artifacts/packages/*.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: build-artifacts
path: ${{github.workspace}}/artifacts

# - name: Publish
# run: dotnet nuget push
# ${{github.workspace}}/artifacts/packages/*.nupkg
# --source https://api.nuget.org/v3/index.json
# --api-key ${{ secrets.NUGET_API_KEY }}
# --skip-duplicate
8 changes: 0 additions & 8 deletions src/Directory.Build.props

This file was deleted.

31 changes: 28 additions & 3 deletions src/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,40 @@
<PropertyGroup>
<Description>This is the OpenAI client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation OpenAI</AssemblyTitle>
<Version>2.0.0-beta.1</Version>
<PackageTags>OpenAI</PackageTags>

<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix>beta.1</VersionSuffix>

<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>

<!-- Sign the assembly with the specified key file. -->
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>OpenAI.snk</AssemblyOriginatorKeyFile>

<!-- Generate an XML documentation file for the project. -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>False</SignAssembly>

<!-- Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>

<!-- Create a .snupkg file in addition to the .nupkg file. -->
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<!-- Embed source files that are not tracked by the source control manager in the PDB -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<!-- Normalize stored file paths in symbols when in a CI build. -->
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="System.ClientModel" Version="1.1.0-beta.4" />
<PackageReference Include="System.Text.Json" Version="8.0.2" />
</ItemGroup>
</Project>
</Project>
6 changes: 0 additions & 6 deletions src/Properties/AssemblyInfo.cs

This file was deleted.

Loading