Skip to content

Building the web app for dev #364

Building the web app for dev

Building the web app for dev #364

# SPDX-FileCopyrightText: Copyright (C) 2025 Opal Health Informatics Group at the Research Institute of the McGill University Health Centre <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
name: Build and Deploy Web
# Default to dev when running automatically (see also "env" below)
run-name: Building ${{ inputs.DEPLOY && 'and deploying ' || '' }}the web app for ${{ inputs.ENVIRONMENT || 'dev' }}
on:
# When pushing to main, automatically build for dev
push:
branches:
- main
# When updating a pull request or adding a pull request to a merge queue, automatically build for dev
pull_request:
merge_group:
# Offer a manual interface to build for all other environments as needed
workflow_dispatch:
inputs:
ENVIRONMENT:
description: 'Environment in which to build'
type: choice
required: true
default: 'dev'
options:
- dev
- prod
DEPLOY:
description: 'Deploy the resulting web app to the web server'
required: true
default: false
type: boolean
BUILD_NUMBER_OVERRIDE:
description: "[Should only be used for prod; otherwise leave blank] A specific build number to use, to match the value released to the app stores."
required: false
type: number
env:
# Read the target environment from workflow_dispatch inputs, or default to dev
ENVIRONMENT: ${{ inputs.ENVIRONMENT || 'dev' }}
permissions:
contents: read
jobs:
build-web:
runs-on: ubuntu-latest
steps:
# Setup
- name: Print environment
run: echo "Environment = $ENVIRONMENT"
- uses: actions/[email protected]
with:
persist-credentials: false
# Fetch part of the commit history and its tags, in order to calculate the build number in `build-setup`
fetch-depth: ${{ vars.FETCH_DEPTH }}
fetch-tags: true
- name: Set up build
uses: ./.github/actions/build-setup
with:
# Should only have a value when building for prod and also releasing the app to the stores; otherwise, will be undefined and the build number will be calculated
BUILD_NUMBER_OVERRIDE: ${{ inputs.BUILD_NUMBER_OVERRIDE }}
ENV_CONFIG_JS: ${{ vars[format('{0}_CONFIG_JS', env.ENVIRONMENT)] }}
ENV_GOOGLE_SERVICES: ${{ vars[format('{0}_GOOGLE_SERVICES', env.ENVIRONMENT)] }}
# Build for web
- name: Build the web app
run: npm run build:web --env="$ENVIRONMENT"
- name: Organize the folder structure for the output
run: |
mkdir web-app
cp -r www web-app
- name: Archive build output
uses: actions/[email protected]
with:
name: web-app
path: web-app
deploy-web:
needs: build-web
runs-on: ubuntu-latest
# Deploy manually via inputs, or automatically (to dev) when building on main
if: ${{ inputs.DEPLOY || github.ref_name == 'main' }}
steps:
# Setup
- uses: actions/[email protected]
with:
persist-credentials: false
- name: Ensure $ENVIRONMENT is defined to avoid destructive mirroring on the server
run: |
echo "Environment = $ENVIRONMENT; target folder for upload is ./app/${ENVIRONMENT}/"
if [ -z "$ENVIRONMENT" ]; then exit 1; fi
shell: bash
- name: Download web build artifact (`www`)
uses: actions/[email protected]
with:
name: web-app
run-id: ${{ github.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install lftp
run: |
sudo apt-get install lftp
lftp --version
- name: List contents of `www`
run: ls -la www
# Upload web files
# See: https://www.cyberciti.biz/faq/lftp-mirror-example/
# See: https://linuxconfig.org/lftp-tutorial-on-linux-with-examples
- name: Upload files using lftp
run: >
lftp -c "
set cmd:fail-exit yes;
open $FTP_HOST
user $FTP_USER $FTP_PASSWORD;
mirror --exclude='app' --exclude='content' --reverse --delete --verbose ./static/landingpage/ ./app/${ENVIRONMENT}/;
mirror --reverse --delete --use-pget-n=10 --verbose ./www/ ./app/${ENVIRONMENT}/app/;
ls -la app/${ENVIRONMENT};
bye
"
env:
FTP_HOST: ${{ vars.FTP_HOST }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
FTP_USER: ${{ vars.FTP_USER }}