-
Notifications
You must be signed in to change notification settings - Fork 2
117 lines (107 loc) · 3.59 KB
/
Copy pathbuild-and-deploy.yml
File metadata and controls
117 lines (107 loc) · 3.59 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
# 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: AGPL-3.0-or-later
name: Build and Deploy
# Default to dev when running automatically (see also "env" below)
run-name: Building and (optionally) deploying 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 site'
required: true
default: true
type: boolean
env:
# Read the target environment from workflow_dispatch inputs, or default to dev
ENVIRONMENT: ${{ inputs.ENVIRONMENT || 'dev' }}
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
# Setup
- name: Print environment
run: echo "Environment = $ENVIRONMENT"
- uses: actions/checkout@v4.2.2
with:
persist-credentials: false
- name: Set up build
uses: ./.github/actions/build-setup
with:
CONFIG: ${{ vars[format('{0}_CONFIG', env.ENVIRONMENT)] }}
NPMRC_FILE: ${{ secrets.NPMRC_FILE }}
# Build
- name: Build the registration website
run: npm run build
- name: Organize the folder structure for the output
run: |
mkdir web-build
cp -r dist web-build
- name: Archive build output
uses: actions/upload-artifact@v4.6.2
with:
name: web-build
path: web-build
deploy:
needs: build
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@v4.2.2
with:
persist-credentials: false
- name: Download build artifact
uses: actions/download-artifact@v4.3.0
with:
name: web-build
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 `dist`
run: ls -la dist
- name: Ensure $ENVIRONMENT is defined to avoid destructive mirroring on the server
run: |
echo "Environment = $ENVIRONMENT; target folder for upload is ./registration/${ENVIRONMENT}/"
if [ -z "$ENVIRONMENT" ]; then exit 1; fi
shell: bash
# 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
working-directory: dist
run: >
lftp -c "
set cmd:fail-exit yes;
open $FTP_HOST
user $FTP_USER $FTP_PASSWORD;
mirror --reverse --delete --parallel=10 --verbose ./ ./registration/${ENVIRONMENT}/;
ls -la ./registration/${ENVIRONMENT};
bye
"
env:
FTP_HOST: ${{ vars.FTP_HOST }}
FTP_PASSWORD: ${{ secrets.FTP_PASSWORD }}
FTP_USER: ${{ vars.FTP_USER }}