From 7f3042ef3c96f3076eacb62d062506b60571d168 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sat, 12 Oct 2024 16:19:49 +0300 Subject: [PATCH 01/18] Added redirect middleware --- AutoHub.API/Middlewares/ReditectMiddleware.cs | 17 +++++++++++++++++ AutoHub.API/Program.cs | 1 + AutoHub.API/Validators/PaginationValidator.cs | 1 - AutoHub.BusinessLogic/Services/EmailService.cs | 3 +-- AutoHub.BusinessLogic/Services/UserService.cs | 2 -- .../ValidatorsTests/UserValidatorTests.cs | 3 +-- 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 AutoHub.API/Middlewares/ReditectMiddleware.cs diff --git a/AutoHub.API/Middlewares/ReditectMiddleware.cs b/AutoHub.API/Middlewares/ReditectMiddleware.cs new file mode 100644 index 0000000..78b8f4c --- /dev/null +++ b/AutoHub.API/Middlewares/ReditectMiddleware.cs @@ -0,0 +1,17 @@ +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"); + } + + 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.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.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; From 602fdbe5885a7f586bc17de0ab09fa7b15d6b96d Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sat, 12 Oct 2024 16:20:36 +0300 Subject: [PATCH 02/18] Fixed redirect middleware --- AutoHub.API/Middlewares/ReditectMiddleware.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AutoHub.API/Middlewares/ReditectMiddleware.cs b/AutoHub.API/Middlewares/ReditectMiddleware.cs index 78b8f4c..be83baf 100644 --- a/AutoHub.API/Middlewares/ReditectMiddleware.cs +++ b/AutoHub.API/Middlewares/ReditectMiddleware.cs @@ -10,6 +10,7 @@ public async Task InvokeAsync(HttpContext httpContext) if (httpContext.Request.Path == "/") { httpContext.Response.Redirect("/index.html"); + return; } await next(httpContext); From 08a6cadf29b6f198e54e089f57000623f754ccf3 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sat, 12 Oct 2024 23:29:43 +0300 Subject: [PATCH 03/18] Updated connection strings --- AutoHub.API/appsettings.Development.json | 2 +- AutoHub.API/appsettings.json | 2 +- AutoHub.DataAccess/AutoHubContext.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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.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); } From 4b47a82cc2eb0293c853a8b0fec122af7382f9f7 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sat, 12 Oct 2024 23:32:43 +0300 Subject: [PATCH 04/18] Fixed App name in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92c3f90..5001cf9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: id: deploy-to-webapp uses: azure/webapps-deploy@v3 with: - app-name: 'AutoHubAPI' + app-name: 'AutoHubApp' slot-name: 'Production' package: . \ No newline at end of file From 6669e0978767a8f34f15c9ad784882dcf88861f0 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 00:01:54 +0300 Subject: [PATCH 05/18] Tying CI --- .github/workflows/ci.yml | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5001cf9..1db781a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,17 @@ on: push: branches: - master + pull_request: + branches: + - '*' workflow_dispatch: +env: + AZURE_WEBAPP_NAME: AutoHubApp # set this to your application's name + AZURE_WEBAPP_PACKAGE_PATH: '.' # 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 + SLOT_NAME: 'Production' + jobs: build: name: Build @@ -20,19 +29,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 }}/.publish' - name: Upload build artifact uses: actions/upload-artifact@v4 with: - name: .net-app - path: ./publish + name: ${{ env.AZURE_WEBAPP_NAME }} + path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.publish test: name: Test @@ -45,7 +54,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,14 +65,13 @@ jobs: - name: Run tests with dotnet run: dotnet test --no-build --no-restore --configuration Release - deploy: name: Deploy to Azure runs-on: windows-latest needs: test environment: - name: 'Production' + name: ${{ env.SLOT_NAME }} url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} permissions: id-token: write @@ -72,7 +80,7 @@ jobs: - name: Download artifact from build job uses: actions/download-artifact@v4 with: - name: .net-app + name: ${{ env.AZURE_WEBAPP_NAME }} - name: Login to Azure uses: azure/login@v2 @@ -85,7 +93,7 @@ jobs: id: deploy-to-webapp uses: azure/webapps-deploy@v3 with: - app-name: 'AutoHubApp' - slot-name: 'Production' - package: . + app-name: ${{ env.AZURE_WEBAPP_NAME }} + slot-name: ${{ env.SLOT_NAME }} + package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.publish \ No newline at end of file From 1f157c6640d045b4ded81ba6bde0f1700a602833 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 00:09:47 +0300 Subject: [PATCH 06/18] CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1db781a..e3ba737 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ on: workflow_dispatch: env: - AZURE_WEBAPP_NAME: AutoHubApp # set this to your application's name + AZURE_WEBAPP_NAME: 'AutoHubApp' # set this to your application's name AZURE_WEBAPP_PACKAGE_PATH: '.' # 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 SLOT_NAME: 'Production' From 36ee62190e09916609f4eb3bb842fc0ca330c74e Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 00:16:36 +0300 Subject: [PATCH 07/18] CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3ba737..181153a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ env: AZURE_WEBAPP_NAME: 'AutoHubApp' # set this to your application's name AZURE_WEBAPP_PACKAGE_PATH: '.' # 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 - SLOT_NAME: 'Production' + SLOT_NAME: 'Production' # set this to the slot name to use jobs: build: From 27a89a0a00ffa080f1adf5a7fd8e9871cc81f2c4 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 00:19:10 +0300 Subject: [PATCH 08/18] CI --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 181153a..64c268e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,6 @@ env: AZURE_WEBAPP_NAME: 'AutoHubApp' # set this to your application's name AZURE_WEBAPP_PACKAGE_PATH: '.' # 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 - SLOT_NAME: 'Production' # set this to the slot name to use jobs: build: @@ -71,7 +70,7 @@ jobs: needs: test environment: - name: ${{ env.SLOT_NAME }} + name: 'Production' url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} permissions: id-token: write @@ -94,6 +93,6 @@ jobs: uses: azure/webapps-deploy@v3 with: app-name: ${{ env.AZURE_WEBAPP_NAME }} - slot-name: ${{ env.SLOT_NAME }} + slot-name: 'Production' package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.publish \ No newline at end of file From 7b72ae8d5f8a7224a095d923b002f3095d2f97c4 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 00:27:29 +0300 Subject: [PATCH 09/18] CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64c268e..b18d7b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,5 +94,5 @@ jobs: with: app-name: ${{ env.AZURE_WEBAPP_NAME }} slot-name: 'Production' - package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.publish + package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} \ No newline at end of file From 531807940196f8ce122cffc785e3aa8a34e71040 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 13:25:38 +0300 Subject: [PATCH 10/18] CI Fix --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b18d7b4..e0c54bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,8 @@ on: workflow_dispatch: env: - AZURE_WEBAPP_NAME: 'AutoHubApp' # set this to your application's name - AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root + 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: @@ -34,13 +34,13 @@ jobs: run: dotnet build --configuration Release - name: Publish artifact - run: dotnet publish -c Release -o '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/.publish' + 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 }}/.publish + path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} test: name: Test From 065cb84b2116681cea917e361ecf4ccdb452c567 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 14:06:04 +0300 Subject: [PATCH 11/18] CI yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0c54bd..2016429 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ on: 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 + 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: From be911b32ec6f3d965a537b1843ad2d5a6acbc222 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Sun, 13 Oct 2024 23:47:34 +0300 Subject: [PATCH 12/18] CI try of fix --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2016429..246fce6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ on: workflow_dispatch: env: - AZURE_WEBAPP_NAME: '.auto-hub-app' # set this to your application's name + 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 @@ -34,7 +34,7 @@ jobs: run: dotnet build --configuration Release - name: Publish artifact - run: dotnet publish -c Release -o '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}' + run: dotnet publish -c Release -o ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} - name: Upload build artifact uses: actions/upload-artifact@v4 From 4e175f387b80da8e925323ef6a4cdbda1afa237c Mon Sep 17 00:00:00 2001 From: Nikita Reshetnik <45916288+grafanaKibana@users.noreply.github.com> Date: Mon, 14 Oct 2024 00:25:51 +0300 Subject: [PATCH 13/18] Add or update the Azure App Service build and deployment workflow config --- .github/workflows/develop_autohubapp.yml | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/develop_autohubapp.yml diff --git a/.github/workflows/develop_autohubapp.yml b/.github/workflows/develop_autohubapp.yml new file mode 100644 index 0000000..cb64788 --- /dev/null +++ b/.github/workflows/develop_autohubapp.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 deploy ASP.Net Core app to Azure Web App - AutoHubApp + +on: + push: + branches: + - develop + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: Build with dotnet + run: dotnet build --configuration Release + + - name: dotnet publish + run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v4 + with: + name: .net-app + path: ${{env.DOTNET_ROOT}}/myapp + + deploy: + runs-on: windows-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + permissions: + id-token: write #This is required for requesting the JWT + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + name: .net-app + + - name: Login to Azure + uses: azure/login@v2 + with: + 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' + slot-name: 'Production' + package: . + \ No newline at end of file From 2a0e5961cd05a52284149649d9d4312d0544688e Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Mon, 14 Oct 2024 00:28:44 +0300 Subject: [PATCH 14/18] Updated CI files, created separate files for th e develop and master --- .github/workflows/develop_autohubapp.yml | 65 --------------------- .github/workflows/develop_ci.yml | 65 +++++++++++++++++++++ .github/workflows/{ci.yml => master_ci.yml} | 6 +- 3 files changed, 68 insertions(+), 68 deletions(-) delete mode 100644 .github/workflows/develop_autohubapp.yml create mode 100644 .github/workflows/develop_ci.yml rename .github/workflows/{ci.yml => master_ci.yml} (91%) diff --git a/.github/workflows/develop_autohubapp.yml b/.github/workflows/develop_autohubapp.yml deleted file mode 100644 index cb64788..0000000 --- a/.github/workflows/develop_autohubapp.yml +++ /dev/null @@ -1,65 +0,0 @@ -# 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 ASP.Net Core app to Azure Web App - AutoHubApp - -on: - push: - branches: - - develop - workflow_dispatch: - -jobs: - build: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v4 - - - name: Set up .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '8.x' - - - name: Build with dotnet - run: dotnet build --configuration Release - - - name: dotnet publish - run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp - - - name: Upload artifact for deployment job - uses: actions/upload-artifact@v4 - with: - name: .net-app - path: ${{env.DOTNET_ROOT}}/myapp - - deploy: - runs-on: windows-latest - needs: build - environment: - name: 'Production' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - permissions: - id-token: write #This is required for requesting the JWT - - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - name: .net-app - - - name: Login to Azure - uses: azure/login@v2 - with: - 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' - slot-name: 'Production' - package: . - \ No newline at end of file diff --git a/.github/workflows/develop_ci.yml b/.github/workflows/develop_ci.yml new file mode 100644 index 0000000..43001a6 --- /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 deploy + +on: + push: + branches: + - develop + pull_request: + branches: + - '*' + 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 91% rename from .github/workflows/ci.yml rename to .github/workflows/master_ci.yml index 246fce6..aa3f909 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/master_ci.yml @@ -84,9 +84,9 @@ jobs: - name: Login to Azure uses: azure/login@v2 with: - client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5BD849A4FE6E4C0DB7AD0EB5E846624D }} - tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_178D5841557B44B6846E2B87FE48DD59 }} - subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_028CAC2C085347419D18855B1FF0AC4C }} + 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 From c3bcb9cf18d7f58dbe97a9ee6abd49c1f91cad59 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Mon, 14 Oct 2024 00:31:33 +0300 Subject: [PATCH 15/18] Fixed CI naming --- .github/workflows/develop_ci.yml | 2 +- .github/workflows/master_ci.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/develop_ci.yml b/.github/workflows/develop_ci.yml index 43001a6..3cf32e1 100644 --- a/.github/workflows/develop_ci.yml +++ b/.github/workflows/develop_ci.yml @@ -1,7 +1,7 @@ # 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 and test on: push: diff --git a/.github/workflows/master_ci.yml b/.github/workflows/master_ci.yml index aa3f909..19fde3f 100644 --- a/.github/workflows/master_ci.yml +++ b/.github/workflows/master_ci.yml @@ -1,7 +1,7 @@ # 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: From b1fb34b89a778c34397c404da3f18224606485f8 Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Mon, 14 Oct 2024 00:44:20 +0300 Subject: [PATCH 16/18] Updated Azure app name --- .github/workflows/master_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/master_ci.yml b/.github/workflows/master_ci.yml index 19fde3f..4bceeb6 100644 --- a/.github/workflows/master_ci.yml +++ b/.github/workflows/master_ci.yml @@ -13,7 +13,7 @@ on: workflow_dispatch: env: - AZURE_WEBAPP_NAME: 'auto-hub-app' # set this to your application's name + 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 From 58ace0bd2f51010264d347d67dcaaba7185042ca Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Mon, 14 Oct 2024 00:49:08 +0300 Subject: [PATCH 17/18] Fixed triggers --- .github/workflows/develop_ci.yml | 4 ++-- .github/workflows/master_ci.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/develop_ci.yml b/.github/workflows/develop_ci.yml index 3cf32e1..73bebd8 100644 --- a/.github/workflows/develop_ci.yml +++ b/.github/workflows/develop_ci.yml @@ -6,10 +6,10 @@ name: Build and test on: push: branches: - - develop + - '!master' pull_request: branches: - - '*' + - 'develop' workflow_dispatch: env: diff --git a/.github/workflows/master_ci.yml b/.github/workflows/master_ci.yml index 4bceeb6..42bbed9 100644 --- a/.github/workflows/master_ci.yml +++ b/.github/workflows/master_ci.yml @@ -6,10 +6,10 @@ name: Build, test and deploy on: push: branches: - - master + - 'master' pull_request: branches: - - '*' + - 'master' workflow_dispatch: env: From 410cb225514ecb82cde85618f039c39d479f79ae Mon Sep 17 00:00:00 2001 From: nikitareshetnik Date: Mon, 14 Oct 2024 01:09:35 +0300 Subject: [PATCH 18/18] CI --- .github/workflows/master_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/master_ci.yml b/.github/workflows/master_ci.yml index 42bbed9..520f48e 100644 --- a/.github/workflows/master_ci.yml +++ b/.github/workflows/master_ci.yml @@ -94,5 +94,5 @@ jobs: with: app-name: ${{ env.AZURE_WEBAPP_NAME }} slot-name: 'Production' - package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} + package: . \ No newline at end of file