From baae5645afadef28077e0d731b0c942eedc18063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sat, 30 Mar 2024 17:31:35 +0100 Subject: [PATCH 1/3] Add lifetime controller --- .../Controllers/LifetimeController.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Source/Testably.Server/Controllers/LifetimeController.cs diff --git a/Source/Testably.Server/Controllers/LifetimeController.cs b/Source/Testably.Server/Controllers/LifetimeController.cs new file mode 100644 index 0000000..b5ad463 --- /dev/null +++ b/Source/Testably.Server/Controllers/LifetimeController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Testably.Server.Controllers; + +[ApiController] +[Route("lifetime")] +[AllowAnonymous] +public class LifetimeController(IHostApplicationLifetime applicationLifetime) : ControllerBase +{ + [HttpPost("quit")] + public IActionResult Quit() + { + applicationLifetime.StopApplication(); + return NoContent(); + } +} \ No newline at end of file From 2ba304819beee5c07d476d23198ab40527839281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sat, 30 Mar 2024 17:34:34 +0100 Subject: [PATCH 2/3] Use lifetime/quit in build.yml --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6babb8c..db6172d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,11 @@ jobs: run: dotnet test --no-build --verbosity normal - name: Publish run: dotnet publish -c Release --output /home/runner/work/Testably.Server/Testably.Server/publish/ Source/Testably.Server/Testably.Server.csproj + - name: Shutdown webpage + shell: pwsh + run: | + Invoke-WebRequest -Uri http://testably.com/lifetime/quit -Method POST + Start-Sleep -Seconds 5 - name: Upload ftp uses: sebastianpopp/ftp-action@releases/v2 with: From 91a3b3cbcf4fc306550548264d79f4c617aaf75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Breu=C3=9F?= Date: Sat, 30 Mar 2024 17:46:51 +0100 Subject: [PATCH 3/3] Improve logging --- .../Controllers/PullRequestStatusCheckController.cs | 4 ++-- Source/Testably.Server/Program.cs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs b/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs index 9d1b1da..a55abbb 100644 --- a/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs +++ b/Source/Testably.Server/Controllers/PullRequestStatusCheckController.cs @@ -59,8 +59,6 @@ public async Task OnPullRequestChanged( return Ok("Ignore all events except 'pull_request'."); } - _logger.LogInformation("Received {PullRequestWebhookModel}", pullRequestModel); - if (pullRequestModel.Payload.Repository.Private || pullRequestModel.Payload.Repository.Owner.Login != RepositoryOwner) { @@ -78,6 +76,7 @@ public async Task OnPullRequestChanged( var repo = pullRequestModel.Payload.Repository.Name; var prNumber = pullRequestModel.Payload.Number; var requestUri = $"https://api.github.com/repos/{owner}/{repo}/pulls/{prNumber}"; + _logger.LogInformation("Try reading '{RequestUri}'", requestUri); var response = await client .GetAsync(requestUri, cancellationToken); @@ -108,6 +107,7 @@ await response.Content.ReadAsStreamAsync(cancellationToken), } var title = titleProperty.GetString()!; + _logger.LogInformation("Validate title for PR #{PullRequest}: '{Title}'", prNumber, title); var commitSha = shaProperty.GetString(); var statusUri = $"https://api.github.com/repos/{owner}/{repo}/statuses/{commitSha}"; var hasValidTitle = ValidateTitle(title); diff --git a/Source/Testably.Server/Program.cs b/Source/Testably.Server/Program.cs index 59d3440..ba9d5d5 100644 --- a/Source/Testably.Server/Program.cs +++ b/Source/Testably.Server/Program.cs @@ -14,14 +14,18 @@ public static void Main(string[] args) var builder = WebApplication.CreateBuilder(args); + // Add services to the container. +#if DEBUG + builder.Services.AddHttpClient("Proxied"); +#else // https://www.ionos.de/hilfe/index.php?id=4426 var webProxy = new WebProxy("http://winproxy.server.lan:3128"); - // Add services to the container. builder.Services.AddHttpClient("Proxied") .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler() { Proxy = webProxy }); +#endif builder.Services.AddRazorPages(); builder.Services.AddControllers() .AddJsonOptions(o