Skip to content

Commit

Permalink
Add linux PR gate (#265)
Browse files Browse the repository at this point in the history
* Add linux PR gate

* minor yml change

* Pipeline test

* Merge

* test

* Test

* test

* test
  • Loading branch information
yangpanMS authored Feb 13, 2024
1 parent b863159 commit ecbc336
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 35 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/pull-request-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Pull Request (Linux)

on:
# push:
# branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
name: PR build + test (Linux)
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'csharp' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x

- name: Add permission to run shell
run: chmod -R +x *.sh

- name: Restore dependencies
run: ./build-restore.sh

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Build
run: ./build.sh

- name: Test
run: ./build-test.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
48 changes: 48 additions & 0 deletions build-restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

if [ "${1,,}" == "/?" ] || [ "${1,,}" == "-?" ] || [ "${1,,}" == "--help" ]; then
Usage
fi

ExitCode=0

echo ""
echo "[Restoring NuGet Packages]"
echo "--------------------------------------------------"
dotnet restore "$(dirname "$0")/src/VirtualClient/VirtualClient.sln" "$1"
result=$?
if [ $result -ne 0 ]; then
Error
fi

End

Usage() {
echo ""
echo "Usage:"
echo "---------------------"
echo "$0 [--interactive]"
echo ""
echo "Examples:"
echo "---------------------"
echo "# Restore NuGet packages for all projects"
echo "$0"
echo ""
echo "# Restore, allowing user to provide credentials"
echo "$0 --interactive"
Finish
}

Error() {
ExitCode=$?
End
}

End() {
echo "Restore Stage Exit Code: $ExitCode"
Finish
}

Finish() {
exit $ExitCode
}
43 changes: 43 additions & 0 deletions build-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

ExitCode=0

Usage() {
echo ""
echo "Usage:"
echo "---------------------"
echo "$0"
Finish
}

Error() {
ExitCode=1
End
}

End() {
echo "Test Stage Exit Code: $ExitCode"
Finish
}

Finish() {
exit $ExitCode
}

if [ "${1,,}" == "/?" ] || [ "${1,,}" == "-?" ] || [ "${1,,}" == "--help" ]; then
Usage
fi

echo ""
echo "[Running Tests]"
echo "--------------------------------------------------"

for file in $(find "$(dirname "$0")/src" -type f -name "*Tests.csproj"); do
dotnet test -c Release "$file" --no-restore --no-build --filter "(Category=Unit|Category=Functional)" --logger "console;verbosity=normal"
result=$?
if [ $result -ne 0 ]; then
Error
fi
done

End
12 changes: 6 additions & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ else
fi

echo "Building VirtualClient solution."
dotnet build src/VirtualClient/VirtualClient.sln -c Debug
dotnet build src/VirtualClient/VirtualClient.sln -c Release

if [ "$BUILD_ALL" = true ]; then
echo "Publishing VirtualClient for all platforms."
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r linux-x64 -c Debug $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r linux-arm64 -c Debug $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r win-x64 -c Debug $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r win-arm64 -c Debug $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r linux-x64 -c Release $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r linux-arm64 -c Release $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r win-x64 -c Release $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r win-arm64 -c Release $PUBLISH_FLAGS
else
echo "Publishing VirtualClient for architecture: $ARCH"
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r $ARCH -c Debug $PUBLISH_FLAGS
dotnet publish src/VirtualClient/VirtualClient.Main/VirtualClient.Main.csproj -r $ARCH -c Release $PUBLISH_FLAGS
fi
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void SetupDefaultMockBehavior(PlatformID platform = PlatformID.Win32NT,
this.expectedExecutableDir = this.mockFixture.ToPlatformSpecificPath(this.mockBlenderPackage, this.mockFixture.Platform, this.mockFixture.CpuArchitecture).Path;
this.expectedExecutablePath = this.mockFixture.PlatformSpecifics.Combine(expectedExecutableDir, "benchmark-launcher-cli.exe");

this.results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "BlenderBenchmark", "MonsterCPU.json"));
this.results = File.ReadAllText(MockFixture.GetDirectory(typeof(BlenderBenchmarkExecutorTests), "Examples", "BlenderBenchmark", "MonsterCPU.json"));
this.mockFixture.Process.StandardOutput = new Common.ConcurrentBuffer(new StringBuilder(this.results));

// Set up the process's standard output to be the mock blender metrics result as the parser reads the results from the std out.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void SetupDefaults(PlatformID platform = PlatformID.Win32NT, Architecture
this.mockFixture.Directory.Setup(f => f.Exists(It.IsAny<string>()))
.Returns(true);

this.mockResults = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"CtsTraffic", "CtsTrafficResultsExample.csv"));
this.mockResults = File.ReadAllText(MockFixture.GetDirectory(typeof(CtsTrafficClientExecutorTests), "Examples", @"CtsTraffic", "CtsTrafficResultsExample.csv"));

