Skip to content

Build & Deploy

Build & Deploy #292

name: Build & Deploy
on:
workflow_dispatch:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
paths:
- "app/**.*"
- "public/**.*"
- "package.json"
- "package-lock.json"
- "next.config.json"
- "tailwind.config.json"
- "postcss.config.json"
- "tsconfig.json"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: "20"
AZURE_WEBAPP_NAME: "ct-aoai-gpt-chat-demo"
AZURE_WEBAPP_PACKAGE_PATH: "."
AZURE_WEBAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
AZURE_OPENAI_BASE_PATH: ${{ secrets.AZURE_OPENAI_BASE_PATH }}}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_MODEL_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_MODEL_DEPLOYMENT }}
AZURE_OPENAI_GPT35_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_GPT35_DEPLOYMENT }}
AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }}
MS_TEAMS_WEBHOOK_URL: ${{ secrets.MS_TEAMS_WEBHOOK_URL }}
APP_DISPLAY_NAME: "GPT Chat Demo"
jobs:
build-and-deploy:
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
runs-on: ubuntu-latest
steps:
- name: 📤 Notify Teams
uses: mikesprague/teams-incoming-webhook-action@v1
with:
github-token: ${{ github.token }}
webhook-url: ${{ env.MS_TEAMS_WEBHOOK_URL }}
deploy-card: true
title: ${{ env.APP_DISPLAY_NAME }} Deployment Started
color: info
- name: 👷 Checkout Repo
uses: actions/checkout@v4
- name: 🏗️ Setup Node.js ${{ env.NODE_VERSION }} environment
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
check-latest: true
- name: ⚡ Cache node_modules and .next folder
id: cache
uses: actions/cache@v4
with:
path: |
~/.npm
${{ github.workspace }}/node_modules
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: ⬆️ Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: npm install --force
- name: 🛠️ Build app
shell: bash
run: npm run build
- name: 📦 Zip all files for deployment step
# IMPORTANT: .next is a hidden folder and will NOT be included in the zip unless we specify it
run: zip ${{ env.AZURE_WEBAPP_NAME}}.zip ./* .next -qr
- name: 🚀 Deploy to Azure App Service
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ env.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/${{ env.AZURE_WEBAPP_NAME}}.zip
type: zip
- name: ⚠️ Cancelled Notification
if: ${{ cancelled() }}
uses: mikesprague/teams-incoming-webhook-action@v1
with:
github-token: ${{ github.token }}
webhook-url: ${{ env.MS_TEAMS_WEBHOOK_URL }}
deploy-card: true
title: ${{ env.APP_DISPLAY_NAME }} Deployment Cancelled
color: warning
- name: ⛔ Failure Notification
if: ${{ failure() }}
uses: mikesprague/teams-incoming-webhook-action@v1
with:
github-token: ${{ github.token }}
webhook-url: ${{ env.MS_TEAMS_WEBHOOK_URL }}
deploy-card: true
title: ${{ env.APP_DISPLAY_NAME }} Deployment Failed
color: failure
- name: 🎉 Success Notification
if: ${{ success() }}
uses: mikesprague/teams-incoming-webhook-action@v1
with:
github-token: ${{ github.token }}
webhook-url: ${{ env.MS_TEAMS_WEBHOOK_URL }}
deploy-card: true
title: ${{ env.APP_DISPLAY_NAME }} Deployment Successful
color: success