Skip to content
Open
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
77 changes: 69 additions & 8 deletions .github/workflows/azure-webapps-dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ env:
on:
push:
branches: [ "main" ]
paths:
#TODO: Add path to WebAPI project
# TODO: add pull request events to trigger the workflow
paths:
- "My-WebAPI/**"
pull_request:
branches: [ "main" ]
paths:
- "My-WebAPI/**"

workflow_dispatch:
inputs:
Expand Down Expand Up @@ -55,17 +58,24 @@ jobs:
- name: Set variables to be passed to the reusable workflow
id: setEnvVariables
run: |
echo "AZURE_WEBAPP_NAME=<YOUR-WEBAPP-NAME>" >> "$GITHUB_OUTPUT"
echo "RESOURCE_GROUP=<YOUR-RG-NAME>" >> "$GITHUB_OUTPUT"
echo "AZURE_WEBAPP_NAME=webapp-technightjfr" >> "$GITHUB_OUTPUT"
echo "RESOURCE_GROUP=JFRTechNight2023" >> "$GITHUB_OUTPUT"

# Add Action to Setup .NET Core
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: #TODO: Add .NET Core version
dotnet-version: ${{env.DOTNET_VERSION}} #TODO: Add .NET Core version

# TODO: Add Action to Build Web App
- name: Build Web App
run: |
dotnet build ${{ env.WEBAPP_BASE_PATH }} -c Release --no-restore

# TODO: Add Action to Run Unit Tests
- name: Run Unit Tests
run: |
dotnet test ${{ env.WEBAPP_BASE_PATH }} -c Release --no-build --no-restore --logger "trx;LogFileName=testresults.trx"

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
Expand All @@ -74,8 +84,23 @@ jobs:
files: ${{ env.WEBAPP_BASE_PATH }}/**/*.trx

# TODO: Add Action to Publish Web App
- name: Publish Web App
run: |
dotnet publish ${{ env.WEBAPP_BASE_PATH }}/WebAPI -c Release -c Release -o ${{ env.DOTNET_ROOT }}/technight-webapi

# TODO: Add Action to Upload Web App Artifacts for Deployment
- name: Upload Web App Artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: ${{ env.DOTNET_ROOT }}/technight-webapi

# TODO: Add Action to Upload Bicep Template for Deployment
- name: Upload Bicep Template
uses: actions/upload-artifact@v2
with:
name: bicep-template
path: arm-templates/webapp/azuredeploy.bicep

########################
# DEVELOPMENT STAGE
Expand All @@ -85,23 +110,59 @@ jobs:
contents: none
runs-on: ubuntu-latest
needs: build
environment: <ENVIRONMENT-NAME>
environment: 'Dev'

# TODO: declare environment variables for the dev environment prefix
env:
ENVIRONMENT_PREFIX: Dev

steps:

# Download the artifacts from the build job (actions/download-artifact@v3)
- name: download-artifact
id: download
uses: actions/download-artifact@v3
with:
name: <YOUR-ARTIFACT-NAME>
name: artifacts

#TODO: Add action to login to Azure (azure/login@v1)
- name: Azure Login
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

#TODO: Add action to deploy the Web App Bicep Template (azure/arm-deploy@v1)
- name: Deploy ARM Template
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroupName: ${{ env.ENVIRONMENT_PREFIX }}-${{ needs.build.outputs.RESOURCE_GROUP }}
template: 'azuredeploy.bicep'
parameters: >
envPrefix=${{ env.ENVIRONMENT_PREFIX }}
webAppName=${{ needs.build.outputs.AZURE_WEBAPP_NAME }}
sku="B1"
failOnStdErr: false

#TODO: Add action to deploy the Web App Artifacts (azure/webapps-deploy@v2)
- name: deploy-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.ENVIRONMENT_PREFIX }}-${{ needs.build.outputs.AZURE_WEBAPP_NAME }}
package: ${{steps.download.outputs.download-path}}
startup-command: 'dotnet WebAPI.dll'

#TODO: Add action to configure the Web App Settings (azure/appservice-settings@v1)
- name: Configure App Settings
uses: azure/appservice-settings@v1
with:
app-name: ${{ env.ENVIRONMENT_PREFIX }}-${{ needs.build.outputs.AZURE_WEBAPP_NAME }}
app-settings-json: ${{ secrets.APP_SETTINGS }}
connection-strings-json: ${{ secrets.CONNECTION_STRINGS }}

#TODO: Add action to log out of Azure
- name: Azure Logout
uses: azure/logout@v1

##############################
# PRODUCTION STAGE (FOR LATER)
Expand Down