-
Notifications
You must be signed in to change notification settings - Fork 3
140 lines (130 loc) · 5.04 KB
/
build-deploy-web.yml
File metadata and controls
140 lines (130 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# SPDX-FileCopyrightText: Copyright (C) 2025 Opal Health Informatics Group at the Research Institute of the McGill University Health Centre <john.kildea@mcgill.ca>
#
# 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:
environment:
# We want to keep environment variables per environment
# Pull requests need access to CONFIG_JS and GOOGLE_SERVICES
# Use a dedicated preview environment for pull requests
name: |-
${{ case(
inputs.ENVIRONMENT != '', inputs.ENVIRONMENT,
github.event_name == 'pull_request', 'preview',
'dev'
) }}
deployment: false
runs-on: ubuntu-latest
steps:
# Setup
- name: Print environment
run: echo "Environment = $ENVIRONMENT"
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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.CONFIG_JS }}
ENV_GOOGLE_SERVICES: ${{ vars.GOOGLE_SERVICES }}
# 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/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: web-app
path: web-app
deploy-web:
environment:
name: ${{ inputs.ENVIRONMENT || 'dev' }}
deployment: false
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/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
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: ${{ secrets.FTP_HOST }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
FTP_USER: ${{ secrets.FTP_USER }}