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

[WIP] Add CI #32

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions CodeCoverage.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
<Exclude>[xunit.*]*,[*Tests]*</Exclude> <!-- [Assembly-Filter]Type-Filter -->
<ExcludeByFile>**/test/**/*.cs,</ExcludeByFile>
<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute</ExcludeByAttribute>
<SingleHit>false</SingleHit>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
30 changes: 23 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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'
38 changes: 36 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#tool nuget:?package=Codecov
#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/";
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")
Expand Down Expand Up @@ -36,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")
Expand All @@ -62,6 +66,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/*.Test/*.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");
Expand Down
2 changes: 1 addition & 1 deletion build.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
CAKE_VERSION=0.37.0
DOTNET_VERSION=3.1.101
DOTNET_VERSION=6.0.300
12 changes: 12 additions & 0 deletions codecov.sh
Original file line number Diff line number Diff line change
@@ -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}
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
codecov:
notify:
after_n_builds: 1
8 changes: 6 additions & 2 deletions scripts/aelf-node/start-mac.sh
Original file line number Diff line number Diff line change
@@ -1,10 +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/
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://127.0.0.1:8001/api/blockChain/blockHeight`
echo "height is $height"
16 changes: 8 additions & 8 deletions scripts/aelf-node/start-window.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
PowerShell.exe -file build.ps1 --target=test-with-codecov
10 changes: 5 additions & 5 deletions scripts/aelf-node/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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
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"
4 changes: 4 additions & 0 deletions test/AElf.Client.Test/AElf.Client.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/AElf.Client.Test/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down