Add IaC Deployment to workflow #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy .NET Core application to Web App learn-iac-arm | |
on: | |
push: | |
branches: | |
- 01-10e | |
env: | |
AZURE_WEBAPP_NAME: learn-iac-arm | |
AZURE_WEBAPP_PACKAGE_PATH: src\myApp\published | |
CONFIGURATION: Release | |
DOTNET_CORE_VERSION: 8.0.x | |
WORKING_DIRECTORY: src\myApp | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ env.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: Publish Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: webapp | |
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
deployIaC: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
# Login to Azure | |
- name: Login via Azure CLI | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_CREDENTIALS }} | |
# Deploy ARM template | |
- name: Deploy ARM template | |
uses: Azure/CLI@v1 | |
with: | |
inlineScript: | | |
cd infra/vsDeploy | |
az deployment group create --resource-group rg-learn-azure-IaC --template-file WebSite.json --parameters WebSite.parameters.json | |
deploy: | |
runs-on: windows-latest | |
needs: | |
- build | |
- deployIaC | |
steps: | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v3 | |
with: | |
name: webapp | |
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
- name: Deploy to Azure WebApp | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
publish-profile: ${{ secrets.learn_iac_arm_AC39 }} | |
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |