Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/dotnet-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: .NET CI/CD

on:
pull_request:
push:
branches:
- main
workflow_dispatch:

env:
DOTNET_VERSION: "10.0.x"
APP_SERVICE_NAME: ${{ vars.APP_SERVICE_NAME }}
RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
UAT_SLOT_NAME: "uat"
PRODUCTION_SLOT_NAME: "production"
ARTIFACT_NAME: "webapp-publish"

jobs:
build_and_test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: Restore
run: dotnet restore docker-app.sln

- name: Build
run: dotnet build docker-app.sln --configuration Release --no-restore

- name: Test
run: dotnet test docker-app.sln --configuration Release --no-build --no-restore

- name: Publish
run: dotnet publish src/docker-app.csproj --configuration Release --no-restore --no-build --output ./publish

- name: Create deployment package
run: |
cd publish
zip -r ../webapp.zip .

- name: Upload publish artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ./webapp.zip
if-no-files-found: error

deploy_uat:
if: github.event_name != 'pull_request'
needs: build_and_test
runs-on: ubuntu-latest
environment: uat
permissions:
contents: read
id-token: write
steps:
- name: Download publish artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: .

- name: Azure login
uses: azure/login@v2

Check failure on line 71 in .github/workflows/dotnet-ci-cd.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=sayedimac_docker-app&issues=AaAe5qJ0XO9zXBuKH05k&open=AaAe5qJ0XO9zXBuKH05k&pullRequest=58
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Deploy to UAT slot
run: az webapp deploy --resource-group "${{ env.RESOURCE_GROUP }}" --name "${{ env.APP_SERVICE_NAME }}" --slot "${{ env.UAT_SLOT_NAME }}" --type zip --src-path ./webapp.zip

deploy_prod:
if: github.event_name != 'pull_request'
needs: deploy_uat
runs-on: ubuntu-latest
environment: prod
permissions:
contents: read
id-token: write
steps:
- name: Azure login
uses: azure/login@v2

Check failure on line 90 in .github/workflows/dotnet-ci-cd.yml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use full commit SHA hash for this dependency.

See more on https://sonarcloud.io/project/issues?id=sayedimac_docker-app&issues=AaAe5qJ0XO9zXBuKH05l&open=AaAe5qJ0XO9zXBuKH05l&pullRequest=58
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Swap slots to production
run: az webapp deployment slot swap --resource-group "${{ env.RESOURCE_GROUP }}" --name "${{ env.APP_SERVICE_NAME }}" --slot "${{ env.UAT_SLOT_NAME }}" --target-slot "${{ env.PRODUCTION_SLOT_NAME }}"
4 changes: 2 additions & 2 deletions src/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - myWebApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/myWebApp.styles.css" asp-append-version="true" />
</head>
Expand Down Expand Up @@ -43,7 +43,7 @@
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<script type="text/javascript" src="https://js.monitor.azure.com/scripts/b/ext/ai.clck.2.min.js"></script>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion src/docker-app.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down