When setting up CI/CD pipeline in one of my projects I decided to give Azure App Service a try. I was using GitHub Actions for building and testing the app written in ASP.NET Core. While there were a plenty of resources about how to configure actions with a basic project structure, I couldn’t find any YAML that could be used when you have your project split into two for testing (as required by .NET) and hence decided to share.
The action definition below assumes the following:
- your app name on Azure is appname (appname.azurewebsites.net)
- the project is split into two (ExampleProject and ExampleProject.Tests) as described in the docs
- you are using .NET Core 3.1 (needed to specify the build artifacts folder)
- your App Service Publish Profile is stored in the repo’s azureASPublishProfile secret
name: Production deploy
on:
push:
branches: [production]
env:
AZURE_AS_NAME: appname
AZURE_AS_PACKAGE_PATH: "./ExampleProject/bin/Release/netcoreapp3.1"
jobs:
build-test-deploy:
name: Build, Test and Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.101
- name: Build
working-directory: ./ExampleProject/
run: dotnet build --configuration Release
- name: Test
working-directory: ./ExampleProject.Tests/
run: dotnet test --configuration Release
- name: Deploy
uses: azure/webapps-deploy@v1
with:
app-name: ${{ env.AZURE_AS_NAME }}
publish-profile: ${{ secrets.azureASPublishProfile }}
package: ${{ env.AZURE_AS_PACKAGE_PATH }}
Action breakdown
This action is triggered whenever changes are pushed to production branch. It first sets up .NET Core on GitHub’s vm, on which the action is running. After that, it builds and tests the app with dotnet cli. The final step (provided that all the prior ones have been completed successfully) is to deploy the app using azure/webapps-deploy
. The most important part here is to specify the appropriate path in which the build artifacts are going to be after the previous steps taking into account the project structure.