From 2cb3d6f1e57347ef7eebd6dde2e6d3d14655d662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20W=C4=99grzyniak?= Date: Wed, 28 Jan 2026 22:08:08 +0100 Subject: [PATCH] adjust yml to run tests & fix release to exclude tests in azure app service --- .../CulinaryRecipesAPI20231012231909.yml | 85 ----------- .github/workflows/master_netreciapi.yml | 137 ++++++++++-------- 2 files changed, 74 insertions(+), 148 deletions(-) delete mode 100644 .github/workflows/CulinaryRecipesAPI20231012231909.yml diff --git a/.github/workflows/CulinaryRecipesAPI20231012231909.yml b/.github/workflows/CulinaryRecipesAPI20231012231909.yml deleted file mode 100644 index 2c8452d..0000000 --- a/.github/workflows/CulinaryRecipesAPI20231012231909.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Build and deploy .NET Core application to Web App CulinaryRecipesAPI20231012231909 with API Management Service CulinaryRecipesAPIapi-CulinaryRecipesAPI -on: - push: - branches: - - master -env: - AZURE_WEBAPP_NAME: CulinaryRecipesAPI20231012231909 - AZURE_WEBAPP_PACKAGE_PATH: CulinaryRecipes.API/publish - AZURE_APIM_RESOURCE_PATH: /api - AZURE_APIM_RESOURCEGROUP: CulinaryRecipesAPI20231012231909ResourceGroup - AZURE_APIM_SERVICENAME: CulinaryRecipesAPIapi - AZURE_APIM_API_ID: CulinaryRecipesAPI - AZURE_APIM_APPSERVICEURL: https://culinaryrecipesapi20231012231909.azurewebsites.net - SWASHBUCLE_ASPNET_CORE_CLI_PACKAGE_VERSION: 6.5.0 - SWASHBUCKLE_DOTNET_CORE_VERSION: 8.0.x - API_IMPORT_SPECIFICATION_PATH: CulinaryRecipes.API/publish/swagger.json - API_IMPORT_DLL: CulinaryRecipes.API/bin/Release/net8.0/CulinaryRecipes.API.dll - API_IMPORT_VERSION: v1 - CONFIGURATION: Release - DOTNET_CORE_VERSION: 8.0.x - WORKING_DIRECTORY: CulinaryRecipes.API -jobs: - build: - runs-on: ubuntu-latest - environment: Production - steps: - - uses: actions/checkout@v4 - - name: Setup .NET SDK - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.DOTNET_CORE_VERSION }} - - name: Setup SwashBuckle .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: ${{ env.SWASHBUCKLE_DOTNET_CORE_VERSION }} - - name: Restore - run: dotnet restore ${{ env.WORKING_DIRECTORY }} - - name: Build - run: dotnet build ${{ env.WORKING_DIRECTORY }} --configuration ${{ env.CONFIGURATION }} --no-restore - - name: Test - run: dotnet test ${{ env.WORKING_DIRECTORY }} --no-build - - name: Publish - run: dotnet publish ${{ env.WORKING_DIRECTORY }} --configuration ${{ env.CONFIGURATION }} --no-build --output ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} - - name: Install Swashbuckle CLI .NET Global Tool - run: dotnet tool install --global Swashbuckle.AspNetCore.Cli --version ${{ env.SWASHBUCLE_ASPNET_CORE_CLI_PACKAGE_VERSION }} - working-directory: ${{ env.WORKING_DIRECTORY }} - - name: Generate Open API Specification Document - run: swagger tofile --output "${{ env.API_IMPORT_SPECIFICATION_PATH }}" "${{ env.API_IMPORT_DLL }}" "${{ env.API_IMPORT_VERSION }}" - env: - IdentityDatabase__ConnectionString: ${{ secrets.IDENTITYDATABASE__CONNECTIONSTRING }} - IdentityDatabase__UsersCollectionName: ${{ secrets.IDENTITYDATABASE__USERSCOLLECTIONNAME }} - IdentityDatabase__RolesCollectionName: ${{ secrets.IDENTITYDATABASE__ROLESCOLLECTIONNAME }} - AdminUser__Email: ${{ secrets.ADMINUSER__EMAIL }} - AdminUser__Password: ${{ secrets.ADMINUSER__PASSWORD }} - AdminUser__Nick: ${{ secrets.ADMINUSER__NICK }} - AdminUser__SecurityStamp: ${{ secrets.ADMINUSER__SECURITYSTAMP }} - - name: Publish Artifacts - uses: actions/upload-artifact@v4 - with: - name: webapp - path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} - deploy: - runs-on: ubuntu-latest - needs: build - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - name: webapp - path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} - - name: Deploy to Azure WebApp - uses: azure/webapps-deploy@v3 - with: - app-name: ${{ env.AZURE_WEBAPP_NAME }} - package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} - publish-profile: ${{ secrets.CulinaryRecipesAPI20231012231909_3E47 }} - - name: Azure Login - uses: azure/login@v2 - with: - creds: ${{ secrets.CULINARYRECIPESAPI_AZURECREDENTIALS }} - - name: Import API into Azure API Management - run: az apim api import --path "${{ env.AZURE_APIM_RESOURCE_PATH }}" --resource-group "${{ env.AZURE_APIM_RESOURCEGROUP }}" --service-name "${{ env.AZURE_APIM_SERVICENAME }}" --api-id "${{ env.AZURE_APIM_API_ID }}" --service-url "${{ env.AZURE_APIM_APPSERVICEURL }}" --specification-path "${{ env.API_IMPORT_SPECIFICATION_PATH }}" --specification-format OpenApi --subscription-required false - - name: logout - run: > - az logout diff --git a/.github/workflows/master_netreciapi.yml b/.github/workflows/master_netreciapi.yml index dab223e..200b271 100644 --- a/.github/workflows/master_netreciapi.yml +++ b/.github/workflows/master_netreciapi.yml @@ -1,68 +1,79 @@ -# 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, Test, Publish, Deploy -name: Build and deploy ASP.Net Core app to Azure Web App - netreciapi on: - push: - branches: - - master - workflow_dispatch: +push: +branches: [ "main" ] +workflow_dispatch: + + +env: +DOTNET_VERSION: "8.0.x" +API_PROJECT: "src/CulinaryRecipes.API/CulinaryRecipes.API.csproj" +SOLUTION: "CulinaryRecipes.sln" +PUBLISH_DIR: "./publish" +AZURE_WEBAPP_NAME: "YOUR_APP_SERVICE_NAME" # <- change + jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read #This is required for actions/checkout - - 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: ubuntu-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 - contents: read #This is required for actions/checkout - - 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_702DF9E4C49447A09FB435256A0BFDF4 }} - tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_1E09EF65FD164B7584DED561E6528FEE }} - subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_57B0D59F8E5A4A0BB61D99F32D529581 }} - - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v3 - with: - app-name: 'netreciapi' - slot-name: 'Production' - package: . - \ No newline at end of file +ci: +name: Build & Test & Publish +runs-on: ubuntu-latest + + +steps: +- name: Checkout +uses: actions/checkout@v4 + + +- name: Setup .NET +uses: actions/setup-dotnet@v4 +with: +dotnet-version: ${{ env.DOTNET_VERSION }} + + +- name: Restore +run: dotnet restore ${{ env.SOLUTION }} + + +- name: Build +run: dotnet build ${{ env.SOLUTION }} -c Release --no-restore + + +# ✅ If tests fail, the job fails and the pipeline is NOT successful +- name: Test +run: dotnet test ${{ env.SOLUTION }} -c Release --no-build --verbosity normal + + +# ✅ Publish ONLY the API project (prevents deploying *.Tests.runtimeconfig.json) +- name: Publish API +run: dotnet publish ${{ env.API_PROJECT }} -c Release -o ${{ env.PUBLISH_DIR }} --no-build + + +- name: Upload artifact (published app) +uses: actions/upload-artifact@v4 +with: +name: api_publish +path: ${{ env.PUBLISH_DIR }} + + +deploy: +name: Deploy to Azure App Service +runs-on: ubuntu-latest +needs: ci # ✅ deploy runs ONLY if ci (including tests) succeeded + + +steps: +- name: Download artifact +uses: actions/download-artifact@v4 +with: +name: api_publish +path: ${{ env.PUBLISH_DIR }} + + +- name: Deploy +uses: azure/webapps-deploy@v3 +with: +app-name: ${{ env.AZURE_WEBAPP_NAME }} +publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} +package: ${{ env.PUBLISH_DIR }} \ No newline at end of file