this.mockFixture.File.Setup(f => f.ReadAllTextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(this.mockResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void SetupDefaults(PlatformID platform = PlatformID.Win32NT, Architecture
this.mockFixture.File.Setup(f => f.Exists(It.IsAny<string>())).Returns(true);
this.mockFixture.Directory.Setup(d => d.Exists(It.IsAny<string>())).Returns(true);

this.mockResults = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"CtsTraffic", "CtsTrafficResultsExample.csv"));
this.mockResults = File.ReadAllText(MockFixture.GetDirectory(typeof(CtsTrafficServerExecutorTests), "Examples", @"CtsTraffic", "CtsTrafficResultsExample.csv"));

this.mockFixture.File.Setup(f => f.ReadAllTextAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(this.mockResults);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public void SetupDefaults(PlatformID platform = PlatformID.Win32NT, Architecture
this.mockFixture.Directory.Setup(f => f.Exists(It.IsAny<string>()))
.Returns(true);

this.mockResults = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"PostgreSQL", "PostgresqlresultsExample.txt"));
this.tclFileContents = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "PostgreSQL", "runTransactions.tcl"));
this.mockResults = File.ReadAllText(MockFixture.GetDirectory(typeof(PostgreSQLClientExecutorTests), "Examples", @"PostgreSQL", "PostgresqlresultsExample.txt"));
this.tclFileContents = File.ReadAllText(MockFixture.GetDirectory(typeof(PostgreSQLClientExecutorTests), "Examples", "PostgreSQL", "runTransactions.tcl"));

