From c681d69b5305a5ef6749725c90017af7dc62866d Mon Sep 17 00:00:00 2001 From: zhxymh Date: Sat, 8 Oct 2022 15:22:24 +0800 Subject: [PATCH 1/9] ci: upgrade dotnet version and add codecov --- azure-pipelines.yml | 30 ++++++++++++++++++++------- build.cake | 33 ++++++++++++++++++++++++++++++ build.config | 2 +- scripts/aelf-node/start-window.ps1 | 2 +- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 464e1d0..68a7151 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ jobs: - task: UseDotNet@2 displayName: 'Install .NET Core SDK' inputs: - version: 3.1.101 + version: 6.0.x - powershell: ./scripts/aelf-node/start-window.ps1 displayName: 'Build and Test' # All tasks on Linux @@ -23,13 +23,28 @@ jobs: pool: vmImage: ubuntu-18.04 steps: - - task: DotNetCoreInstaller@0 + - task: UseDotNet@2 + displayName: 'Install .NET Core SDK' inputs: - version: '3.1.101' + version: 6.0.x - script: cd scripts/aelf-node && bash start.sh displayName: 'Deploy a full node' - - script: bash build.sh -target=test + - script: bash build.sh -target=test-with-codecov displayName: 'build and test' + - task: PublishTestResults@2 + condition: always() + inputs: + testRunner: VSTest + testResultsFiles: '**/*.trx' + - task: reportgenerator@5 + displayName: ReportGenerator + inputs: + reports: '$(Build.SourcesDirectory)/test/*/TestResults/*/coverage.cobertura.xml' + targetdir: '$(Build.SourcesDirectory)/CodeCoverage' + reporttypes: 'Cobertura' + assemblyfilters: '-xunit*' + - script: bash build.sh --target=upload-coverage-azure + displayName: 'Upload data to Codecov' # All tasks on macOS - job: build_all_macos displayName: Build all tasks (macos) @@ -38,10 +53,11 @@ jobs: variables: phpVersion: 7.2 steps: - - task: DotNetCoreInstaller@0 + - task: UseDotNet@2 + displayName: 'Install .NET Core SDK' inputs: - version: '3.1.101' + version: 6.0.x - script: cd scripts/aelf-node && bash start-mac.sh displayName: 'Deploy a full node' - - script: bash build.sh -target=test + - script: bash build.sh -target=test-with-codecov displayName: 'build and test' diff --git a/build.cake b/build.cake index 3f1db00..7b869ca 100755 --- a/build.cake +++ b/build.cake @@ -1,3 +1,6 @@ +#tool nuget:?package=Codecov +#addin nuget:?package=Cake.Codecov&version=0.8.0 + var target = Argument("target", "default"); var rootPath = "./"; var srcPath = rootPath + "AElf.Client/"; @@ -62,6 +65,36 @@ Task("test") } }); +Task("test-with-codecov") + .Description("operation test") + .IsDependentOn("Build") + .Does(() => +{ + var testSetting = new DotNetCoreTestSettings{ + Configuration = configuration, + NoRestore = true, + NoBuild = true, + ArgumentCustomization = args => { + return args + .Append("--logger trx") + .Append("--settings CodeCoverage.runsettings") + .Append("--collect:\"XPlat Code Coverage\""); + } + }; + var testProjects = GetFiles("./test/*.Tests/*.csproj"); + var testProjectList = testProjects.OrderBy(p=>p.FullPath).ToList(); + foreach(var testProject in testProjectList) + { + DotNetCoreTest(testProject.FullPath, testSetting); + } +}); + +Task("upload-coverage-azure") + .Does(() => +{ + Codecov("./CodeCoverage/Cobertura.xml","$CODECOV_TOKEN"); +}); + Task("default") .Description("default run test(-target test)") .IsDependentOn("build"); diff --git a/build.config b/build.config index 803c029..015ef8e 100644 --- a/build.config +++ b/build.config @@ -1,3 +1,3 @@ #!/usr/bin/env bash CAKE_VERSION=0.37.0 -DOTNET_VERSION=3.1.101 +DOTNET_VERSION=6.0.300 diff --git a/scripts/aelf-node/start-window.ps1 b/scripts/aelf-node/start-window.ps1 index c708a48..555949a 100644 --- a/scripts/aelf-node/start-window.ps1 +++ b/scripts/aelf-node/start-window.ps1 @@ -12,4 +12,4 @@ cd aelf/aelf $job2 = Start-Job -ScriptBlock { cd D:\a\1\s\aelf\aelf; dotnet AElf.Launcher.dll; } sleep 60 cd D:\a\1\s -PowerShell.exe -file build.ps1 --target=test +PowerShell.exe -file build.ps1 --target=test-with-codecov From d8e7e2a9aedbdf04a3fb8f0fe98c56ce5bdc0e8b Mon Sep 17 00:00:00 2001 From: zhxymh Date: Sat, 8 Oct 2022 15:57:10 +0800 Subject: [PATCH 2/9] ci: fix cake script --- build.cake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 7b869ca..74422de 100755 --- a/build.cake +++ b/build.cake @@ -2,6 +2,7 @@ #addin nuget:?package=Cake.Codecov&version=0.8.0 var target = Argument("target", "default"); +var configuration = Argument("configuration", "Debug"); var rootPath = "./"; var srcPath = rootPath + "AElf.Client/"; var testPath = rootPath + "AElf.Client.Test/"; @@ -39,7 +40,7 @@ Task("build") { var buildSetting = new DotNetCoreBuildSettings{ NoRestore = true, - Configuration = "Debug", + Configuration = configuration, ArgumentCustomization = args => { return args.Append("/clp:ErrorsOnly") .Append("--no-incremental") From 2914b866bee6bbe1da7283265a3191e3d64aee32 Mon Sep 17 00:00:00 2001 From: zhxymh Date: Sat, 8 Oct 2022 16:16:58 +0800 Subject: [PATCH 3/9] ci: fix sln name --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 74422de..28cacb1 100755 --- a/build.cake +++ b/build.cake @@ -7,7 +7,7 @@ var rootPath = "./"; var srcPath = rootPath + "AElf.Client/"; var testPath = rootPath + "AElf.Client.Test/"; var distPath = rootPath + "aelf-node/"; -var solution = rootPath + "AElf.Client.sln"; +var solution = rootPath + "all.sln"; var srcProjects = GetFiles(srcPath + "AElf.Client.csproj"); Task("clean") From cf362da03b0deea71096733fc3b5bd9f1f4188d9 Mon Sep 17 00:00:00 2001 From: zhxymh Date: Sat, 8 Oct 2022 16:35:38 +0800 Subject: [PATCH 4/9] ci: fix script --- CodeCoverage.runsettings | 17 +++++++++++++++++ build.cake | 2 +- codecov.sh | 12 ++++++++++++ codecov.yml | 3 +++ test/AElf.Client.Test/AElf.Client.Test.csproj | 4 ++++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 CodeCoverage.runsettings create mode 100755 codecov.sh create mode 100755 codecov.yml diff --git a/CodeCoverage.runsettings b/CodeCoverage.runsettings new file mode 100755 index 0000000..e58b313 --- /dev/null +++ b/CodeCoverage.runsettings @@ -0,0 +1,17 @@ + + + + + + + + cobertura + [xunit.*]*,[*Tests]* + **/test/**/*.cs, + Obsolete,GeneratedCodeAttribute + false + + + + + \ No newline at end of file diff --git a/build.cake b/build.cake index 28cacb1..0a0ccb6 100755 --- a/build.cake +++ b/build.cake @@ -82,7 +82,7 @@ Task("test-with-codecov") .Append("--collect:\"XPlat Code Coverage\""); } }; - var testProjects = GetFiles("./test/*.Tests/*.csproj"); + var testProjects = GetFiles("./test/*.Test/*.csproj"); var testProjectList = testProjects.OrderBy(p=>p.FullPath).ToList(); foreach(var testProject in testProjectList) { diff --git a/codecov.sh b/codecov.sh new file mode 100755 index 0000000..6b97c5b --- /dev/null +++ b/codecov.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +TOKEN=$1 +rm -r ./test/*.Tests/TestResults +rm -r CodeCoverage +for name in `ls ./test/*.Tests/*.csproj | awk '{print $NF}'`; +do + echo ${name} + dotnet test ${name} --logger trx --settings CodeCoverage.runsettings --collect:"XPlat Code Coverage" +done +reportgenerator /test/*/TestResults/*/coverage.cobertura.xml -reports:./test/*/TestResults/*/coverage.cobertura.xml -targetdir:./CodeCoverage -reporttypes:Cobertura -assemblyfilters:-xunit* +codecov -f ./CodeCoverage/Cobertura.xml -t ${TOKEN} \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100755 index 0000000..23be405 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +codecov: + notify: + after_n_builds: 1 \ No newline at end of file diff --git a/test/AElf.Client.Test/AElf.Client.Test.csproj b/test/AElf.Client.Test/AElf.Client.Test.csproj index f6a8729..13defc3 100644 --- a/test/AElf.Client.Test/AElf.Client.Test.csproj +++ b/test/AElf.Client.Test/AElf.Client.Test.csproj @@ -11,6 +11,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From 7ccf67d764748063b50d0b77fabbd06b967f3a7f Mon Sep 17 00:00:00 2001 From: zhxymh Date: Sat, 8 Oct 2022 17:07:49 +0800 Subject: [PATCH 5/9] test: fix url --- test/AElf.Client.Test/ClientTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/AElf.Client.Test/ClientTest.cs b/test/AElf.Client.Test/ClientTest.cs index 4127c7f..d783513 100644 --- a/test/AElf.Client.Test/ClientTest.cs +++ b/test/AElf.Client.Test/ClientTest.cs @@ -25,7 +25,7 @@ namespace AElf.Client.Test; public class ClientTest { - private const string BaseUrl = "http://192.168.196.116:8000"; + private const string BaseUrl = "http://127.0.0.1:8001"; private string _genesisAddress; private string GenesisAddress => GetGenesisContractAddress(); From 1675e8e422019b07d85842b2cc0e3d6bc6a30aa8 Mon Sep 17 00:00:00 2001 From: zhxymh Date: Sat, 8 Oct 2022 17:30:20 +0800 Subject: [PATCH 6/9] ci: test mac script --- scripts/aelf-node/start-mac.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/aelf-node/start-mac.sh b/scripts/aelf-node/start-mac.sh index e580f84..c96de98 100644 --- a/scripts/aelf-node/start-mac.sh +++ b/scripts/aelf-node/start-mac.sh @@ -8,3 +8,6 @@ cp scripts/aelf-node/keys/SD6BXDrKT2syNd1WehtPyRo3dPBiXqfGUj8UJym7YP9W9RynM.json cp scripts/aelf-node/app* aelf/ echo "start node" cd aelf && dotnet AElf.Launcher.dll >/dev/null 2>&1 & +sleep 30 +height=`curl -s http://$ip:8001/api/blockChain/blockHeight` +echo "height is $height" \ No newline at end of file From 7aeeb58720c651ff261c626ca4ca9c63adfda66f Mon Sep 17 00:00:00 2001 From: YueZh127 Date: Sat, 8 Oct 2022 19:33:16 +0800 Subject: [PATCH 7/9] ci: fix script --- scripts/aelf-node/start-mac.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/aelf-node/start-mac.sh b/scripts/aelf-node/start-mac.sh index c96de98..58586d9 100644 --- a/scripts/aelf-node/start-mac.sh +++ b/scripts/aelf-node/start-mac.sh @@ -1,13 +1,14 @@ brew install redis brew services start redis brew install unzip +brew install wget mkdir -p ~/.local/share/aelf/keys cd ../../ -wget https://github.com/AElfProject/AElf/releases/download/v1.0.0/aelf.zip && unzip aelf.zip +wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip && unzip aelf.zip cp scripts/aelf-node/keys/SD6BXDrKT2syNd1WehtPyRo3dPBiXqfGUj8UJym7YP9W9RynM.json ~/.local/share/aelf/keys/ cp scripts/aelf-node/app* aelf/ echo "start node" cd aelf && dotnet AElf.Launcher.dll >/dev/null 2>&1 & sleep 30 -height=`curl -s http://$ip:8001/api/blockChain/blockHeight` +height=`curl -s http://127.0.0.1:8001/api/blockChain/blockHeight` echo "height is $height" \ No newline at end of file From 21b4fb2b88d22fbd4b6f466f5830269bc07dde92 Mon Sep 17 00:00:00 2001 From: YueZh127 Date: Sun, 9 Oct 2022 14:15:19 +0800 Subject: [PATCH 8/9] ci:fix ci scripts --- scripts/aelf-node/start-window.ps1 | 14 +++++++------- scripts/aelf-node/start.sh | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/aelf-node/start-window.ps1 b/scripts/aelf-node/start-window.ps1 index 555949a..2b9f83e 100644 --- a/scripts/aelf-node/start-window.ps1 +++ b/scripts/aelf-node/start-window.ps1 @@ -2,14 +2,14 @@ wget https://github.com/microsoftarchive/redis/releases/download/win-3.2.100/Red Expand-Archive -Path redis.zip -DestinationPath redis ; $job1 = Start-Job -ScriptBlock { cd D:\a\1\s\redis; .\redis-server.exe; } sleep 30 -mkdir -p C:\Users\VssAdministrator\AppData\Local\aelf\keys -cp -r scripts\aelf-node\keys\* C:\Users\VssAdministrator\AppData\Local\aelf\keys; -wget https://github.com/AElfProject/AElf/releases/download/v1.0.0/aelf.zip -OutFile aelf.zip ; +mkdir -p C:\AppData\Local\aelf\keys +cp -r scripts\aelf-node\keys\* C:\AppData\Local\aelf\keys; +wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip -OutFile aelf.zip ; Expand-Archive -Path aelf.zip -DestinationPath aelf ; -cp scripts\aelf-node\appsettings.json aelf\aelf\appsettings.json ; -cp scripts\aelf-node\appsettings.MainChain.TestNet.json aelf\aelf\appsettings.MainChain.TestNet.json ; -cd aelf/aelf -$job2 = Start-Job -ScriptBlock { cd D:\a\1\s\aelf\aelf; dotnet AElf.Launcher.dll; } +cp scripts\aelf-node\appsettings.json aelf\AElf\appsettings.json ; +cp scripts\aelf-node\appsettings.MainChain.TestNet.json aelf\AElf\appsettings.MainChain.TestNet.json ; +cd aelf/AElf +$job2 = Start-Job -ScriptBlock { cd D:\a\1\s\aelf\AElf; dotnet AElf.Launcher.dll; } sleep 60 cd D:\a\1\s PowerShell.exe -file build.ps1 --target=test-with-codecov diff --git a/scripts/aelf-node/start.sh b/scripts/aelf-node/start.sh index 138b5c5..f280602 100644 --- a/scripts/aelf-node/start.sh +++ b/scripts/aelf-node/start.sh @@ -3,7 +3,7 @@ ip=`ip a | grep eth0 |grep 'inet' | awk -F/ '{print $1}'| awk '{print $2}'` sudo apt update && apt install unzip sudo mkdir -p /home/ubuntu/.ssh/aelf/keys && sudo mkdir -p /root/.ssh/aelf/keys cd ../../ -wget https://github.com/AElfProject/AElf/releases/download/v1.0.0/aelf.zip +wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip sudo unzip aelf.zip sed -i "s/127.0.0.1/$ip/g" scripts/aelf-node/appsettings.json sudo mkdir -p aelf/aelf/keys From ed956fc6935fc7de75629217e99924e48dc81b2b Mon Sep 17 00:00:00 2001 From: YueZh127 Date: Sun, 9 Oct 2022 17:23:09 +0800 Subject: [PATCH 9/9] doc: add ci badge --- README.md | 6 ++++++ scripts/aelf-node/start-mac.sh | 2 +- scripts/aelf-node/start.sh | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e3fdb08..569b64f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # AElf-Client +BRANCH | AZURE PIPELINES | TESTS | CODE COVERAGE +-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------- +MASTER | [![Build Status](https://dev.azure.com/AElfProject/aelf-sdk.cs/_apis/build/status/AElfProject.aelf-sdk.cs?branchName=master)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=master) | [![Test Status](https://img.shields.io/azure-devops/tests/AElfProject/aelf-sdk.cs/14/master)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=master) | [![codecov](https://codecov.io/gh/AElfProject/aelf-sdk.cs/branch/master/graph/badge.svg?token=mBrO9ZNFAS)](https://codecov.io/gh/AElfProject/aelf-sdk.cs) +DEV | [![Build Status](https://dev.azure.com/AElfProject/aelf-sdk.cs/_apis/build/status/AElfProject.aelf-sdk.cs?branchName=dev)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=dev) | [![Test Status](https://img.shields.io/azure-devops/tests/AElfProject/aelf-sdk.cs/14/dev)](https://dev.azure.com/AElfProject/aelf-sdk.cs/_build/latest?definitionId=14&branchName=dev) | [![codecov](https://codecov.io/gh/AElfProject/aelf-sdk.cs/branch/dev/graph/badge.svg?token=mBrO9ZNFAS)](https://codecov.io/gh/AElfProject/aelf-sdk.cs) + + ## Introduction This is a C# client library, used to communicate with the [AElf](https://github.com/AElfProject/AElf) API. diff --git a/scripts/aelf-node/start-mac.sh b/scripts/aelf-node/start-mac.sh index 58586d9..9e61a56 100644 --- a/scripts/aelf-node/start-mac.sh +++ b/scripts/aelf-node/start-mac.sh @@ -6,7 +6,7 @@ mkdir -p ~/.local/share/aelf/keys cd ../../ wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip && unzip aelf.zip cp scripts/aelf-node/keys/SD6BXDrKT2syNd1WehtPyRo3dPBiXqfGUj8UJym7YP9W9RynM.json ~/.local/share/aelf/keys/ -cp scripts/aelf-node/app* aelf/ +cp scripts/aelf-node/app* AElf/ echo "start node" cd aelf && dotnet AElf.Launcher.dll >/dev/null 2>&1 & sleep 30 diff --git a/scripts/aelf-node/start.sh b/scripts/aelf-node/start.sh index f280602..4f7062b 100644 --- a/scripts/aelf-node/start.sh +++ b/scripts/aelf-node/start.sh @@ -6,11 +6,11 @@ cd ../../ wget https://github.com/AElfProject/AElf/releases/download/v1.2.0/aelf.zip sudo unzip aelf.zip sed -i "s/127.0.0.1/$ip/g" scripts/aelf-node/appsettings.json -sudo mkdir -p aelf/aelf/keys -sudo cp scripts/aelf-node/keys/*.json aelf/aelf/keys/ -sudo cp scripts/aelf-node/app* aelf/ +sudo mkdir -p AElf/aelf/keys +sudo cp scripts/aelf-node/keys/*.json AElf/aelf/keys/ +sudo cp scripts/aelf-node/app* AElf/ echo "start node" -cd aelf && sudo dotnet AElf.Launcher.dll >/dev/null 2>&1 & +cd AElf && sudo dotnet AElf.Launcher.dll >/dev/null 2>&1 & sleep 30 height=`curl -s http://$ip:8001/api/blockChain/blockHeight` echo "height is $height"