Merge pull request #141 from gitfrosh/beta #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy Express.js backend and React frontend as Azure Web App | |
on: | |
push: | |
paths-ignore: | |
- 'db/**' | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [21.x] | |
steps: | |
# Checkout project | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Setup Node | |
- name: Use Node.js ${{ matrix.node-version }} for frontend | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
# FRONTEND # | |
# Install Packages | |
- name: Install Dependencies for Frontend | |
run: npm ci | |
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 # | |
# Install Packages | |
- name: Install Dependencies for Backend | |
run: | | |
npm ci | |
working-directory: ./backend | |
# Run Jest tests | |
- name: Run Tests | |
working-directory: ./backend | |
run: npm run test --if-present | |
# Compile TS | |
- name: Compile TS | |
working-directory: ./backend | |
run: npm run compile | |
- 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 }} |