this.mockFixture.ProcessManager.OnProcessCreated = (process) =>
{
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task PostgreSQLClientExecutorInitializesTheRequiredConfigurationFil
this.SetupDefaults(PlatformID.Unix);

// Example contents of the runTransactions.tcl file.
string tclFileContent = await File.ReadAllTextAsync(Path.Combine(MockFixture.ExamplesDirectory, "PostgreSQL", "runTransactions.tcl"));
string tclFileContent = await File.ReadAllTextAsync(MockFixture.GetDirectory(typeof(PostgreSQLClientExecutorTests), "Examples", "PostgreSQL", "runTransactions.tcl"));

// Reading the contexts of the runTransactions.tcl file
this.mockFixture.File.Setup(file => file.ReadAllTextAsync(It.Is<string>(path => path.EndsWith("/linux-x64/runTransactions.tcl")), It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -185,7 +185,7 @@ public async Task PostgreSQLClientExecutorInitializesTheRequiredConfigurationFil
this.SetupDefaults(PlatformID.Win32NT);

// Example contents of the runTransactions.tcl file.
string tclFileContent = await File.ReadAllTextAsync(Path.Combine(MockFixture.ExamplesDirectory, "PostgreSQL", "runTransactions.tcl"));
string tclFileContent = await File.ReadAllTextAsync(MockFixture.GetDirectory(typeof(PostgreSQLClientExecutorTests), "Examples", "PostgreSQL", "runTransactions.tcl"));

// Reading the contexts of the runTransactions.tcl file
this.mockFixture.File.Setup(file => file.ReadAllTextAsync(It.Is<string>(path => path.EndsWith("\\win-x64\\runTransactions.tcl")), It.IsAny<CancellationToken>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class RedisBenchmarkMetricsParserTests
[Test]
public void RedisBenchmarkMetricsParserParsesTheExpectedMetricsFromResultsCorrectly_1()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"Redis\RedisBenchmarkResults.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(RedisBenchmarkMetricsParserTests), "Examples", @"Redis\RedisBenchmarkResults.txt"));
var parser = new RedisBenchmarkMetricsParser(results);

IList<Metric> metrics = parser.Parse();
Expand Down Expand Up @@ -187,7 +187,7 @@ public void RedisBenchmarkMetricsParserParsesTheExpectedMetricsFromResultsCorrec
[Test]
public void RedisBenchmarkMetricsParserParsesTheExpectedMetricsFromResultsCorrectly_2()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"Redis\RedisBenchmarkResults_2.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(RedisBenchmarkMetricsParserTests), "Examples", @"Redis\RedisBenchmarkResults_2.txt"));
var parser = new RedisBenchmarkMetricsParser(results);

IList<Metric> metrics = parser.Parse();
Expand All @@ -213,7 +213,7 @@ public void RedisBenchmarkMetricsParserParsesTheExpectedMetricsFromResultsCorrec
[Test]
public void RedisBenchmarkMetricsParserAssociatesTheCorrectRelativityToTheMetrics()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"Redis\RedisBenchmarkResults.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(RedisBenchmarkMetricsParserTests), "Examples", @"Redis\RedisBenchmarkResults.txt"));
var parser = new RedisBenchmarkMetricsParser(results);

IList<Metric> metrics = parser.Parse();
Expand All @@ -230,7 +230,7 @@ public void RedisBenchmarkMetricsParserAssociatesTheCorrectRelativityToTheMetric
[Test]
public void RedisBenchmarkMetricsParserThrowIfInvalidOutputFormat_1()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"Redis\RedisBenchmarkResults.txt")).Substring(0, 100); // invalid results
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(RedisBenchmarkMetricsParserTests), "Examples", @"Redis\RedisBenchmarkResults.txt")).Substring(0, 100); // invalid results
var parser = new RedisBenchmarkMetricsParser(results);

WorkloadResultsException exception = Assert.Throws<WorkloadResultsException>(() => parser.Parse());
Expand All @@ -240,7 +240,7 @@ public void RedisBenchmarkMetricsParserThrowIfInvalidOutputFormat_1()
[Test]
public void RedisBenchmarkMetricsParserThrowIfInvalidOutputFormat_2()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, @"Redis\RedisBenchmarkResults.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(RedisBenchmarkMetricsParserTests), "Examples", @"Redis\RedisBenchmarkResults.txt"));
var parser = new RedisBenchmarkMetricsParser(string.Join(Environment.NewLine, results.Split(Environment.NewLine).Take(1))); // headers exist but no measurements within.

WorkloadResultsException exception = Assert.Throws<WorkloadResultsException>(() => parser.Parse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void SetupDefaultMockBehavior(PlatformID platform = PlatformID.Win32NT,
this.mockSpecViewExePath = this.mockFixture.Combine(this.mockSpecViewExeDir, "RunViewperf.exe");
this.mockPstoolsExePath = this.mockFixture.Combine(this.mockPstoolsExeDir, "PsExec.exe");

string mockResultPath = Path.Combine(MockFixture.ExamplesDirectory, "SPECview", "3dsmaxResultCSV.csv");
string mockResultPath = MockFixture.GetDirectory(typeof(SpecViewExecutorTests), "Examples", "SPECview", "3dsmaxResultCSV.csv");
this.results = File.ReadAllText(mockResultPath);
this.mockFixture.FileSystem.Setup(rt => rt.Directory.GetDirectories(this.mockSpecViewExeDir, "results_*", SearchOption.TopDirectoryOnly)).Returns(new string[] { mockResultPath });
this.mockFixture.FileSystem.Setup(rt => rt.File.ReadAllText(It.IsAny<string>())).Returns(this.results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void DiskFiltersHandlesAnomaliesEncounters_1()
// Scenario:
// We found an anomaly on one of the Linux systems that had 32 disks where they were not
// identified properly.
string rawText = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "lshw", "lshw_disk_storage_results_anomaly.xml"));
string rawText = File.ReadAllText(MockFixture.GetDirectory(typeof(DiskFiltersTests), "Examples", "lshw", "lshw_disk_storage_results_anomaly.xml"));
LshwDiskParser parser = new LshwDiskParser(rawText);

IEnumerable<Disk> disks = parser.Parse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class CoreInfoParserTests
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromIntelSystems_Scenario1()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_Intel.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_Intel.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand Down Expand Up @@ -45,7 +45,7 @@ public void CoreInfoParserParsesTheExpectedResultsFromIntelSystems_Scenario1()
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromIntelSystems_Scenario2()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_Intel_2.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_Intel_2.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand Down Expand Up @@ -73,7 +73,7 @@ public void CoreInfoParserParsesTheExpectedResultsFromIntelSystems_Scenario2()
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromIntelSystems_Scenario3()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_Intel_3.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_Intel_3.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand Down Expand Up @@ -101,7 +101,7 @@ public void CoreInfoParserParsesTheExpectedResultsFromIntelSystems_Scenario3()
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromAMDSystems_Scenario1()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_AMD.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_AMD.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand Down Expand Up @@ -129,7 +129,7 @@ public void CoreInfoParserParsesTheExpectedResultsFromAMDSystems_Scenario1()
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromAMDSystems_Scenario2()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_AMD_Milan.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_AMD_Milan.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand Down Expand Up @@ -157,7 +157,7 @@ public void CoreInfoParserParsesTheExpectedResultsFromAMDSystems_Scenario2()
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromAmpereSystems_Scenario1()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_Ampere.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_Ampere.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand All @@ -184,7 +184,7 @@ public void CoreInfoParserParsesTheExpectedResultsFromAmpereSystems_Scenario1()
[Test]
public void CoreInfoParserParsesTheExpectedResultsFromAmpereSystems_Scenario2()
{
string results = File.ReadAllText(Path.Combine(MockFixture.ExamplesDirectory, "CoreInfo", "CoreInfo_Results_Ampere_2.txt"));
string results = File.ReadAllText(MockFixture.GetDirectory(typeof(CoreInfoParserTests), "Examples", "CoreInfo", "CoreInfo_Results_Ampere_2.txt"));
CoreInfoParser parser = new CoreInfoParser(results);
CpuInfo info = parser.Parse();

Expand Down
Loading

0 comments on commit ecbc336

Please sign in to comment.