From d1006a357b55f8099d382231423aef9423e71827 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:05:44 +0100 Subject: [PATCH 01/13] fix: prevent add_message metric duplicate --- .../Middlewares/CatchAllMiddleware.cs | 76 +++--- .../Repositories/FollowerRepository.cs | 138 +++++------ .../Repositories/MessageRepository.cs | 228 +++++++++--------- csharp-minitwit/Utils/SanitizeMetricsPath.cs | 47 ++-- 4 files changed, 241 insertions(+), 248 deletions(-) diff --git a/csharp-minitwit/Middlewares/CatchAllMiddleware.cs b/csharp-minitwit/Middlewares/CatchAllMiddleware.cs index 7528e05..7a838f5 100644 --- a/csharp-minitwit/Middlewares/CatchAllMiddleware.cs +++ b/csharp-minitwit/Middlewares/CatchAllMiddleware.cs @@ -1,38 +1,38 @@ -using System.Diagnostics; -using Microsoft.AspNetCore.Http; -using System.Threading.Tasks; -using csharp_minitwit.Utils; -// Assuming ApplicationMetrics is in the same namespace, or add the appropriate using statement - -namespace csharp_minitwit.Middlewares -{ - public class CatchAllMiddleware - { - private readonly RequestDelegate _next; - - public CatchAllMiddleware(RequestDelegate next) - { - _next = next; - } - - public async Task InvokeAsync(HttpContext context) - { - var watch = Stopwatch.StartNew(); - - // Used to monitor total requests received grouped by endpoint - ApplicationMetrics.HttpRequestTotal.WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)).Inc(); - - await _next(context); - - watch.Stop(); - - // Used to monitor response delay grouped by endpoint - ApplicationMetrics.HttpRequestDuration - .WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)) - .Observe(watch.Elapsed.TotalSeconds); - - // Used to monitor response status codes grouped by endpoint - ApplicationMetrics.HttpResponseStatusCodeTotal.WithLabels(context.Response.StatusCode.ToString()).Inc(); - } - } -} +using System.Diagnostics; +using Microsoft.AspNetCore.Http; +using System.Threading.Tasks; +using csharp_minitwit.Utils; +// Assuming ApplicationMetrics is in the same namespace, or add the appropriate using statement + +namespace csharp_minitwit.Middlewares +{ + public class CatchAllMiddleware + { + private readonly RequestDelegate _next; + + public CatchAllMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + var watch = Stopwatch.StartNew(); + + // Used to monitor total requests received grouped by endpoint + ApplicationMetrics.HttpRequestTotal.WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)).Inc(); + + await _next(context); + + watch.Stop(); + + // Used to monitor response delay grouped by endpoint + ApplicationMetrics.HttpRequestDuration + .WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)) + .Observe(watch.Elapsed.TotalSeconds); + + // Used to monitor response status codes grouped by endpoint + ApplicationMetrics.HttpResponseStatusCodeTotal.WithLabels(context.Response.StatusCode.ToString()).Inc(); + } + } +} diff --git a/csharp-minitwit/Services/Repositories/FollowerRepository.cs b/csharp-minitwit/Services/Repositories/FollowerRepository.cs index 29fb970..bf1513d 100644 --- a/csharp-minitwit/Services/Repositories/FollowerRepository.cs +++ b/csharp-minitwit/Services/Repositories/FollowerRepository.cs @@ -1,69 +1,71 @@ -using System.Diagnostics; - -using csharp_minitwit.Services.Interfaces; -using csharp_minitwit.Utils; - -using Microsoft.EntityFrameworkCore; - -namespace csharp_minitwit.Services.Repositories -{ - public class FollowerRepository(MinitwitContext dbContext) : IFollowerRepository - { - public async Task Follow(int whoId, int whomId) - { - var watch = Stopwatch.StartNew(); - - await dbContext.Followers.AddAsync(new Follower - { - WhoId = whoId, - WhomId = whomId - }); - - watch.Stop(); - ApplicationMetrics.HttpRequestDuration - .WithLabels(MetricsHelpers.SanitizePath("/follow")) - .Observe(watch.Elapsed.TotalSeconds); - - return await dbContext.SaveChangesAsync() > 0; - } - - public async Task Unfollow(int whoId, int whomId) - { - var watch = Stopwatch.StartNew(); - var follower = await dbContext.Followers - .FirstOrDefaultAsync(f => f.WhoId == whoId && f.WhomId == whomId); - - if (follower != null) - { - dbContext.Followers.Remove(follower); - await dbContext.SaveChangesAsync(); - - watch.Stop(); - ApplicationMetrics.HttpRequestDuration - .WithLabels(MetricsHelpers.SanitizePath("unfollow")) - .Observe(watch.Elapsed.TotalSeconds); - - return true; - } - else - { - return false; - } - } - - public async Task IsFollowing(int whoId, int whomId) - { - return await dbContext.Followers - .AnyAsync(f => f.WhoId == whoId && f.WhomId == whomId); - } - - public async Task> GetFollowingNames(int n, int whoId) - { - return await dbContext.Followers - .Where(f => f.WhoId == whoId) - .Take(n) - .Select(f => f.Whom.Username) - .ToListAsync(); - } - } +using System.Diagnostics; + +using csharp_minitwit.Services.Interfaces; +using csharp_minitwit.Utils; + +using Microsoft.EntityFrameworkCore; + +namespace csharp_minitwit.Services.Repositories +{ + public class FollowerRepository(MinitwitContext dbContext) : IFollowerRepository + { + public async Task Follow(int whoId, int whomId) + { + var watch = Stopwatch.StartNew(); + + await dbContext.Followers.AddAsync(new Follower + { + WhoId = whoId, + WhomId = whomId + }); + + watch.Stop(); + Console.WriteLine("/follow"); + ApplicationMetrics.HttpRequestDuration + .WithLabels(MetricsHelpers.SanitizePath("/follow")) + .Observe(watch.Elapsed.TotalSeconds); + + return await dbContext.SaveChangesAsync() > 0; + } + + public async Task Unfollow(int whoId, int whomId) + { + var watch = Stopwatch.StartNew(); + var follower = await dbContext.Followers + .FirstOrDefaultAsync(f => f.WhoId == whoId && f.WhomId == whomId); + + if (follower != null) + { + dbContext.Followers.Remove(follower); + await dbContext.SaveChangesAsync(); + + watch.Stop(); + Console.WriteLine("/unfollow"); + ApplicationMetrics.HttpRequestDuration + .WithLabels(MetricsHelpers.SanitizePath("unfollow")) + .Observe(watch.Elapsed.TotalSeconds); + + return true; + } + else + { + return false; + } + } + + public async Task IsFollowing(int whoId, int whomId) + { + return await dbContext.Followers + .AnyAsync(f => f.WhoId == whoId && f.WhomId == whomId); + } + + public async Task> GetFollowingNames(int n, int whoId) + { + return await dbContext.Followers + .Where(f => f.WhoId == whoId) + .Take(n) + .Select(f => f.Whom.Username) + .ToListAsync(); + } + } } \ No newline at end of file diff --git a/csharp-minitwit/Services/Repositories/MessageRepository.cs b/csharp-minitwit/Services/Repositories/MessageRepository.cs index 39f835f..402b82b 100644 --- a/csharp-minitwit/Services/Repositories/MessageRepository.cs +++ b/csharp-minitwit/Services/Repositories/MessageRepository.cs @@ -1,118 +1,112 @@ -using System.Diagnostics; - -using csharp_minitwit.Models; -using csharp_minitwit.Models.ViewModels; -using csharp_minitwit.Services.Interfaces; -using csharp_minitwit.Utils; - -using Microsoft.EntityFrameworkCore; - -namespace csharp_minitwit.Services.Repositories -{ - public class MessageRepository(MinitwitContext dbContext) : IMessageRepository - { - public Task AddMessageAsync(string text, int authorId) - { - var watch = Stopwatch.StartNew(); - var message = new Message - { - Text = text, - AuthorId = authorId, - PubDate = (int)DateTimeOffset.Now.ToUnixTimeSeconds(), - }; - - dbContext.Messages.Add(message); - - watch.Stop(); - ApplicationMetrics.HttpRequestDuration - .WithLabels(MetricsHelpers.SanitizePath("add_message")) - .Observe(watch.Elapsed.TotalSeconds); - - return dbContext.SaveChangesAsync(); - } - - public async Task> GetMessagesWithAuthorAsync(int n) - { - return await dbContext.Messages - .Where(m => m.Flagged == 0) - .Join(dbContext.Users, - message => message.AuthorId, - user => user.UserId, - (message, user) => new MessageWithAuthorModel - { - Message = message, - Author = user, - }) - .OrderByDescending(ma => ma.Message.PubDate) - .Take(n) - .ToListAsync(); - } - - public async Task> GetMessagesByAuthorAsync(int n, int authorId) - { - return await dbContext.Messages - .Where(m => m.Flagged == 0 && m.AuthorId == authorId) - .Join(dbContext.Users, - message => message.AuthorId, - user => user.UserId, - (message, user) => new MessageWithAuthorModel - { - Message = message, - Author = user, - }) - .OrderByDescending(ma => ma.Message.PubDate) - .Take(n) - .ToListAsync(); - } - - public async Task> GetFollowedMessages(int n, int userId) - { - return await dbContext.Messages - .Where(m => m.Flagged == 0) - .Join(dbContext.Users, - message => message.AuthorId, - user => user.UserId, - (message, user) => new MessageWithAuthorModel - { - Message = message, - Author = user, - }) - .Where(ma => - ma.Author.UserId == userId - || dbContext.Followers.Any(f => f.WhoId == userId && f.WhomId == ma.Author.UserId)) - .OrderByDescending(ma => ma.Message.PubDate) - .Take(n) - .ToListAsync(); - } - - public async Task> GetApiMessagesAsync(int n) - { - return await dbContext.Messages - .Where(m => m.Flagged == 0) - .OrderByDescending(m => m.PubDate) - .Take(n) - .Select(m => new APIMessageModel - { - content = m.Text, - pub_date = m.PubDate, - user = m.Author.Username - }) - .ToListAsync(); - } - - public async Task> GetApiMessagesByAuthorAsync(int n, int authorId) - { - return await dbContext.Messages - .Where(m => m.AuthorId == authorId && m.Flagged == 0) - .OrderByDescending(m => m.PubDate) - .Take(n) - .Select(m => new APIMessageModel - { - content = m.Text, - pub_date = m.PubDate, - user = m.Author.Username - }) - .ToListAsync(); - } - } +using System.Diagnostics; + +using csharp_minitwit.Models; +using csharp_minitwit.Models.ViewModels; +using csharp_minitwit.Services.Interfaces; +using csharp_minitwit.Utils; + +using Microsoft.EntityFrameworkCore; + +namespace csharp_minitwit.Services.Repositories +{ + public class MessageRepository(MinitwitContext dbContext) : IMessageRepository + { + public Task AddMessageAsync(string text, int authorId) + { + var message = new Message + { + Text = text, + AuthorId = authorId, + PubDate = (int)DateTimeOffset.Now.ToUnixTimeSeconds(), + }; + + dbContext.Messages.Add(message); + + return dbContext.SaveChangesAsync(); + } + + public async Task> GetMessagesWithAuthorAsync(int n) + { + return await dbContext.Messages + .Where(m => m.Flagged == 0) + .Join(dbContext.Users, + message => message.AuthorId, + user => user.UserId, + (message, user) => new MessageWithAuthorModel + { + Message = message, + Author = user, + }) + .OrderByDescending(ma => ma.Message.PubDate) + .Take(n) + .ToListAsync(); + } + + public async Task> GetMessagesByAuthorAsync(int n, int authorId) + { + return await dbContext.Messages + .Where(m => m.Flagged == 0 && m.AuthorId == authorId) + .Join(dbContext.Users, + message => message.AuthorId, + user => user.UserId, + (message, user) => new MessageWithAuthorModel + { + Message = message, + Author = user, + }) + .OrderByDescending(ma => ma.Message.PubDate) + .Take(n) + .ToListAsync(); + } + + public async Task> GetFollowedMessages(int n, int userId) + { + return await dbContext.Messages + .Where(m => m.Flagged == 0) + .Join(dbContext.Users, + message => message.AuthorId, + user => user.UserId, + (message, user) => new MessageWithAuthorModel + { + Message = message, + Author = user, + }) + .Where(ma => + ma.Author.UserId == userId + || dbContext.Followers.Any(f => f.WhoId == userId && f.WhomId == ma.Author.UserId)) + .OrderByDescending(ma => ma.Message.PubDate) + .Take(n) + .ToListAsync(); + } + + public async Task> GetApiMessagesAsync(int n) + { + return await dbContext.Messages + .Where(m => m.Flagged == 0) + .OrderByDescending(m => m.PubDate) + .Take(n) + .Select(m => new APIMessageModel + { + content = m.Text, + pub_date = m.PubDate, + user = m.Author.Username + }) + .ToListAsync(); + } + + public async Task> GetApiMessagesByAuthorAsync(int n, int authorId) + { + return await dbContext.Messages + .Where(m => m.AuthorId == authorId && m.Flagged == 0) + .OrderByDescending(m => m.PubDate) + .Take(n) + .Select(m => new APIMessageModel + { + content = m.Text, + pub_date = m.PubDate, + user = m.Author.Username + }) + .ToListAsync(); + } + } } \ No newline at end of file diff --git a/csharp-minitwit/Utils/SanitizeMetricsPath.cs b/csharp-minitwit/Utils/SanitizeMetricsPath.cs index 95fc66d..6c9d632 100644 --- a/csharp-minitwit/Utils/SanitizeMetricsPath.cs +++ b/csharp-minitwit/Utils/SanitizeMetricsPath.cs @@ -1,26 +1,23 @@ -namespace csharp_minitwit.Utils -{ - public static class MetricsHelpers - { - - public static string SanitizePath(string path) - { - // Normalize and simplify the path - var normalizedPath = path.Trim('/').ToLower(); - switch (normalizedPath) - { - case "public": - case "register": - case "login": - case "logout": - case "add_message": - case "follow": - case "unfollow": - - return normalizedPath; - default: - return "other"; // Generalize other paths to reduce cardinality - } - } - } +namespace csharp_minitwit.Utils +{ + public static class MetricsHelpers + { + + public static string SanitizePath(string path) + { + // Normalize and simplify the path + var normalizedPath = path.Trim('/').ToLower(); + switch (normalizedPath) + { + case "public": + case "register": + case "login": + case "logout": + case "add_message": + return normalizedPath; + default: + return "other"; // Generalize other paths to reduce cardinality + } + } + } } \ No newline at end of file From 7cdeff35c6f1a46891bbb004f760a9c2f0a06dc8 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:07:30 +0100 Subject: [PATCH 02/13] chore: remove log to console --- csharp-minitwit/Services/Repositories/FollowerRepository.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/csharp-minitwit/Services/Repositories/FollowerRepository.cs b/csharp-minitwit/Services/Repositories/FollowerRepository.cs index bf1513d..bf460fc 100644 --- a/csharp-minitwit/Services/Repositories/FollowerRepository.cs +++ b/csharp-minitwit/Services/Repositories/FollowerRepository.cs @@ -20,7 +20,6 @@ await dbContext.Followers.AddAsync(new Follower }); watch.Stop(); - Console.WriteLine("/follow"); ApplicationMetrics.HttpRequestDuration .WithLabels(MetricsHelpers.SanitizePath("/follow")) .Observe(watch.Elapsed.TotalSeconds); @@ -40,7 +39,6 @@ public async Task Unfollow(int whoId, int whomId) await dbContext.SaveChangesAsync(); watch.Stop(); - Console.WriteLine("/unfollow"); ApplicationMetrics.HttpRequestDuration .WithLabels(MetricsHelpers.SanitizePath("unfollow")) .Observe(watch.Elapsed.TotalSeconds); From 96a925a9e4be71e936082252fb071cd6700c54eb Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:23:20 +0100 Subject: [PATCH 03/13] refactor: apply formatting --- csharp-minitwit/Controllers/HomeController.cs | 4 +- csharp-minitwit/Metrics/ApplicationMetrics.cs | 60 +-- .../Middlewares/CatchAllMiddleware.cs | 7 +- ...322123833_compatibility_with_postgresql.cs | 418 +++++++++--------- csharp-minitwit/Program.cs | 9 +- csharp-minitwit/Services/MinitwitContext.cs | 196 ++++---- 6 files changed, 349 insertions(+), 345 deletions(-) diff --git a/csharp-minitwit/Controllers/HomeController.cs b/csharp-minitwit/Controllers/HomeController.cs index 51d711a..7013a99 100644 --- a/csharp-minitwit/Controllers/HomeController.cs +++ b/csharp-minitwit/Controllers/HomeController.cs @@ -6,12 +6,12 @@ using csharp_minitwit.Models.ViewModels; using csharp_minitwit.Services.Interfaces; using csharp_minitwit.Services.Repositories; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.EntityFrameworkCore.Query; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query; namespace csharp_minitwit.Controllers; diff --git a/csharp-minitwit/Metrics/ApplicationMetrics.cs b/csharp-minitwit/Metrics/ApplicationMetrics.cs index e23c0d9..a821cb5 100644 --- a/csharp-minitwit/Metrics/ApplicationMetrics.cs +++ b/csharp-minitwit/Metrics/ApplicationMetrics.cs @@ -1,30 +1,30 @@ -using Prometheus; - -public static class ApplicationMetrics -{ - public static readonly Histogram HttpRequestDuration = Metrics - .CreateHistogram("minitwit_http_request_duration_seconds", "Histogram of HTTP request duration.", - new HistogramConfiguration - { - // Define buckets with appropriate ranges for your application - Buckets = Histogram.LinearBuckets(start: 0.1, width: 0.1, count: 10), - LabelNames = new[] { "endpoint" } - }); - - public static readonly Counter HttpResponseStatusCodeTotal = Metrics - .CreateCounter("minitwit_http_response_status_code_total", "Total number of HTTP responses sent by the application by status code.", - new CounterConfiguration - { - // Add a label for the HTTP status code - LabelNames = new[] { "status_code" } - }); - - public static readonly Counter HttpRequestTotal = Metrics - .CreateCounter("minitwit_http_requests_total", "Total number of HTTP requests made to the application.", - new CounterConfiguration - { - LabelNames = new[] { "endpoint" } - }); - - -} +using Prometheus; + +public static class ApplicationMetrics +{ + public static readonly Histogram HttpRequestDuration = Metrics + .CreateHistogram("minitwit_http_request_duration_seconds", "Histogram of HTTP request duration.", + new HistogramConfiguration + { + // Define buckets with appropriate ranges for your application + Buckets = Histogram.LinearBuckets(start: 0.1, width: 0.1, count: 10), + LabelNames = new[] { "endpoint" } + }); + + public static readonly Counter HttpResponseStatusCodeTotal = Metrics + .CreateCounter("minitwit_http_response_status_code_total", "Total number of HTTP responses sent by the application by status code.", + new CounterConfiguration + { + // Add a label for the HTTP status code + LabelNames = new[] { "status_code" } + }); + + public static readonly Counter HttpRequestTotal = Metrics + .CreateCounter("minitwit_http_requests_total", "Total number of HTTP requests made to the application.", + new CounterConfiguration + { + LabelNames = new[] { "endpoint" } + }); + + +} \ No newline at end of file diff --git a/csharp-minitwit/Middlewares/CatchAllMiddleware.cs b/csharp-minitwit/Middlewares/CatchAllMiddleware.cs index 7a838f5..168231f 100644 --- a/csharp-minitwit/Middlewares/CatchAllMiddleware.cs +++ b/csharp-minitwit/Middlewares/CatchAllMiddleware.cs @@ -1,7 +1,9 @@ using System.Diagnostics; -using Microsoft.AspNetCore.Http; using System.Threading.Tasks; + using csharp_minitwit.Utils; + +using Microsoft.AspNetCore.Http; // Assuming ApplicationMetrics is in the same namespace, or add the appropriate using statement namespace csharp_minitwit.Middlewares @@ -25,7 +27,6 @@ public async Task InvokeAsync(HttpContext context) await _next(context); watch.Stop(); - // Used to monitor response delay grouped by endpoint ApplicationMetrics.HttpRequestDuration .WithLabels(MetricsHelpers.SanitizePath(context.Request.Path)) @@ -35,4 +36,4 @@ public async Task InvokeAsync(HttpContext context) ApplicationMetrics.HttpResponseStatusCodeTotal.WithLabels(context.Response.StatusCode.ToString()).Inc(); } } -} +} \ No newline at end of file diff --git a/csharp-minitwit/Migrations/20240322123833_compatibility_with_postgresql.cs b/csharp-minitwit/Migrations/20240322123833_compatibility_with_postgresql.cs index 0660a0e..9ee5b57 100644 --- a/csharp-minitwit/Migrations/20240322123833_compatibility_with_postgresql.cs +++ b/csharp-minitwit/Migrations/20240322123833_compatibility_with_postgresql.cs @@ -1,209 +1,209 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace csharp_minitwit.Migrations -{ - /// - public partial class compatibility_with_postgresql : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropPrimaryKey( - name: "PK_Follower", - table: "follower"); - - migrationBuilder.RenameColumn( - name: "message_id", - table: "message", - newName: "MessageId"); - - migrationBuilder.RenameColumn( - name: "follower_id", - table: "follower", - newName: "FollowerId"); - - migrationBuilder.AlterColumn( - name: "user_id", - table: "user", - type: "integer", - nullable: false, - oldClrType: typeof(int), - oldType: "INTEGER") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AlterColumn( - name: "pub_date", - table: "message", - type: "integer", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "INTEGER", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "flagged", - table: "message", - type: "integer", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "INTEGER", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "author_id", - table: "message", - type: "integer", - nullable: false, - oldClrType: typeof(int), - oldType: "INTEGER"); - - migrationBuilder.AlterColumn( - name: "MessageId", - table: "message", - type: "integer", - nullable: false, - oldClrType: typeof(int), - oldType: "INTEGER") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AlterColumn( - name: "whom_id", - table: "follower", - type: "integer", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "INTEGER", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "who_id", - table: "follower", - type: "integer", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "INTEGER", - oldNullable: true); - - migrationBuilder.AlterColumn( - name: "FollowerId", - table: "follower", - type: "integer", - nullable: false, - oldClrType: typeof(int), - oldType: "INTEGER") - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AddPrimaryKey( - name: "PK_follower", - table: "follower", - column: "FollowerId"); - - migrationBuilder.CreateIndex( - name: "IX_user_username", - table: "user", - column: "username"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropIndex( - name: "IX_user_username", - table: "user"); - - migrationBuilder.DropPrimaryKey( - name: "PK_follower", - table: "follower"); - - migrationBuilder.RenameColumn( - name: "MessageId", - table: "message", - newName: "message_id"); - - migrationBuilder.RenameColumn( - name: "FollowerId", - table: "follower", - newName: "follower_id"); - - migrationBuilder.AlterColumn( - name: "user_id", - table: "user", - type: "INTEGER", - nullable: false, - oldClrType: typeof(int), - oldType: "integer") - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AlterColumn( - name: "pub_date", - table: "message", - type: "INTEGER", - nullable: true, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "flagged", - table: "message", - type: "INTEGER", - nullable: true, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "author_id", - table: "message", - type: "INTEGER", - nullable: false, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "message_id", - table: "message", - type: "INTEGER", - nullable: false, - oldClrType: typeof(int), - oldType: "integer") - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AlterColumn( - name: "whom_id", - table: "follower", - type: "INTEGER", - nullable: true, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "who_id", - table: "follower", - type: "INTEGER", - nullable: true, - oldClrType: typeof(int), - oldType: "integer"); - - migrationBuilder.AlterColumn( - name: "follower_id", - table: "follower", - type: "INTEGER", - nullable: false, - oldClrType: typeof(int), - oldType: "integer") - .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - migrationBuilder.AddPrimaryKey( - name: "PK_Follower", - table: "follower", - column: "follower_id"); - } - } -} +using Microsoft.EntityFrameworkCore.Migrations; + +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace csharp_minitwit.Migrations +{ + /// + public partial class compatibility_with_postgresql : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Follower", + table: "follower"); + + migrationBuilder.RenameColumn( + name: "message_id", + table: "message", + newName: "MessageId"); + + migrationBuilder.RenameColumn( + name: "follower_id", + table: "follower", + newName: "FollowerId"); + + migrationBuilder.AlterColumn( + name: "user_id", + table: "user", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "pub_date", + table: "message", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "flagged", + table: "message", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "author_id", + table: "message", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "MessageId", + table: "message", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "whom_id", + table: "follower", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "who_id", + table: "follower", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "INTEGER", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "FollowerId", + table: "follower", + type: "integer", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_follower", + table: "follower", + column: "FollowerId"); + + migrationBuilder.CreateIndex( + name: "IX_user_username", + table: "user", + column: "username"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_user_username", + table: "user"); + + migrationBuilder.DropPrimaryKey( + name: "PK_follower", + table: "follower"); + + migrationBuilder.RenameColumn( + name: "MessageId", + table: "message", + newName: "message_id"); + + migrationBuilder.RenameColumn( + name: "FollowerId", + table: "follower", + newName: "follower_id"); + + migrationBuilder.AlterColumn( + name: "user_id", + table: "user", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "pub_date", + table: "message", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "flagged", + table: "message", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "author_id", + table: "message", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "message_id", + table: "message", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AlterColumn( + name: "whom_id", + table: "follower", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "who_id", + table: "follower", + type: "INTEGER", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "follower_id", + table: "follower", + type: "INTEGER", + nullable: false, + oldClrType: typeof(int), + oldType: "integer") + .OldAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + migrationBuilder.AddPrimaryKey( + name: "PK_Follower", + table: "follower", + column: "follower_id"); + } + } +} \ No newline at end of file diff --git a/csharp-minitwit/Program.cs b/csharp-minitwit/Program.cs index 5c12f71..e20e3a3 100644 --- a/csharp-minitwit/Program.cs +++ b/csharp-minitwit/Program.cs @@ -1,12 +1,15 @@ using System.Reflection; -using Microsoft.OpenApi.Models; + using csharp_minitwit; using csharp_minitwit.Middlewares; +using csharp_minitwit.Middlewares; using csharp_minitwit.Services.Interfaces; -using Microsoft.EntityFrameworkCore; using csharp_minitwit.Services.Repositories; + +using Microsoft.EntityFrameworkCore; +using Microsoft.OpenApi.Models; + using Prometheus; -using csharp_minitwit.Middlewares; var builder = WebApplication.CreateBuilder(args); diff --git a/csharp-minitwit/Services/MinitwitContext.cs b/csharp-minitwit/Services/MinitwitContext.cs index 54c5039..eaaa0ee 100644 --- a/csharp-minitwit/Services/MinitwitContext.cs +++ b/csharp-minitwit/Services/MinitwitContext.cs @@ -1,99 +1,99 @@ -using System; -using System.Collections.Generic; - -using Microsoft.EntityFrameworkCore; - -namespace csharp_minitwit; - -public partial class MinitwitContext : DbContext -{ - private readonly string _connectionString; - - public MinitwitContext() { } - - public MinitwitContext(DbContextOptions options) - : base(options) - { - } - - public virtual DbSet Followers { get; set; } - - public virtual DbSet Messages { get; set; } - - public virtual DbSet Users { get; set; } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - if (!optionsBuilder.IsConfigured) - { - optionsBuilder.UseSqlite(_connectionString); - } - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity(entity => - { - entity.ToTable("follower"); - - entity.HasKey(e => e.FollowerId); - - entity.HasOne(e => e.Who) - .WithMany(u => u.Following) - .HasForeignKey(e => e.WhoId) - .OnDelete(DeleteBehavior.Restrict) // Prevent cascading delete - .HasConstraintName("FK_Follower_Who"); - - entity.HasOne(e => e.Whom) - .WithMany(u => u.Followers) - .HasForeignKey(e => e.WhomId) - .OnDelete(DeleteBehavior.Restrict) // Prevent cascading delete - .HasConstraintName("FK_Follower_Whom"); - - entity.Property(e => e.WhoId).HasColumnName("who_id"); - entity.Property(e => e.WhomId).HasColumnName("whom_id"); - }); - - modelBuilder.Entity(entity => - { - entity.ToTable("message"); - - entity.HasKey(e => e.MessageId); - - entity.HasOne(m => m.Author) - .WithMany(u => u.Messages) - .HasForeignKey(m => m.AuthorId) - .OnDelete(DeleteBehavior.Cascade) // Prevent cascading delete - .HasConstraintName("FK_Message_User"); - - entity.Property(e => e.AuthorId).HasColumnName("author_id"); - entity.Property(e => e.Flagged).HasColumnName("flagged"); - entity.Property(e => e.PubDate).HasColumnName("pub_date"); - entity.Property(e => e.Text) - .HasColumnType("text") - .HasColumnName("text"); - }); - - modelBuilder.Entity(entity => - { - entity.ToTable("user"); - - entity.Property(e => e.UserId).HasColumnName("user_id").ValueGeneratedOnAdd(); - entity.Property(e => e.Email) - .HasColumnType("text") - .HasColumnName("email"); - entity.Property(e => e.PwHash) - .HasColumnType("text") - .HasColumnName("pw_hash"); - entity.Property(e => e.Username) - .HasColumnType("text") - .HasColumnName("username"); - entity.HasIndex(e => e.Username); - }); - - OnModelCreatingPartial(modelBuilder); - } - - - partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +using System; +using System.Collections.Generic; + +using Microsoft.EntityFrameworkCore; + +namespace csharp_minitwit; + +public partial class MinitwitContext : DbContext +{ + private readonly string _connectionString; + + public MinitwitContext() { } + + public MinitwitContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Followers { get; set; } + + public virtual DbSet Messages { get; set; } + + public virtual DbSet Users { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseSqlite(_connectionString); + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.ToTable("follower"); + + entity.HasKey(e => e.FollowerId); + + entity.HasOne(e => e.Who) + .WithMany(u => u.Following) + .HasForeignKey(e => e.WhoId) + .OnDelete(DeleteBehavior.Restrict) // Prevent cascading delete + .HasConstraintName("FK_Follower_Who"); + + entity.HasOne(e => e.Whom) + .WithMany(u => u.Followers) + .HasForeignKey(e => e.WhomId) + .OnDelete(DeleteBehavior.Restrict) // Prevent cascading delete + .HasConstraintName("FK_Follower_Whom"); + + entity.Property(e => e.WhoId).HasColumnName("who_id"); + entity.Property(e => e.WhomId).HasColumnName("whom_id"); + }); + + modelBuilder.Entity(entity => + { + entity.ToTable("message"); + + entity.HasKey(e => e.MessageId); + + entity.HasOne(m => m.Author) + .WithMany(u => u.Messages) + .HasForeignKey(m => m.AuthorId) + .OnDelete(DeleteBehavior.Cascade) // Prevent cascading delete + .HasConstraintName("FK_Message_User"); + + entity.Property(e => e.AuthorId).HasColumnName("author_id"); + entity.Property(e => e.Flagged).HasColumnName("flagged"); + entity.Property(e => e.PubDate).HasColumnName("pub_date"); + entity.Property(e => e.Text) + .HasColumnType("text") + .HasColumnName("text"); + }); + + modelBuilder.Entity(entity => + { + entity.ToTable("user"); + + entity.Property(e => e.UserId).HasColumnName("user_id").ValueGeneratedOnAdd(); + entity.Property(e => e.Email) + .HasColumnType("text") + .HasColumnName("email"); + entity.Property(e => e.PwHash) + .HasColumnType("text") + .HasColumnName("pw_hash"); + entity.Property(e => e.Username) + .HasColumnType("text") + .HasColumnName("username"); + entity.HasIndex(e => e.Username); + }); + + OnModelCreatingPartial(modelBuilder); + } + + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } \ No newline at end of file From 6211b677d6c407b9592b38e34271427fb01ed83c Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:26:34 +0100 Subject: [PATCH 04/13] fix: add checkout steps in workflow --- .github/workflows/quality.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 97e22ab..428bcce 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -30,5 +30,7 @@ jobs: git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git checkout ${{ github.ref_name }} + git add . git commit -am "Automated formatting" git push From a6a358e475c5ab147d80bbbbde7a609aa3161e1e Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:29:39 +0100 Subject: [PATCH 05/13] fix: correct branch reference --- .github/workflows/quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 428bcce..02e6011 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -30,7 +30,7 @@ jobs: git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git checkout ${{ github.ref_name }} + git checkout ${{ github.head_ref }} git add . git commit -am "Automated formatting" git push From 0fe2fb12dded6740f062b3be74bf85b445934962 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:31:23 +0100 Subject: [PATCH 06/13] fix: replace repo reference --- .github/workflows/quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 02e6011..4e237ab 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -29,7 +29,7 @@ jobs: run: | git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{github.action_repository}} git checkout ${{ github.head_ref }} git add . git commit -am "Automated formatting" From 7f63c4e551b0407bccbc59dd1bec0a3aff594a5b Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:36:16 +0100 Subject: [PATCH 07/13] fix: hardcode repo to test --- .github/workflows/quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 4e237ab..6ec03aa 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -29,7 +29,7 @@ jobs: run: | git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{github.action_repository}} + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DevopsGroupC/Minitwit git checkout ${{ github.head_ref }} git add . git commit -am "Automated formatting" From 7ef716290341df9756b399d862fe57a91ed021e2 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:41:36 +0100 Subject: [PATCH 08/13] feat: add branch fetching --- .github/workflows/quality.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 6ec03aa..1ee4427 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -30,6 +30,7 @@ jobs: git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DevopsGroupC/Minitwit + git fetch --all git checkout ${{ github.head_ref }} git add . git commit -am "Automated formatting" From 43e347e6f2597a0cc73a3f0cf736a1d635e3f2af Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:43:27 +0100 Subject: [PATCH 09/13] fix: syntax --- .github/workflows/quality.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 1ee4427..4cdb274 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetches all history for all branches and tags - name: Setup .NET uses: actions/setup-dotnet@v4 @@ -30,8 +32,7 @@ jobs: git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DevopsGroupC/Minitwit - git fetch --all - git checkout ${{ github.head_ref }} + git checkout 'origin/${{ github.head_ref }}' git add . git commit -am "Automated formatting" git push From b251e991696693b690600b3185ebed861e6f9485 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:46:06 +0100 Subject: [PATCH 10/13] feat: add check for files to commit --- .github/workflows/quality.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 4cdb274..f6180b7 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -34,5 +34,10 @@ jobs: git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DevopsGroupC/Minitwit git checkout 'origin/${{ github.head_ref }}' git add . - git commit -am "Automated formatting" - git push + # Check if there are any changes to commit + if git diff --staged --quiet; then + echo "No changes to commit." + else + git commit -am "Automated formatting" + git push + fi From 71294c5831781713957819e6198d91c20f689e09 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 19:52:34 +0100 Subject: [PATCH 11/13] refactor: update workflow --- .github/workflows/quality.yml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index f6180b7..c30ad9e 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -2,8 +2,11 @@ name: Format check on push on: pull_request: types: [opened, reopened, edited, synchronize, ready_for_review] - # branches: - # - feature/software-quality-tools + + push: + branches: + - feature/software-quality-tools + jobs: dotnet-format: runs-on: ubuntu-latest @@ -13,8 +16,6 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetches all history for all branches and tags - name: Setup .NET uses: actions/setup-dotnet@v4 @@ -27,17 +28,18 @@ jobs: - name: Format run: dotnet format ./csharp-minitwit/csharp-minitwit.sln --verbosity diagnostic + - name: Lint Dockerfile + uses: hadolint/hadolint-action@master + with: + dockerfile: ./csharp-minitwit/Dockerfile + + # - name: Lint C# code + # run: dotnet build + - name: Push changes run: | git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/DevopsGroupC/Minitwit - git checkout 'origin/${{ github.head_ref }}' - git add . - # Check if there are any changes to commit - if git diff --staged --quiet; then - echo "No changes to commit." - else - git commit -am "Automated formatting" - git push - fi + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY + git commit -am "Automated formatting" + git push \ No newline at end of file From 3b4ccbe67b467214916be1f0586296aa7c3e1d0a Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 20:00:27 +0100 Subject: [PATCH 12/13] refactor: consolidate RUN commands --- csharp-minitwit/Dockerfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/csharp-minitwit/Dockerfile b/csharp-minitwit/Dockerfile index 7bd2d9f..2e349a1 100644 --- a/csharp-minitwit/Dockerfile +++ b/csharp-minitwit/Dockerfile @@ -6,9 +6,8 @@ WORKDIR /app COPY . . -RUN dotnet restore - -RUN dotnet publish -c Release -o out +RUN dotnet restore && \ + dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app @@ -17,7 +16,7 @@ WORKDIR /app ARG ENVIRONMENT ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT} -COPY --from=build /app/out . +COPY --from=build /app/out . COPY ./Databases/schema.sql ./schema.sql COPY ./Databases/volume/minitwit.db ./Databases/volume/minitwit.db COPY ./Services/latest_processed_sim_action_id.txt ./Services/latest_processed_sim_action_id.txt From 993e11e635b006cf0a7af50aec5ea752c00f3a03 Mon Sep 17 00:00:00 2001 From: Martin Lupa Date: Sun, 24 Mar 2024 20:04:27 +0100 Subject: [PATCH 13/13] fix: fix push --- .github/workflows/quality.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index c30ad9e..66dad1b 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -2,10 +2,6 @@ name: Format check on push on: pull_request: types: [opened, reopened, edited, synchronize, ready_for_review] - - push: - branches: - - feature/software-quality-tools jobs: dotnet-format: @@ -41,5 +37,13 @@ jobs: git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git commit -am "Automated formatting" - git push \ No newline at end of file + git fetch --all + git checkout 'origin/${{ github.head_ref }}' + git add . + # Check if there are any changes to commit + if git diff --staged --quiet; then + echo "No changes to commit." + else + git commit -am "Automated formatting" + git push + fi