Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
In this lab, you will learn how to create a reusable GitHub Actions workflow for deploying an ASP.NET Web App to Azure. This reusable workflow will allow you to standardize the deployment process across multiple workflows or projects by passing in parameters for the web app name and package path.
.github/workflows
directory of your repository.Create a new file named reusable-workflow-azure-webapp-deploy.yml
.
reusable-workflow-azure-webapp-deploy.yml
file. This workflow is responsible for deploying the web app to Azure.name: Reusable Workflow Azure Web App Deploy
on:
workflow_call:
inputs:
AZURE_WEBAPP_PACKAGE_PATH:
required: true
type: string
AZURE_WEBAPP_NAME:
required: true
type: string
secrets:
AZURE_SERVICE_PRINCIPAL:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: webapp
path: $
- name: Azure Login
uses: azure/login@v2
with:
creds: $
- name: Deploy to Azure WebApp
uses: azure/webapps-deploy@v2
with:
app-name: $
package: $
workflow_call
: This event allows other workflows to call this reusable workflow. It defines two required inputs:
AZURE_WEBAPP_PACKAGE_PATH
: The path to the web app package that will be deployed.AZURE_WEBAPP_NAME
: The name of the Azure Web App where the package will be deployed.It also defines a required secret AZURE_SERVICE_PRINCIPAL
for authentication with Azure.
deploy
job:
actions/download-artifact@v4
: Downloads the build artifact (the web app package) from the previous job or workflow.azure/login@v2
: Logs in to Azure using the provided Service Principal.azure/webapps-deploy@v2
: Deploys the web app to Azure using the specified web app name and package.Congratulations! You have created a shared GitHub Actions workflow for deploying an ASP.NET Web App to Azure. This shared workflow can be reused across multiple workflows or projects by passing in parameters for the web app name and package path.