Skip to content

Commit 8f843d2

Browse files
committed
chore: add script to install yarn dependencies
* Use frozen lockfile in build for reproducible builds * Do not install optional dependencies * Suppress interactive prompts in build
1 parent 91bf863 commit 8f843d2

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

.github/workflows/coder.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ jobs:
6060
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
6161

6262
- name: Install node_modules
63-
run: yarn install
64-
working-directory: site
63+
run: ./scripts/yarn_install.sh
6564

6665
- name: "yarn lint"
6766
run: yarn lint
@@ -108,8 +107,7 @@ jobs:
108107
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
109108

110109
- name: Install node_modules
111-
run: yarn install
112-
working-directory: site
110+
run: ./scripts/yarn_install.sh
113111

114112
- name: "make fmt"
115113
run: "make --output-sync -j fmt"
@@ -214,8 +212,8 @@ jobs:
214212
with:
215213
node-version: "14"
216214

217-
- run: yarn install
218-
working-directory: site
215+
- name: Install node_modules
216+
run: ./scripts/yarn_install.sh
219217

220218
- uses: actions/setup-go@v2
221219
with:
@@ -252,13 +250,15 @@ jobs:
252250
with:
253251
node-version: "14"
254252

255-
- run: yarn install
256-
working-directory: site
253+
- name: Install node_modules
254+
run: ./scripts/yarn_install.sh
257255

258-
- run: yarn build
256+
- name: Build frontend
257+
run: yarn build
259258
working-directory: site
260259

261-
- run: yarn storybook:build
260+
- name: Build Storybook
261+
run: yarn storybook:build
262262
working-directory: site
263263

264264
- run: yarn test:coverage

develop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function create_initial_user() {
2222
}
2323

2424
# Run yarn install, to make sure node_modules are ready to go
25-
yarn --cwd=./site install
25+
"$PROJECT_ROOT/scripts/yarn_install.sh"
2626

2727
# Do initial build - a dev build for coderd.
2828
# It's OK that we don't build the front-end before - because the front-end

scripts/yarn_install.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# Run "yarn install" with flags appropriate to the environment
4+
# (local development vs build system)
5+
#
6+
# Usage: yarn_install.sh [optional extra flags]
7+
8+
set -euo pipefail
9+
10+
PROJECT_ROOT=$(git rev-parse --show-toplevel)
11+
cd "$PROJECT_ROOT/site"
12+
13+
yarn_flags=(
14+
# Do not execute install scripts
15+
# TODO: check if build works properly with this enabled
16+
# --ignore-scripts
17+
18+
# Check if existing node_modules are valid
19+
# TODO: determine if this is necessary
20+
# --check-files
21+
22+
# Do not install optional dependencies
23+
--ignore-optional
24+
)
25+
26+
if [ -n "${CI:-}" ]; then
27+
yarn_flags+=(
28+
# Install dependencies from lockfile, ensuring builds are fully
29+
# reproducible
30+
--frozen-lockfile
31+
# Suppress progress information
32+
--silent
33+
# Disable interactive prompts for build
34+
--non-interactive
35+
)
36+
fi
37+
38+
# Append whatever is specified on the command line
39+
yarn_flags+=("$@")
40+
41+
echo "+ yarn install ${yarn_flags[*]}"
42+
yarn install "${yarn_flags[@]}"

0 commit comments

Comments
 (0)