Skip to content

Merge branch 'master' of https://github.com/segunak/charlotte-third-p… #7

Merge branch 'master' of https://github.com/segunak/charlotte-third-p…

Merge branch 'master' of https://github.com/segunak/charlotte-third-p… #7

# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions
name: Deploy Azure Function
on:
push:
branches:
- master
paths:
- 'azure-function/**' # Ensures the workflow triggers for changes in the azure-function folder
pull_request:
branches:
- master
paths:
- 'azure-function/**' # Ensures the workflow triggers for PRs affecting the azure-function folder
workflow_dispatch:
concurrency:
group: deploy-azure-function
cancel-in-progress: true
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: './azure-function' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python version
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: pip install -r requirements.txt --target=.python_packages
working-directory: ./azure-function
- name: Zip artifact for deployment
run: zip release.zip ./azure-function -r
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: python-app
path: |
release.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: python-app
- name: Unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Function'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'charlotte-third-places'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
scm-do-build-during-deployment: true
enable-oryx-build: true
respect-funcignore: true
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_578D7E3EBA21453795CE9E97514E2950 }}
- name: Smoke Test
run: |
#!/bin/bash
set -euo pipefail
API_URL="https://charlotte-third-places.azurewebsites.net/api/smoke-test"
REQUEST_BODY='{"House":"Martell"}'
response=$(curl -s -w "\n%{http_code}" -X POST \
-H "Content-Type: application/json" \
-H "x-functions-key: ${{ secrets.AZURE_FUNCTION_KEY }}" \
-d "$REQUEST_BODY" \
"$API_URL")
http_status=$(tail -n1 <<< "$response")
response_body=$(sed '$ d' <<< "$response")
echo "HTTP Status: $http_status"
echo "Response Body: $response_body"
if [ "$http_status" -eq 200 ]; then
echo "Smoke test passed with 200 OK."
else
echo "Smoke test failed with HTTP status: $http_status."
echo "Response body: $response_body"
exit 1
fi