Skip to content

Commit d9988d7

Browse files
authored
ci: add ci for test and auto-release. (#1047)
* Add unittest redist holder for all test projects. * Move redist holder to another folder. * Create dotnet.yml to config github action * Revise the sln file. * Update dotnet.yml * Add version to tensorflow.hub. * Create release.yml * Update dotnet.yml * Update and rename dotnet.yml to build_and_test.yml * Update release.yml * Update release.yml * Revise project using. * Update build_and_test.yml * Update release.yml * Update the package info of Tensorflow.Hub. * Add a tolorance to equivalence of NDArray. * Create semantic.yml * fix: run code clean. * Update release.yml * Update release.yml * ci: revise the auto release ci. * ci: update release ci. * ci: update release ci. * ci: update ci files. * ci: update ci files. * ci: update ci files. * ci: update ci files. * ci: update ci files. * ci: update release ci and hub package info. * ci: revise build_and_test ci. * test: add tolorance to float NDArray comparison. * ci: disable linux test. * ci: update release ci. * Update release.yml * ci: update release ci. * ci: revise auto-release ci. * ci: update auto-release ci. * Update release.yml * ci: specify packed project names of auto-release. * ci: revise auto release ci file. * ci: revise auto-release ci file. * ci: revise auto-release ci file. * ci: revise auto-release ci file. * Update release.yml * ci: revise auto-release ci file. * ci: revise auto-release ci file. * ci: revise auto-release ci file.
1 parent 179e32a commit d9988d7

File tree

18 files changed

+280
-28
lines changed

18 files changed

+280
-28
lines changed

.github/workflows/build_and_test.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: build_and_test
5+
6+
on:
7+
push:
8+
branches: [ "master" ]
9+
pull_request:
10+
branches: [ "master" ]
11+
types: ["opened", "reopened", "synchronize", "ready_for_review", "auto_merge_enabled"]
12+
13+
jobs:
14+
windows:
15+
16+
runs-on: windows-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Setup .NET 6
21+
uses: actions/setup-dotnet@v3
22+
with:
23+
dotnet-version: 6.0.x
24+
- name: Restore dependencies
25+
run: dotnet restore
26+
- name: Build CPU version
27+
run: dotnet build --no-restore
28+
- name: Test CPU version
29+
run: dotnet test --no-build --verbosity normal
30+
- name: uninstall redist cpu for unit tests
31+
run: dotnet remove helpers/Tensorflow.UnitTest.RedistHolder package SciSharp.TensorFlow.Redist
32+
- name: install redist gpu for unit tests
33+
run: dotnet add helpers/Tensorflow.UnitTest.RedistHolder package SciSharp.TensorFlow.Redist-Windows-GPU
34+
- name: Restore dependencies
35+
run: dotnet restore
36+
- name: Build GPU version
37+
run: dotnet build --no-restore
38+
# - name: Test GPU version
39+
# run: dotnet test --no-build --verbosity normal
40+
41+
linux:
42+
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v3
47+
- name: Setup .NET
48+
uses: actions/setup-dotnet@v3
49+
with:
50+
dotnet-version: 6.0.x
51+
- name: Restore dependencies
52+
run: dotnet restore
53+
- name: Build CPU version
54+
run: dotnet build --no-restore
55+
# - name: Test CPU version
56+
# run: dotnet test --no-build --verbosity normal
57+
- name: uninstall redist cpu for unit tests
58+
run: dotnet remove helpers/Tensorflow.UnitTest.RedistHolder package SciSharp.TensorFlow.Redist
59+
- name: install redist gpu for unit tests
60+
run: dotnet add helpers/Tensorflow.UnitTest.RedistHolder package SciSharp.TensorFlow.Redist-Linux-GPU
61+
- name: Restore dependencies
62+
run: dotnet restore
63+
- name: Build GPU version
64+
run: dotnet build --no-restore
65+
# - name: Test GPU version
66+
# run: dotnet test --no-build --verbosity normal

.github/workflows/release.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: auto-release
2+
3+
on:
4+
label:
5+
types: [created, edited]
6+
pull_request:
7+
branches:
8+
- master
9+
types: [ labeled, opened, reopened, synchronize ]
10+
11+
env:
12+
MYGET_API_TOKEN: ${{ SECRETS.RINNE_MYGET_KEY }}
13+
GITHUB_TOKEN: ${{ SECRETS.RINNE_GITHUB_TOKEN }}
14+
15+
jobs:
16+
build:
17+
if: contains(github.event.pull_request.labels.*.name, 'auto-release')
18+
runs-on: windows-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Setup .NET 6.0.x SDK
23+
uses: actions/setup-dotnet@v3
24+
with:
25+
dotnet-version: 6.0.x
26+
27+
- name: Check .NET info
28+
run: dotnet --info
29+
30+
- name: Install dependencies
31+
run: dotnet restore
32+
33+
- name: Build solution
34+
run: dotnet build -c Release --no-restore
35+
36+
# run-semantic-release:
37+
# runs-on: ubuntu-latest
38+
# needs: build
39+
40+
# steps:
41+
# - name: Checkout
42+
# uses: actions/checkout@v2
43+
44+
# - name: Run semantic-release
45+
# run: |
46+
# export PATH=$PATH:$(yarn global bin)
47+
# yarn global add semantic-release@17.4.3
48+
# semantic-release
49+
50+
release:
51+
runs-on: windows-latest
52+
# needs: run-semantic-release
53+
needs: build
54+
55+
steps:
56+
- uses: actions/checkout@v3
57+
- name: Setup .NET 6.0.x SDK
58+
uses: actions/setup-dotnet@v3
59+
with:
60+
dotnet-version: 6.0.x
61+
62+
- name: Check .NET info
63+
run: dotnet --info
64+
65+
- name: Install dependencies
66+
run: dotnet restore
67+
68+
- name: Build solution
69+
run: dotnet build -c Release --no-restore
70+
71+
- name: Pack packages
72+
run: |
73+
git fetch --unshallow;
74+
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*";
75+
git fetch origin;
76+
$LastTag = git describe --tags;
77+
echo "Last tag is: $LastTag";
78+
$Version = ($LastTag).TrimStart('v') + "-preview";
79+
echo "Publishing version: $Version";
80+
dotnet pack ./src/TensorFlowNET.Core/Tensorflow.Binding.csproj -c Release -o packages /p:PackageVersion=$Version /p:Version=$Version;
81+
dotnet pack ./src/TensorFlowNET.Keras/Tensorflow.Keras.csproj -c Release -o packages /p:PackageVersion=$Version /p:Version=$Version;
82+
dotnet pack ./src/TensorflowNET.Hub/Tensorflow.Hub.csproj -c Release -o packages /p:PackageVersion=$Version /p:Version=$Version;
83+
84+
if($LastExitCode -ne 0)
85+
{
86+
Write-Warning -Message "Pack packages warming, last exit code is ${LastExitCode}."
87+
$LastExitCode = 0;
88+
}
89+
90+
- name: Upload packages artifacts
91+
uses: actions/upload-artifact@v1.0.0
92+
with:
93+
name: "drop-ci-packages"
94+
path: './packages'
95+
96+
- name: Add myget nuget source
97+
run: dotnet nuget add source https://www.myget.org/F/rinne/api/v2/package --name myget.org
98+
99+
- name: Push TensorFlow.NET to myget.org
100+
run: dotnet nuget push .\packages\TensorFlow*.nupkg -s myget.org -k $env:MYGET_API_TOKEN --skip-duplicate

.github/workflows/semantic.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Semantic
2+
3+
on:
4+
pull_request:
5+
branches: [ "master" ]
6+
7+
jobs:
8+
semantic-pull-request:
9+
name: Semantic check
10+
runs-on: windows-latest
11+
steps:
12+
- name: semantic-pull-request
13+
uses: amannn/action-semantic-pull-request@v4
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
with:
17+
validateSingleCommit: true

TensorFlow.NET.sln

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{01A1787F-A9B
3131
EndProject
3232
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{1B0918B9-65AD-4F34-A287-AF4597B27DBD}"
3333
EndProject
34-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "console", "console", "{E1A5D2B7-10AF-4876-85C0-7714EF274214}"
34+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helpers", "helpers", "{E1A5D2B7-10AF-4876-85C0-7714EF274214}"
35+
EndProject
36+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.UnitTest.RedistHolder", "helpers\Tensorflow.UnitTest.RedistHolder\Tensorflow.UnitTest.RedistHolder.csproj", "{62D543A2-8846-45A3-829B-5754B094A8E2}"
3537
EndProject
3638
Global
3739
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -262,13 +264,31 @@ Global
262264
{7DEA8760-E401-4872-81F3-405F185A13A0}.Release|x64.Build.0 = Release|Any CPU
263265
{7DEA8760-E401-4872-81F3-405F185A13A0}.Release|x86.ActiveCfg = Release|Any CPU
264266
{7DEA8760-E401-4872-81F3-405F185A13A0}.Release|x86.Build.0 = Release|Any CPU
267+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
268+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
269+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Debug|x64.ActiveCfg = Debug|Any CPU
270+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Debug|x64.Build.0 = Debug|Any CPU
271+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Debug|x86.ActiveCfg = Debug|Any CPU
272+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Debug|x86.Build.0 = Debug|Any CPU
273+
{62D543A2-8846-45A3-829B-5754B094A8E2}.GPU|Any CPU.ActiveCfg = Debug|Any CPU
274+
{62D543A2-8846-45A3-829B-5754B094A8E2}.GPU|Any CPU.Build.0 = Debug|Any CPU
275+
{62D543A2-8846-45A3-829B-5754B094A8E2}.GPU|x64.ActiveCfg = Debug|Any CPU
276+
{62D543A2-8846-45A3-829B-5754B094A8E2}.GPU|x64.Build.0 = Debug|Any CPU
277+
{62D543A2-8846-45A3-829B-5754B094A8E2}.GPU|x86.ActiveCfg = Debug|Any CPU
278+
{62D543A2-8846-45A3-829B-5754B094A8E2}.GPU|x86.Build.0 = Debug|Any CPU
279+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
280+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Release|Any CPU.Build.0 = Release|Any CPU
281+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Release|x64.ActiveCfg = Release|Any CPU
282+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Release|x64.Build.0 = Release|Any CPU
283+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Release|x86.ActiveCfg = Release|Any CPU
284+
{62D543A2-8846-45A3-829B-5754B094A8E2}.Release|x86.Build.0 = Release|Any CPU
265285
EndGlobalSection
266286
GlobalSection(SolutionProperties) = preSolution
267287
HideSolutionNode = FALSE
268288
EndGlobalSection
269289
GlobalSection(NestedProjects) = preSolution
270290
{FD682AC0-7B2D-45D3-8B0D-C6D678B04144} = {01A1787F-A9BE-4221-84E8-6360DD010AB6}
271-
{3A6EB896-604F-4E25-B677-B8103BCF3D2E} = {1B0918B9-65AD-4F34-A287-AF4597B27DBD}
291+
{3A6EB896-604F-4E25-B677-B8103BCF3D2E} = {E1A5D2B7-10AF-4876-85C0-7714EF274214}
272292
{23C28035-2FCE-41F3-9A12-E73CE8A5AE32} = {1B0918B9-65AD-4F34-A287-AF4597B27DBD}
273293
{03F06299-3F4B-4449-A709-3A647657BC0C} = {E1A5D2B7-10AF-4876-85C0-7714EF274214}
274294
{49D71826-C03D-4FA7-9BAC-22C1327E65CF} = {01A1787F-A9BE-4221-84E8-6360DD010AB6}
@@ -279,6 +299,7 @@ Global
279299
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3} = {1B0918B9-65AD-4F34-A287-AF4597B27DBD}
280300
{9738D16A-CFA0-405C-A7DF-D3D203B0CB18} = {01A1787F-A9BE-4221-84E8-6360DD010AB6}
281301
{7DEA8760-E401-4872-81F3-405F185A13A0} = {1B0918B9-65AD-4F34-A287-AF4597B27DBD}
302+
{62D543A2-8846-45A3-829B-5754B094A8E2} = {E1A5D2B7-10AF-4876-85C0-7714EF274214}
282303
EndGlobalSection
283304
GlobalSection(ExtensibilityGlobals) = postSolution
284305
SolutionGuid = {2DEAD3CC-486B-4918-A607-50B0DE7B114A}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
internal class EmptyClass
2+
{
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.11.3" />
9+
<PackageReference Include="SciSharp.TensorFlow.Redist-Lite" Version="2.6.0" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using static Tensorflow.Binding;
1+
using static Tensorflow.Binding;
62

73
namespace Tensorflow.NumPy
84
{
@@ -14,35 +10,52 @@ public partial class NDArray
1410
public static NDArray operator -(NDArray lhs, NDArray rhs) => new NDArray(BinaryOpWrapper("sub", lhs, rhs));
1511
[AutoNumPy]
1612
public static NDArray operator *(NDArray lhs, NDArray rhs) => new NDArray(BinaryOpWrapper("mul", lhs, rhs));
17-
[AutoNumPy]
13+
[AutoNumPy]
1814
public static NDArray operator /(NDArray lhs, NDArray rhs) => new NDArray(BinaryOpWrapper("div", lhs, rhs));
1915
[AutoNumPy]
2016
public static NDArray operator %(NDArray lhs, NDArray rhs) => new NDArray(BinaryOpWrapper("mod", lhs, rhs));
21-
[AutoNumPy]
17+
[AutoNumPy]
2218
public static NDArray operator >(NDArray lhs, NDArray rhs) => new NDArray(gen_math_ops.greater(lhs, rhs));
23-
[AutoNumPy]
19+
[AutoNumPy]
2420
public static NDArray operator <(NDArray lhs, NDArray rhs) => new NDArray(gen_math_ops.less(lhs, rhs));
25-
[AutoNumPy]
21+
[AutoNumPy]
2622
public static NDArray operator -(NDArray lhs) => new NDArray(gen_math_ops.neg(lhs));
2723
[AutoNumPy]
2824
public static NDArray operator ==(NDArray lhs, NDArray rhs)
2925
{
30-
if(ReferenceEquals(lhs, rhs))
26+
if (ReferenceEquals(lhs, rhs))
3127
return Scalar(true);
32-
if(lhs is null)
28+
if (lhs is null)
3329
return Scalar(false);
34-
if(rhs is null)
30+
if (rhs is null)
3531
return Scalar(false);
36-
return new NDArray(math_ops.equal(lhs, rhs));
32+
// TODO(Rinne): use np.allclose instead.
33+
if (lhs.dtype.is_floating() || rhs.dtype.is_floating())
34+
{
35+
var diff = tf.abs(lhs - rhs);
36+
return new NDArray(gen_math_ops.less(diff, new NDArray(1e-5).astype(diff.dtype)));
37+
}
38+
else
39+
{
40+
return new NDArray(math_ops.equal(lhs, rhs));
41+
}
3742
}
3843
[AutoNumPy]
3944
public static NDArray operator !=(NDArray lhs, NDArray rhs)
4045
{
41-
if(ReferenceEquals(lhs, rhs))
46+
if (ReferenceEquals(lhs, rhs))
4247
return Scalar(false);
43-
if(lhs is null || rhs is null)
48+
if (lhs is null || rhs is null)
4449
return Scalar(true);
45-
return new NDArray(math_ops.not_equal(lhs, rhs));
50+
if (lhs.dtype.is_floating() || rhs.dtype.is_floating())
51+
{
52+
var diff = tf.abs(lhs - rhs);
53+
return new NDArray(gen_math_ops.greater_equal(diff, new NDArray(1e-5).astype(diff.dtype)));
54+
}
55+
else
56+
{
57+
return new NDArray(math_ops.not_equal(lhs, rhs));
58+
}
4659
}
4760
}
4861
}

src/TensorFlowNET.Core/Tensorflow.Binding.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ https://tensorflownet.readthedocs.io</Description>
4141
<FileVersion>1.0.0.0</FileVersion>
4242
<PackageLicenseFile>LICENSE</PackageLicenseFile>
4343
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
44+
<PackageOutputPath>packages</PackageOutputPath>
4445
<SignAssembly>true</SignAssembly>
4546
<AssemblyOriginatorKeyFile>Open.snk</AssemblyOriginatorKeyFile>
4647
<Platforms>AnyCPU;x64</Platforms>

src/TensorFlowNET.Keras/Tensorflow.Keras.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Keras is an API designed for human beings, not machines. Keras follows best prac
3434
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
3535
<PackageTags>tensorflow, keras, deep learning, machine learning</PackageTags>
3636
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
37+
<PackageOutputPath>packages</PackageOutputPath>
3738
<RepositoryType>Git</RepositoryType>
3839
<SignAssembly>true</SignAssembly>
3940
<AssemblyOriginatorKeyFile>Open.snk</AssemblyOriginatorKeyFile>

src/TensorflowNET.Hub/Tensorflow.Hub.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44
<TargetFrameworks>netstandard2.0;net6</TargetFrameworks>
55
<LangVersion>10</LangVersion>
66
<Nullable>enable</Nullable>
7+
<Version>1.0.0</Version>
8+
<PackageId>TensorFlow.Hub</PackageId>
9+
<PackageLicenseExpression>Apache2.0</PackageLicenseExpression>
10+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
11+
<SignAssembly>true</SignAssembly>
12+
<Authors>Yaohui Liu, Haiping Chen</Authors>
13+
<Company>SciSharp STACK</Company>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
15+
<Copyright>Apache 2.0, Haiping Chen $([System.DateTime]::UtcNow.ToString(yyyy))</Copyright>
16+
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
17+
<RepositoryType>git</RepositoryType>
18+
<PackageProjectUrl>http://scisharpstack.org</PackageProjectUrl>
19+
<PackageIconUrl>https://avatars3.githubusercontent.com/u/44989469?s=200&amp;v=4</PackageIconUrl>
20+
<PackageTags>TensorFlow, SciSharp, Machine Learning, Deep Learning, Transfer Learning, TensorFlow Hub, TensorFlow.NET, TF.NET, AI</PackageTags>
21+
<PackageOutputPath>packages</PackageOutputPath>
22+
<Description>
23+
Google's TensorFlow Hub full binding in .NET Standard.
24+
A library for transfer learning with TensorFlow.NET.
25+
</Description>
726
</PropertyGroup>
827

928
<ItemGroup>

test/TensorFlowNET.Graph.UnitTest/TensorFlowNET.Graph.UnitTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
<PrivateAssets>all</PrivateAssets>
3232
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3333
</PackageReference>
34-
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.11.3" />
3534
</ItemGroup>
3635

3736
<ItemGroup>
37+
<ProjectReference Include="..\..\helpers\Tensorflow.UnitTest.RedistHolder\Tensorflow.UnitTest.RedistHolder.csproj" />
3838
<ProjectReference Include="..\..\src\TensorFlowNET.Core\Tensorflow.Binding.csproj" />
3939
<ProjectReference Include="..\TensorFlowNET.Keras.UnitTest\Tensorflow.Keras.UnitTest.csproj" />
4040
</ItemGroup>

test/TensorFlowNET.Keras.UnitTest/Layers/ActivationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Softplus()
4949
Tensor input = tf.constant(new float[] { -3f, -2f, -1f, 0f, 1f, 2f });
5050
Tensor output = keras.layers.Softplus().Apply(input);
5151
NDArray expected = new NDArray(new float[] { 0.04858733f, 0.12692805f, 0.31326166f, 0.6931472f, 1.3132616f, 2.126928f });
52-
Assert.AreEqual(expected, output.numpy());
52+
Assert.IsTrue(expected == output.numpy());
5353
}
5454

5555
[TestMethod]

0 commit comments

Comments
 (0)