Skip to content
name: Build and deploy Node.js app to Azure Web App - lotr-backend
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Frontend build steps
- name: Set up Node.js version for frontend
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: npm install for frontend
run: npm install
working-directory: frontend
# Include whenver tests are added
# - name: npm run test for frontend
# run: npm run test --if-present
# working-directory: frontend
- name: npm run build for frontend
run: npm run build
working-directory: frontend
# working-directory: frontend
# with:
# node-version: '18.x'
# app_location: "/frontend"
# output_location: "build"
# Copy build directory to backend
- name: Copy frontend build to backend
run: cp -R ./frontend/build/* ./backend/__BUILD/
# Backend build steps
- name: Set up Node.js version for backend
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: npm install, build, and test for backend
run: |
npm install
npm run test --if-present
working-directory: ./backend
- name: Zip artifact for deployment
run: zip release.zip ./* -r
working-directory: ./backend
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: node-app
path: backend/release.zip
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: node-app
- name: Unzip artifact for deployment
run: unzip release.zip
- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'lotr-backend'
slot-name: 'Production'
package: .
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_755D03D3D66E4CFEA1B7360C17082E2D }}