-
Notifications
You must be signed in to change notification settings - Fork 26
198 lines (172 loc) · 7.32 KB
/
web-build.yml
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
##################################################################################
# Configuration
# These variables will be populated from environment
##################################################################################
env:
DEPLOYMENT_REPO: ${{vars.DEPLOYMENT_REPO}}
DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}}
DEPLOYMENT_REPO_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}}
##################################################################################
# Main Code
##################################################################################
name: Web Build
# Only keep one active build per ref (e.g. pr branch, push branch, triggering workflow ref)
concurrency:
group: web-build-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_call:
#############################################################################
# Inputs
# Optional variables to configure from parent workflow via workflow_call
#############################################################################
inputs:
deployment-env:
description: Name of environment to load deployment variables from
type: string
required: true
default: debug
build-flags:
description: Additional flags to pass to build command (e.g. base-href)
type: string
default: ""
branch:
description: Name of branch to build (defaults to event trigger sha)
type: string
default: ""
include-tests:
description: "Specify whether to include running workspace lint and test before build"
type: boolean
default: false
lfs:
description: Enable git lfs to include download of all binary assets (user-facing deployments)
type: boolean
default: true
skip-upload:
description: "Specify whether to skip uploading build artifact at end"
type: boolean
default: false
#############################################################################
# Outputs
# Variables available to parent workflows following workflow_call
#############################################################################
outputs:
DEPLOYMENT_NAME:
description: "Name of the deployment built"
value: ${{ jobs.configure_build.outputs.DEPLOYMENT_NAME }}
GIT_SHA:
description: "Git SHA of build head"
value: ${{ jobs.configure_build.outputs.GIT_SHA }}
jobs:
configure_build:
environment: ${{inputs.deployment-env}}
outputs:
DEPLOYMENT_NAME: ${{ steps.populate.outputs.DEPLOYMENT_NAME }}
GIT_SHA: ${{ steps.populate.outputs.GIT_SHA }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{inputs.branch}}
# Output determined environment name alongside git SHA (for use in error logging)
- name: Populate Outputs
id: populate
run: |
echo "DEPLOYMENT_NAME=$DEPLOYMENT_NAME" >> $GITHUB_OUTPUT;
echo "GIT_SHA=$(git rev-parse --short=6 HEAD)" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: configure_build
environment: ${{needs.configure_build.outputs.DEPLOYMENT_NAME}}
env:
GIT_SHA: ${{ needs.configure_build.outputs.GIT_SHA }}
steps:
- uses: actions/checkout@v4
with:
lfs: ${{inputs.lfs}}
ref: ${{inputs.branch}}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
#############################################################################
# Node Modules
# Manually restore any previous cache to speed install
# As immutable install will not change cache only save new cache if not hit
# Uses fine-grained methods from https://github.com/actions/cache
#############################################################################
- uses: actions/cache/restore@v3
id: cache
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
run: yarn install --immutable
- uses: actions/cache/save@v3
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ./.yarn/cache
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('yarn.lock') }}
#############################################################################
# Prebuild
# Populate variables and set deployment configuration as required
# Exact population varies depending on whether is PR, release, dispatch etc.
#############################################################################
- name: Populate git sha
if: ${{env.GIT_SHA}}
run: echo "export const GIT_SHA = \"$GIT_SHA\";" > src/environments/sha.ts
- name: Import remote deployment
uses: actions/checkout@v4
with:
repository: ${{env.DEPLOYMENT_REPO}}
lfs: ${{inputs.lfs}}
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
# TODO - add support for specific branch/release
- name: Set deployment private key
if: ${{env.DEPLOYMENT_REPO_PRIVATE_KEY}}
run:
echo $DEPLOYMENT_REPO_PRIVATE_KEY > .idems_app/deployments/$DEPLOYMENT_NAME/encrypted/private.key
- name: Set deployment
run: yarn workflow deployment set ${{env.DEPLOYMENT_NAME}}
#############################################################################
# Build
# Run optional tests before building and uploading final build as artifact
# for use in other actions
#############################################################################
- name: Lint
if: ${{inputs.include-tests}}
run: yarn lint && yarn workspace api lint
# Ensure test xlsx files checked out
- name: Checkout test files
if: ${{ inputs.include-tests && !inputs.lfs }}
run: git lfs pull --include "packages/scripts/test/data/input/*"
- name: Test
if: ${{inputs.include-tests}}
run: yarn test:workspaces
- name: Build
run: yarn build ${{inputs.build-flags}}
env:
# Fix possible out-of-memory issues
NODE_OPTIONS: --max_old_space_size=6144
# Use github pages upload artifact action to compress and upload
- name: Upload artifact
if: ${{!inputs.skip-upload}}
uses: actions/[email protected]
with:
path: "www/"
name: www
##################################################################################
# Links
##################################################################################
# Create a reusable workflow to build deployment app
# https://colinsalmcorner.com/musings-on-reusable-workflows/
##################################################################################
# Notes
##################################################################################
# Alternative methods previously used:
# Git SHA
# GIT_SHA=`echo ${{github.event.pull_request.head.sha}} | cut -c1-6`
# Deployment name (https://www.linuxjournal.com/article/8919)
# DEPLOYMENT_NAME=${GITHUB_BASE_REF##*/}