Skip to content

Commit 50ece14

Browse files
workflow for speechmatics-dotnet
1 parent 3b0ef7a commit 50ece14

24 files changed

Lines changed: 353 additions & 152 deletions

.github/workflows/dotnet.yml

Lines changed: 164 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,187 @@ name: .NET
55

66
on:
77
push:
8-
branches: [ "master" ]
8+
tags:
9+
- 'v[0-9]+.[0-9]+.[0-9]+'
10+
- 'v[0-9]+.[0-9]+.[0-9]+-*'
911
pull_request:
10-
branches: [ "master" ]
1112

1213
jobs:
13-
build:
14+
format-check:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Setup .NET
20+
uses: actions/setup-dotnet@v3
21+
with:
22+
dotnet-version: 8.0.x
23+
- name: Restore dependencies
24+
run: dotnet restore
25+
working-directory: ./SmRtAPI
26+
- name: lint
27+
run: dotnet format --verify-no-changes
28+
working-directory: ./SmRtAPI
1429

30+
build:
1531
runs-on: ubuntu-latest
1632

1733
steps:
1834
- uses: actions/checkout@v3
1935
- name: Setup .NET
2036
uses: actions/setup-dotnet@v3
2137
with:
22-
dotnet-version: 6.0.x
38+
dotnet-version: 8.0.x
2339
- name: Restore dependencies
2440
run: dotnet restore
2541
working-directory: ./SmRtAPI
42+
- name: Lint
43+
run: dotnet format --verify-no-changes
44+
working-directory: ./SmRtAPI
2645
- name: Build
2746
run: dotnet build --no-restore SmRtAPI
2847
working-directory: ./SmRtAPI
2948
- name: Test
3049
run: dotnet test --no-build --verbosity normal SmRtAPI
3150
working-directory: ./SmRtAPI
51+
52+
package:
53+
runs-on: ubuntu-latest
54+
outputs:
55+
nuget_repo: ${{ steps.version.outputs.nuget_repo }}
56+
steps:
57+
- uses: actions/checkout@v3
58+
- name: Setup .NET
59+
uses: actions/setup-dotnet@v3
60+
with:
61+
dotnet-version: 8.0.x
62+
- name: Extract version from tag, choose nuget repo
63+
id: version
64+
run: |
65+
set -euxo pipefail
66+
NUGET_REPO="https://api.nuget.org/v3/index.json"
67+
TAG_NAME="${GITHUB_REF##*/}" # e.g., v2.0.0
68+
69+
if [[ "$TAG_NAME" != "merge" ]] && [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
70+
echo "Invalid SemVer tag: $TAG_NAME"
71+
exit 1
72+
fi
73+
74+
VERSION="${TAG_NAME#v}" # strip the leading "v"
75+
76+
if [[ "$VERSION" = "merge" ]]; then
77+
# If it's not a tag, use a fixed version for the package, which will not be published
78+
# text 'merge' comes from parsing "refs/pull/PULL_REQUEST_NUMBER/merge"
79+
PR_NUMBER=$(echo "$GITHUB_REF" | sed -n 's#refs/pull/\([0-9]\+\)/merge#\1#p')
80+
VERSION="2.0.${PR_NUMBER}"
81+
fi
82+
83+
PACKAGE_VERSION=$VERSION
84+
85+
if [[ "$VERSION" == *-rc* ]]; then
86+
# If it's a release candidate, use the test NuGet repo
87+
SUFFIX="${VERSION#*-}"
88+
VERSION="${VERSION%%-*}"
89+
NUGET_REPO="https://apiint.nugettest.org/v3/index.json"
90+
fi
91+
92+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
93+
echo "nuget_repo=$NUGET_REPO" >> "$GITHUB_OUTPUT"
94+
echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
95+
- name: Restore dependencies
96+
run: dotnet restore
97+
working-directory: ./SmRtAPI/SmRtAPI
98+
- name: Pack NuGet Package
99+
run: |
100+
set -euxo pipefail
101+
mkdir -p ../docs
102+
cp ../../README.md ../docs/README.md
103+
COMMIT_SHA=$(git rev-parse HEAD)
104+
105+
dotnet pack \
106+
-p:PackageLicenseExpression=MIT \
107+
-p:PackageVersion=${{ steps.version.outputs.package_version }} \
108+
-p:Version=${{ steps.version.outputs.version }} \
109+
-p:AssemblyVersion=${{ steps.version.outputs.version }}.0 \
110+
-p:RepositoryCommit=$COMMIT_SHA \
111+
-p:Configuration=Release \
112+
-p:PackageProjectUrl="https://github.com/speechmatics/speechmatics-dotnet" \
113+
-o ../../nupkgs
114+
working-directory: ./SmRtAPI/SmRtAPI
115+
- name: Upload NuGet Packages to gibhub
116+
uses: actions/upload-artifact@v4
117+
with:
118+
name: nupkgs
119+
path: nupkgs/*.nupkg
120+
retention-days: 1
121+
122+
sign:
123+
runs-on: windows-latest
124+
needs: package
125+
env:
126+
APP_ID: ${{ secrets.APP_ID }}
127+
TENANT_ID: ${{ secrets.TENANT_ID }}
128+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
129+
steps:
130+
- uses: actions/download-artifact@v4
131+
with:
132+
name: nupkgs
133+
path: nupkgs
134+
- name: Sign
135+
shell: pwsh
136+
run: |
137+
$timeserver = "http://timestamp.digicert.com"
138+
$certificate_name = "GlobalSign-Code-Signing-Certificate"
139+
140+
dotnet tool install --tool-path . NuGetKeyVaultSignTool
141+
142+
$nupkgFiles = Get-ChildItem -Path nupkgs -Filter *.nupkg
143+
if ($nupkgFiles.Count -eq 0) {
144+
Write-Host "No .nupkg files found in the directory."
145+
exit 1
146+
}
147+
foreach ($file in $nupkgFiles) {
148+
Write-Output "Signing $file"
149+
./NuGetKeyVaultSignTool sign $file `
150+
--azure-key-vault-tenant-id "${{ env.TENANT_ID }}" `
151+
--azure-key-vault-url "https://signing-key.vault.azure.net/" `
152+
--azure-key-vault-client-id "${{ env.APP_ID }}" `
153+
--azure-key-vault-client-secret "${{ env.AZURE_CLIENT_SECRET }}" `
154+
--azure-key-vault-certificate "$certificate_name" `
155+
--timestamp-rfc3161 $timeserver
156+
}
157+
- name: Upload signed NuGet packages to github
158+
uses: actions/upload-artifact@v4
159+
with:
160+
name: signed_nupkgs
161+
path: nupkgs/*.nupkg
162+
retention-days: 1
163+
164+
publish:
165+
runs-on: ubuntu-latest
166+
if: startsWith(github.ref, 'refs/tags/v')
167+
needs: ["sign", "package"]
168+
env:
169+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
170+
NUGET_API_KEY_TESTING: ${{ secrets.NUGET_API_KEY_TESTING }}
171+
steps:
172+
- uses: actions/download-artifact@v4
173+
with:
174+
name: signed_nupkgs
175+
path: nupkgs
176+
- name: Publish nuget packages
177+
shell: bash
178+
run: |
179+
set -euxo pipefail
180+
NUGET_REPO="${{ needs.package.outputs.nuget_repo }}"
181+
182+
if [[ "$NUGET_REPO" == *nugettest* ]]; then
183+
echo "Publishing to test NuGet repo"
184+
NUGET_API_KEY="$NUGET_API_KEY_TESTING"
185+
fi
186+
187+
for file in nupkgs/*.nupkg; do
188+
echo "Publishing $file"
189+
dotnet nuget verify $file
190+
dotnet nuget push $file --api-key "$NUGET_API_KEY" --source "$NUGET_REPO"
191+
done

SmRtAPI/DemoApp/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,21 @@ public static void Main(string[] args)
5858
AddPartialTranslationMessageCallback = s => Console.WriteLine(ToJson(s)),
5959
ErrorMessageCallback = s => Console.WriteLine(ToJson(s)),
6060
WarningMessageCallback = s => Console.WriteLine(ToJson(s)),
61-
CustomDictionaryPlainWords = new[] {"speechmagic"},
61+
CustomDictionaryPlainWords = new[] { "speechmagic" },
6262
CustomDictionarySoundsLikes = new Dictionary<string, IEnumerable<string>>(),
6363
Insecure = true,
6464
EnablePartials = true,
6565
EnableEntities = true,
66-
Diarization=DiarizationType.Speaker,
67-
TranslationConfig = new TranslationConfig() {
68-
TargetLanguages = new [] {"de"},
66+
Diarization = DiarizationType.Speaker,
67+
TranslationConfig = new TranslationConfig()
68+
{
69+
TargetLanguages = new[] { "de" },
6970
EnablePartials = true
7071
}
7172
};
7273

7374
// We can do this here, or earlier. It's not used until .Run() is called on the API object.
74-
config.CustomDictionarySoundsLikes["gnocchi"] = new[] {"nokey", "noki"};
75+
config.CustomDictionarySoundsLikes["gnocchi"] = new[] { "nokey", "noki" };
7576

7677
var api = new SmRtApi(RtUrl,
7778
stream,
@@ -89,7 +90,7 @@ public static void Main(string[] args)
8990
}
9091

9192
var finish = DateTime.Now;
92-
Debug.WriteLine("Starting at {0} -- {1}", finish, finish-start);
93+
Debug.WriteLine("Starting at {0} -- {1}", finish, finish - start);
9394
Console.ReadLine();
9495
}
9596
}

SmRtAPI/DemoAppNetCore/DemoAppNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

SmRtAPI/SmRtAPI/Config/SmRtApiConfig.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ public class SmRtApiConfig : SmRtApiConfigBase
1212
/// <summary>
1313
/// Action to perform on extended partial transcript data
1414
/// </summary>
15-
public Action<AddPartialTranscriptMessage> AddPartialTranscriptMessageCallback { get; set; }
15+
public Action<AddPartialTranscriptMessage>? AddPartialTranscriptMessageCallback { get; set; }
1616

1717
/// <summary>
1818
/// Action to perform on extended transcript data
1919
/// </summary>
20-
public Action<AddTranscriptMessage> AddTranscriptMessageCallback { get; set; }
20+
public Action<AddTranscriptMessage>? AddTranscriptMessageCallback { get; set; }
2121

2222
/// <summary>
2323
/// Action to perform on partial translation data
2424
/// </summary>
25-
public Action<AddPartialTranslationMessage> AddPartialTranslationMessageCallback { get; set; }
25+
public Action<AddPartialTranslationMessage>? AddPartialTranslationMessageCallback { get; set; }
2626

2727
/// <summary>
2828
/// Action to perform on translation data
2929
/// </summary>
30-
public Action<AddTranslationMessage> AddTranslationMessageCallback { get; set; }
30+
public Action<AddTranslationMessage>? AddTranslationMessageCallback { get; set; }
3131

3232
/// <summary>
3333
/// Create new config for a given language,

SmRtAPI/SmRtAPI/Config/TranslationConfig.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
using System;
21
using System.Collections.Generic;
3-
using System.Text;
42

53
namespace Speechmatics.Realtime.Client.Config
64
{
75

86
/// <summary>
97
/// Additional configuration for translation
108
/// </summary>
11-
public class TranslationConfig {
9+
public class TranslationConfig
10+
{
1211

1312
/// <summary>
1413
/// List of target languages to translate to
1514
/// </summary>
16-
public IEnumerable<string> TargetLanguages { get; set; }
15+
public IEnumerable<string> TargetLanguages { get; set; } = new List<string>();
1716

1817
/// <summary>
1918
/// Flag for enabling translation partials.

SmRtAPI/SmRtAPI/Enumerations/AudioFormatEncoding.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
88
*/
99

10-
/// <summary>
11-
/// Type of audio
12-
/// </summary>
10+
/// <summary>
11+
/// Type of audio
12+
/// </summary>
1313
public enum AudioFormatEncoding
1414
{
1515
/// <summary>

0 commit comments

Comments
 (0)