diff --git a/.github/workflows/develop_ci.yml b/.github/workflows/develop_ci.yml new file mode 100644 index 0000000..73bebd8 --- /dev/null +++ b/.github/workflows/develop_ci.yml @@ -0,0 +1,65 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and test + +on: + push: + branches: + - '!master' + pull_request: + branches: + - 'develop' + workflow_dispatch: + +env: + AZURE_WEBAPP_NAME: 'auto-hub-app' # set this to your application's name + AZURE_WEBAPP_PACKAGE_PATH: './publish' # set this to the path to your web app project, defaults to the repository root + DOTNET_VERSION: '8.x' # set this to the dot net version to use + +jobs: + build: + name: Build + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Build with dotnet + run: dotnet build --configuration Release + + - name: Publish artifact + run: dotnet publish -c Release -o ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.AZURE_WEBAPP_NAME }} + path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} + + test: + name: Test + runs-on: windows-latest + needs: build + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Build with dotnet + run: dotnet build --configuration Release + + - name: Restore dependencies + run: dotnet restore + + - name: Run tests with dotnet + run: dotnet test --no-build --no-restore --configuration Release \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/master_ci.yml similarity index 63% rename from .github/workflows/ci.yml rename to .github/workflows/master_ci.yml index 8a5389e..520f48e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/master_ci.yml @@ -1,14 +1,22 @@ # Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy # More GitHub Actions for Azure: https://github.com/Azure/actions -name: Build and deploy +name: Build, test and deploy on: push: branches: - - master + - 'master' + pull_request: + branches: + - 'master' workflow_dispatch: +env: + AZURE_WEBAPP_NAME: 'AutoHubApp' # set this to your application's name + AZURE_WEBAPP_PACKAGE_PATH: './publish' # set this to the path to your web app project, defaults to the repository root + DOTNET_VERSION: '8.x' # set this to the dot net version to use + jobs: build: name: Build @@ -20,19 +28,19 @@ jobs: - name: Set up .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: "8.x" + dotnet-version: ${{ env.DOTNET_VERSION }} - name: Build with dotnet run: dotnet build --configuration Release - name: Publish artifact - run: dotnet publish -c Release -o ./publish + run: dotnet publish -c Release -o ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} - name: Upload build artifact uses: actions/upload-artifact@v4 with: - name: .autohub-artifacts - path: ./publish + name: ${{ env.AZURE_WEBAPP_NAME }} + path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} test: name: Test @@ -45,7 +53,7 @@ jobs: - name: Set up .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: "8.x" + dotnet-version: ${{ env.DOTNET_VERSION }} - name: Build with dotnet run: dotnet build --configuration Release @@ -56,7 +64,6 @@ jobs: - name: Run tests with dotnet run: dotnet test --no-build --no-restore --configuration Release - deploy: name: Deploy to Azure runs-on: windows-latest @@ -72,20 +79,20 @@ jobs: - name: Download artifact from build job uses: actions/download-artifact@v4 with: - name: .autohub-artifacts + name: ${{ env.AZURE_WEBAPP_NAME }} - name: Login to Azure uses: azure/login@v2 with: - client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_C858A91760294A7E968810EBCA7F4CFD }} - tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_E46CDD63D0554EE68973979DDB7E5095 }} - subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_96C8763478B642DF952093578964EE66 }} + client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_D8F08FF4580C4308A9B851754C2EB53A }} + tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_20D1A7B5198E45CB92C2D3AC6AEF683E }} + subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_6503C5D792634D21975C28A9B4896C84 }} - name: Deploy to Azure Web App id: deploy-to-webapp uses: azure/webapps-deploy@v3 with: - app-name: 'AutoHubApp' + app-name: ${{ env.AZURE_WEBAPP_NAME }} slot-name: 'Production' package: . - + \ No newline at end of file diff --git a/AutoHub.API/Middlewares/ReditectMiddleware.cs b/AutoHub.API/Middlewares/ReditectMiddleware.cs new file mode 100644 index 0000000..be83baf --- /dev/null +++ b/AutoHub.API/Middlewares/ReditectMiddleware.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.Http; +using System.Threading.Tasks; + +namespace AutoHub.API.Middlewares; + +public class RedirectMiddleware(RequestDelegate next) +{ + public async Task InvokeAsync(HttpContext httpContext) + { + if (httpContext.Request.Path == "/") + { + httpContext.Response.Redirect("/index.html"); + return; + } + + await next(httpContext); + } +} diff --git a/AutoHub.API/Program.cs b/AutoHub.API/Program.cs index 75b663e..edf8676 100644 --- a/AutoHub.API/Program.cs +++ b/AutoHub.API/Program.cs @@ -55,6 +55,7 @@ app.UseSwaggerDocumentation(); app.UseRedocDocumentation(); app.UseMiddleware(); +app.UseMiddleware(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); diff --git a/AutoHub.API/Validators/PaginationValidator.cs b/AutoHub.API/Validators/PaginationValidator.cs index 48a6534..afe8135 100644 --- a/AutoHub.API/Validators/PaginationValidator.cs +++ b/AutoHub.API/Validators/PaginationValidator.cs @@ -2,7 +2,6 @@ using AutoHub.BusinessLogic.Models; using AutoHub.Domain.Constants; using FluentValidation; -using Microsoft.IdentityModel.Tokens; namespace AutoHub.API.Validators; diff --git a/AutoHub.API/appsettings.Development.json b/AutoHub.API/appsettings.Development.json index eb943d8..3b66e8d 100644 --- a/AutoHub.API/appsettings.Development.json +++ b/AutoHub.API/appsettings.Development.json @@ -13,7 +13,7 @@ "HoursToExpire": 3 }, "ConnectionStrings": { - "PostgresConnectionString": "Host=localhost;Port=5432;Database=AutoHubDb;Username=postgres;Password=admin;Include Error Detail=true;", + "PostgresConnectionString": "Server=tcp:autohub-server.database.windows.net,1433;Initial Catalog=autohub-db;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default;", "AzureSqlServerConnectionString": "Server=autohub-db.database.windows.net,1433;Initial Catalog=AutoHubDb;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default" } } \ No newline at end of file diff --git a/AutoHub.API/appsettings.json b/AutoHub.API/appsettings.json index de13105..ff3839e 100644 --- a/AutoHub.API/appsettings.json +++ b/AutoHub.API/appsettings.json @@ -14,6 +14,6 @@ "HoursToExpire": 3 }, "ConnectionStrings": { - "AzureSqlServerConnectionString": "Server=autohub-db.database.windows.net,1433;Initial Catalog=AutoHubDb;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default" + "AzureSqlServerConnectionString": "Server=tcp:autohub-server.database.windows.net,1433;Initial Catalog=autohub-db;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default;" } } \ No newline at end of file diff --git a/AutoHub.BusinessLogic/Services/EmailService.cs b/AutoHub.BusinessLogic/Services/EmailService.cs index f3fc751..47da877 100644 --- a/AutoHub.BusinessLogic/Services/EmailService.cs +++ b/AutoHub.BusinessLogic/Services/EmailService.cs @@ -1,5 +1,4 @@ -using System.IO; -using AutoHub.BusinessLogic.Configuration; +using AutoHub.BusinessLogic.Configuration; using AutoHub.BusinessLogic.Interfaces; using MailKit.Net.Smtp; using Microsoft.Extensions.Options; diff --git a/AutoHub.BusinessLogic/Services/UserService.cs b/AutoHub.BusinessLogic/Services/UserService.cs index 72466b0..041f05b 100644 --- a/AutoHub.BusinessLogic/Services/UserService.cs +++ b/AutoHub.BusinessLogic/Services/UserService.cs @@ -7,12 +7,10 @@ using AutoHub.Domain.Exceptions; using AutoMapper; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.WebUtilities; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; using AutoHub.BusinessLogic.Common; using AutoHub.BusinessLogic.Models; diff --git a/AutoHub.DataAccess/AutoHubContext.cs b/AutoHub.DataAccess/AutoHubContext.cs index 5fe88fa..ba1e747 100644 --- a/AutoHub.DataAccess/AutoHubContext.cs +++ b/AutoHub.DataAccess/AutoHubContext.cs @@ -29,7 +29,7 @@ public AutoHubContext(DbContextOptions options) : base(options) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer("Server=autohub-db.database.windows.net,1433;Initial Catalog=AutoHubDb;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default"); + optionsBuilder.UseSqlServer("Server=tcp:autohub-server.database.windows.net,1433;Initial Catalog=autohub-db;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;Authentication=Active Directory Default;"); optionsBuilder.UseLazyLoadingProxies(); optionsBuilder.LogTo(Console.WriteLine); } diff --git a/AutoHub.Tests/ValidatorsTests/UserValidatorTests.cs b/AutoHub.Tests/ValidatorsTests/UserValidatorTests.cs index 1a6b36b..6e14fb3 100644 --- a/AutoHub.Tests/ValidatorsTests/UserValidatorTests.cs +++ b/AutoHub.Tests/ValidatorsTests/UserValidatorTests.cs @@ -1,5 +1,4 @@ -using AutoFixture; -using AutoHub.API.Models.UserModels; +using AutoHub.API.Models.UserModels; using AutoHub.API.Validators.ModelValidators; using FluentValidation.TestHelper; using Xunit;