Merge pull request #2 from lanedirt/1-add-github-actions

Add GitHub actions
This commit is contained in:
Leendert de Borst
2024-06-10 16:50:22 +02:00
committed by GitHub
5 changed files with 75 additions and 72 deletions

17
.github/release.yml vendored Normal file
View File

@@ -0,0 +1,17 @@
# .github/release.yml
changelog:
categories:
- title: 🚀 New Features
labels:
- '*'
exclude:
labels:
- dependencies
- bug
- title: 🧩 Dependencies Updates
labels:
- dependencies
- title: 🐞 Bug Fixes
labels:
- bug

View File

@@ -0,0 +1,28 @@
# 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: .NET build and run tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test src/Tests/AliasVault.UnitTests --no-build --verbosity normal

View File

@@ -0,0 +1,27 @@
# 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: Playwright integration tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build
- name: Ensure browsers are installed
run: pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net8.0/playwright.ps1 install --with-deps
- name: Run your tests
run: dotnet test src/Tests/AliasVault.E2ETests --no-build --verbosity normal

View File

@@ -43,7 +43,7 @@ public class PlaywrightTest
await _webAppManager.StartBlazorWasmAsync(appPort);
var playwright = await Playwright.CreateAsync();
Browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = false });
Browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true });
Context = await Browser.NewContextAsync();
// Intercept requests and override appsettings.json

View File

@@ -5,8 +5,6 @@ using System.Net;
public class WebAppManager
{
private Process _webApiProcess;
private List<string> _webApiErrors = new();
private Process _blazorWasmProcess;
private List<string> _blazorWasmErrors = new();
@@ -18,54 +16,6 @@ public class WebAppManager
return baseDir;
}
public async Task StartWebApiAsync(int port)
{
var projectPath = $"{GetBaseDirectory()}/../../AliasVault.Api/AliasVault.Api.csproj";
_webApiProcess = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"run --project {projectPath} --urls=http://localhost:{port}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
_webApiProcess.OutputDataReceived += (sender, args) =>
{
TestContext.Progress.WriteLine("WebAPI: " + args.Data);
if (args.Data != null && args.Data.Contains("error"))
{
_webApiErrors.Add(args.Data);
}
};
_webApiProcess.ErrorDataReceived += (sender, args) =>
{
if (args.Data != null && !string.IsNullOrEmpty(args.Data))
{
_webApiErrors.Add(args.Data);
}
};
try
{
_webApiProcess.Start();
_webApiProcess.BeginOutputReadLine();
_webApiProcess.BeginErrorReadLine();
TestContext.Progress.WriteLine("WebAPI process started, waiting for startup...");
await WaitForStartupAsync(port);
TestContext.Progress.WriteLine("WebAPI started successfully.");
}
catch (Exception ex)
{
TestContext.Progress.WriteLine($"Failed to start WebAPI: {ex.Message}");
}
}
public async Task StartBlazorWasmAsync(int port)
{
var projectPath = $"{GetBaseDirectory()}/../../AliasVault.WebApp/AliasVault.WebApp.csproj";
@@ -113,15 +63,9 @@ public class WebAppManager
}
catch (Exception e)
{
if (_webApiErrors != null && _webApiErrors.Count > 0)
if (_blazorWasmErrors.Count > 0)
{
// Concatenate all errors and fail the test
Assert.Fail($"WebAPI failed to start: {string.Join(Environment.NewLine, _webApiErrors)}");
return;
}
if (_blazorWasmErrors != null && _blazorWasmErrors.Count > 0)
{
Assert.Fail($"WASM failed to start: {string.Join(Environment.NewLine, _webApiErrors)}");
Assert.Fail($"WASM failed to start: {string.Join(Environment.NewLine, _blazorWasmErrors)}");
return;
}
@@ -131,19 +75,6 @@ public class WebAppManager
}
}
public void StopWebApi()
{
if (_webApiProcess.HasExited)
{
#if WINDOWS
KillProcessAndChildrenWindows(_webApiProcess.Id);
#else
KillProcessAndChildrenUnix(_webApiProcess.Id);
#endif
_webApiProcess.Dispose();
}
}
public void StopBlazorWasm()
{
if (!_blazorWasmProcess.HasExited)