2021-11-03 17:58:38 -07:00
# This workflow will build and push a Python application to an Azure Web App when a commit is pushed to your default branch.
2021-10-27 12:20:09 -07:00
#
# This workflow assumes you have already created the target Azure App Service web app.
2021-11-16 09:43:18 -08:00
# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=bash&pivots=python-framework-flask
2021-10-27 12:20:09 -07:00
#
# To configure this workflow:
#
# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials
#
# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret
#
2021-11-16 09:43:18 -08:00
# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the PYTHON_VERSION environment variables below.
2021-10-27 12:20:09 -07:00
#
# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions
# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples
2021-10-15 15:33:45 -07:00
2021-10-24 21:45:21 -07:00
name : Build and deploy Python app to Azure Web App
2021-10-15 15:33:45 -07:00
env :
AZURE_WEBAPP_NAME : your-app-name # set this to the name of your Azure Web App
2021-10-24 21:45:21 -07:00
PYTHON_VERSION : '3.8' # set this to the Python version to use
2021-10-15 15:33:45 -07:00
on :
push :
2022-08-30 10:13:31 -04:00
branches : [ $default-branch ]
2021-10-15 15:33:45 -07:00
workflow_dispatch :
2022-03-19 15:39:54 +05:30
permissions :
contents : read
2021-10-15 15:33:45 -07:00
jobs :
build :
runs-on : ubuntu-latest
steps :
2022-03-28 13:10:48 -04:00
- uses : actions/checkout@v3
2021-10-15 15:33:45 -07:00
- name : Set up Python version
2022-03-28 13:10:48 -04:00
uses : actions/setup-python@v3.0.0
2021-10-15 15:33:45 -07:00
with :
python-version : ${{ env.PYTHON_VERSION }}
2021-11-25 10:03:14 +00:00
cache : 'pip'
2021-10-15 15:33:45 -07:00
- name : Create and start virtual environment
run : |
python -m venv venv
source venv/bin/activate
2021-11-24 14:26:16 -08:00
2021-10-15 15:33:45 -07:00
- name : Install dependencies
run : pip install -r requirements.txt
2022-11-04 20:45:41 +01:00
2021-10-15 15:33:45 -07:00
# Optional: Add step to run tests here (PyTest, Django test suites, etc.)
2022-11-04 20:45:41 +01:00
2021-10-15 15:33:45 -07:00
- name : Upload artifact for deployment jobs
2022-03-14 07:35:28 -07:00
uses : actions/upload-artifact@v3
2021-10-15 15:33:45 -07:00
with :
name : python-app
path : |
2022-11-04 20:45:41 +01:00
.
2021-10-15 15:33:45 -07:00
!venv/
deploy :
2022-03-19 15:39:54 +05:30
permissions :
contents : none
2021-10-15 15:33:45 -07:00
runs-on : ubuntu-latest
needs : build
environment :
2021-10-24 21:45:21 -07:00
name : 'Development'
2021-10-15 15:33:45 -07:00
url : ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps :
- name : Download artifact from build job
2022-03-14 07:35:28 -07:00
uses : actions/download-artifact@v3
2021-10-15 15:33:45 -07:00
with :
name : python-app
path : .
2022-11-04 20:45:41 +01:00
2021-10-15 15:33:45 -07:00
- name : 'Deploy to Azure Web App'
id : deploy-to-webapp
2021-10-27 12:20:09 -07:00
uses : azure/webapps-deploy@v2
2021-10-15 15:33:45 -07:00
with :
2021-10-24 21:45:21 -07:00
app-name : ${{ env.AZURE_WEBAPP_NAME }}
2021-10-15 15:33:45 -07:00
publish-profile : ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}