diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..aea33e5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,58 @@ +name: Build + +on: + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, synchronize, reopened] + release: + types: [created] + +env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + +jobs: + build: + runs-on: windows-latest + steps: + - name: Set up JDK 17 + uses: actions/setup-java@v5 + with: + java-version: 17 + distribution: 'zulu' # Alternative distribution options are available. + - name: Setup dotnet + uses: actions/setup-dotnet@v5.2.0 + with: + dotnet-version: 8.0.x + - name: Checkout code + uses: actions/checkout@v5 + - name: Cache SonarQube Cloud packages + uses: actions/cache@v5 + with: + path: ~\sonar\cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache SonarQube Cloud scanner + id: cache-sonar-scanner + uses: actions/cache@v5 + with: + path: ${{ runner.temp }}\scanner + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner + - name: Install SonarQube Cloud scanner + if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' + shell: powershell + run: | + New-Item -Path ${{ runner.temp }}\scanner -ItemType Directory + dotnet tool update dotnet-sonarscanner --tool-path ${{ runner.temp }}\scanner + - name: SonarQube Cloud scanner begin + if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && env.SONAR_TOKEN != '') }} + run: ${{ runner.temp }}\scanner\dotnet-sonarscanner begin /k:"KxSystems_csharpkdb" /o:"kxsystems" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.cs.vstest.reportsPaths="**\TestResults\*.trx" /d:sonar.cs.opencover.reportsPaths="*\coverage.opencover.xml" /d:sonar.verbose=false + - name: Build + run : dotnet build /p:Configuration=Release .\CSharpKdb.sln + - name: Test + run: dotnet test /p:Configuration=Release --no-build .\kx.Test\kx.Test.csproj --logger:trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover + - name: SonarQube Cloud scanner finish + if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && env.SONAR_TOKEN != '') }} + run: ${{ runner.temp }}\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 471ccf4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: csharp -mono: none -dotnet: 3.1 -solution: ./CSharpKdb.sln - -addons: - sonarcloud: - organization: "kxsystems" - -before_install: -- bash ./tools/travis-ci-install-sonar.sh - -script: - - bash ./tools/travis-ci-build.sh diff --git a/Demos/FeedDemo/FeedDemo.csproj b/Demos/FeedDemo/FeedDemo.csproj index c9f7094..691f166 100644 --- a/Demos/FeedDemo/FeedDemo.csproj +++ b/Demos/FeedDemo/FeedDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net8.0 diff --git a/Demos/QueryResponseDemo/QueryResponseDemo.csproj b/Demos/QueryResponseDemo/QueryResponseDemo.csproj index c1388b1..158e112 100644 --- a/Demos/QueryResponseDemo/QueryResponseDemo.csproj +++ b/Demos/QueryResponseDemo/QueryResponseDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net8.0 diff --git a/Demos/SerializationDemo/SerializationDemo.csproj b/Demos/SerializationDemo/SerializationDemo.csproj index c1388b1..158e112 100644 --- a/Demos/SerializationDemo/SerializationDemo.csproj +++ b/Demos/SerializationDemo/SerializationDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net8.0 diff --git a/Demos/SubscriberDemo/SubscriberDemo.csproj b/Demos/SubscriberDemo/SubscriberDemo.csproj index c1388b1..158e112 100644 --- a/Demos/SubscriberDemo/SubscriberDemo.csproj +++ b/Demos/SubscriberDemo/SubscriberDemo.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net8.0 diff --git a/kx.Benchmark.Test/kx.Benchmark.Test.csproj b/kx.Benchmark.Test/kx.Benchmark.Test.csproj index 8a8c45d..002a4b2 100644 --- a/kx.Benchmark.Test/kx.Benchmark.Test.csproj +++ b/kx.Benchmark.Test/kx.Benchmark.Test.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net8.0 kx.Benchmark.Test.Program true kx.Benchmark.Test.snk diff --git a/kx.Test/TestUtils/TestSerialisationHelper.cs b/kx.Test/TestUtils/TestSerialisationHelper.cs index 0d3f039..3271b91 100644 --- a/kx.Test/TestUtils/TestSerialisationHelper.cs +++ b/kx.Test/TestUtils/TestSerialisationHelper.cs @@ -1,42 +1,39 @@ -using System; +using MessagePack; +using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace kx.Test.TestUtils { + /// + /// A helper class for testing serialisation and de-serialisation logic + /// in unit-tests + /// + internal static class TestSerialisationHelper + { /// - /// A helper class for testing serialisation and de-serialisation logic - /// in unit-tests + /// Performs binary serialisation and de-serialisation on a specified exception. /// - internal static class TestSerialisationHelper + /// The type of exception being tested. + /// The exception to be serialised and de-serialised. + /// + /// A de-serialised instance of the exception passed. All serialisable members should match the original. + /// + /// + /// This is primarily intended to confirm custom exceptions within the DeltaApiCore + /// library comply to ISerialization pattern. + /// + /// See https://stackoverflow.com/questions/94488/what-is-the-correct-way-to-make-a-custom-net-exception-serializable + /// + public static T SerialiseAndDeserialiseException(T exception) + where T : Exception { - /// - /// Performs binary serialisation and de-serialisation on a specified exception. - /// - /// The type of exception being tested. - /// The exception to be serialised and de-serialised. - /// - /// A de-serialised instance of the exception passed. All serialisable members should match the original. - /// - /// - /// This is primarily intended to confirm custom exceptions within the DeltaApiCore - /// library comply to ISerialization pattern. - /// - /// See https://stackoverflow.com/questions/94488/what-is-the-correct-way-to-make-a-custom-net-exception-serializable - /// - public static T SerialiseAndDeserialiseException(T exception) - where T : Exception - { - BinaryFormatter binaryFormatter = new BinaryFormatter(); - - using (var stream = new MemoryStream()) - { - binaryFormatter.Serialize(stream, exception); - - stream.Seek(0, 0); - - return (T)binaryFormatter.Deserialize(stream); - } - } + using (var stream = new MemoryStream()) + { + MessagePackSerializer.Serialize(stream, exception, MessagePack.Resolvers.ContractlessStandardResolver.Options); + stream.Seek(0, 0); + return (T)MessagePackSerializer.Deserialize(stream, MessagePack.Resolvers.ContractlessStandardResolver.Options); + } } + } } diff --git a/kx.Test/kx.Test.csproj b/kx.Test/kx.Test.csproj index b42f6ab..fd34070 100644 --- a/kx.Test/kx.Test.csproj +++ b/kx.Test/kx.Test.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net8.0 false @@ -25,6 +25,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/kx/kx.csproj b/kx/kx.csproj index 97ed3ab..9cb549d 100644 --- a/kx/kx.csproj +++ b/kx/kx.csproj @@ -1,7 +1,7 @@ - netstandard2.1 + netstandard2.1;net8.0 CSharpKDB CSharpKDB Provides functionality for .NET applications to interface with a KDB+ process. diff --git a/tools/travis-ci-build.sh b/tools/travis-ci-build.sh deleted file mode 100644 index 781b287..0000000 --- a/tools/travis-ci-build.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -# Only Run SonarScanner if it is not a pull_request -if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then - echo "Executing MSBuild DLL begin command..." - dotnet ./tools/sonar/SonarScanner.MSBuild.dll begin /o:"kxsystems" /k:"KxSystems_csharpkdb" /d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" /d:sonar.cs.opencover.reportsPaths="*/coverage.opencover.xml" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.verbose=false /d:sonar.login=${SONAR_TOKEN} -fi - -# Run Release build -echo "Running build..." -dotnet build /p:Configuration=Release ./CSharpKdb.sln - -# Run Tests, Coverlet to record result and code-coverage -echo "Running tests..." -dotnet test /p:Configuration=Release --no-build ./kx.Test/kx.Test.csproj --logger:trx /p:CollectCoverage=true /p:CoverletOutputFormat=opencover - -if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then - echo "Executing MSBuild DLL end command..." - dotnet ./tools/sonar/SonarScanner.MSBuild.dll end /d:sonar.login=${SONAR_TOKEN} -fi \ No newline at end of file diff --git a/tools/travis-ci-install-sonar.sh b/tools/travis-ci-install-sonar.sh deleted file mode 100644 index 4ad4cec..0000000 --- a/tools/travis-ci-install-sonar.sh +++ /dev/null @@ -1,25 +0,0 @@ - -#!/bin/sh -if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then - java -version - echo "Sonar requires updated Java for Ubuntu 16.04.7, updating repos" - sudo apt-get update - sudo apt-get install -y software-properties-common - sudo add-apt-repository -y ppa:linuxuprising/java - sudo apt-get update - echo "Set properties to agree to Java17 license prompts" - echo oracle-java17-installer shared/accepted-oracle-license-v1-3 select true | sudo /usr/bin/debconf-set-selections - echo "Install Java17" - sudo apt install -y oracle-java17-installer --install-recommends - sudo apt install oracle-java17-set-default - java -version -fi -echo "Starting sonar install..." -wget -O sonar.zip https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.0.4.24009/sonar-scanner-msbuild-5.0.4.24009-netcoreapp3.0.zip -echo "Unzipping..." -unzip -qq sonar.zip -d tools/sonar -echo "Displaying file structure..." -find . -ls -l tools/sonar -echo "Changing permissions..." -chmod +x tools/sonar/sonar-scanner-4.4.0.2170/bin/sonar-scanner