Bot Continuous Delivery - microsoft-campus-community/workshop-shopping-list-bot GitHub Wiki

Prerequisite: If you do not have the Azure resources, you should go to the Deploy Bot page first. It also assumes that you have forked this repository and have the bot working locally. If you do not have a working bot, go back to Test Bot locally.

Continuous delivery boils down to defining a script to automate the steps of building the bot and publishing it to Azure.

The Action

You can find the .github/workflows folder where all continuous delivery pipelines for this workshop are defined in the root of the repository. The pipeline to continuously deliver the bot is defined in the main_shopping-list-bot-web-app.yml file.

The on part of the yml file tells GitHub when to run this action.

on:
  push:
    branches:
      - main
    paths:
      - 'shopping-list-bot/**'

You can see that it will only run when you push changes on your main branch from your local git repository to your forked repository of this repository on GitHub. Because this is a mono-repository, meaning that there are different projects (i.e. one for the bot and one for the Azure Funtions) in this repository, the paths option in the push trigger is defined. As a result, only changes in the folder shopping-list-bot where the bot is located will trigger this action. If the bot does not change then GitHub should not redeploy it.

Next in the main_shopping-list-bot-web-app.yml file some environment variables for when running the action are defined.

env:  
  AZURE_WEBAPP_NAME: <shopping-list-bot-web-app> # set this to your application's name  
  AZURE_WEBAPP_PACKAGE_PATH: 'shopping-list-bot' # set this to the path to your web app project, defaults to the repository root  
  NODE_VERSION: '14.x' # set this to the node version to use

Here you need to replace with the name of your web app you defined when creating the resources for the bot in the previous bot deployment step. You can push your updated webapp name to your forked repository and will not have to change it unless you change the name of the app service.

Below the environment variables different steps are defined to run when this action is triggered.

  1. GitHub's action runner will configure NodeJS on GitHub's server executing your pipeline.
  2. NPM will install the dependencies for the bot, build it and test the bot.
  3. GitHub's action runner will publish the output from building the bot to your Azure App Service. Note that in this step publish-profile: ${{ secrets.AzureAppService_PublishProfile_bcee5b88aa5b4ee2aa4c3c4a525cbcfe }} use one last piece of configuration. A secret that allows GitHub to connect with your Azure. The following steps explain how to set up this secret.

Set GitHub Secrets for Azure

GitHub needs to communicate with your Azure when running the pipeline. You need to configure this connection using GitHub secret you get from Azure.

  1. Go to the Azure portal and navigate to your App Service in the resource group you created for this workshop. Screenshot of Azure Portal with App Service resource for the bot open.
  2. With the App Service resource open you should click on the Deployment Center under Deployment in the left navigation list.
  3. In the deployment center, click on the Manage publish profile button in the top row. Screenshot of Azure Portal with App Service Deployment Center for bot open.
  4. In the 'Manage Publish Profile' panel click on the Download publish profile button. This will download a profile.yml file. Screenshot of Azure Portal with App Service Deployment Center Manage Publish Profile open and red circle around 'Download publish profile' button.
  5. When the profile.yml file is downloaded you need to open it in an editor and copy its entire content.
  6. In your browser navigate to your fork of this repository on GitHub.
  7. Click on the Settings tab.
  8. In the list of settings click on Secrets.
  9. On the secrets page click on the New repository secret button. Screenshot of GitHub.com showing how to navigate to secrets page in settings. Red circle around 'New repository secret' button.
  10. In the Value textbox paste the entire content of the publish.yml file you downloaded from Azure.
  11. In the Name field for the secret paste AzureAppService_PublishProfile_bcee5b88aa5b4ee2aa4c3c4a525cbcfe which is how the GitHub Action references the secret.
  12. Click Add secret.

The next time you push changes to you bot project on the main branch of your forked repository to GitHub it will trigger the GitHub Action and deploy the changes to your bot running in the cloud. You can try it out now by doing any change in the shopping-list-bot folder of your forked repository.

NEXT: Configure your bot in Azure