Skip to content

Commit

Permalink
chore: add script to install yarn dependencies
Browse files Browse the repository at this point in the history
* Use frozen lockfile in build for reproducible builds
* Do not install optional dependencies
* Suppress interactive prompts in build
  • Loading branch information
jawnsy committed Feb 20, 2022
1 parent 91bf863 commit 8f843d2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ jobs:
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}

- name: Install node_modules
run: yarn install
working-directory: site
run: ./scripts/yarn_install.sh

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

- name: Install node_modules
run: yarn install
working-directory: site
run: ./scripts/yarn_install.sh

- name: "make fmt"
run: "make --output-sync -j fmt"
Expand Down Expand Up @@ -214,8 +212,8 @@ jobs:
with:
node-version: "14"

- run: yarn install
working-directory: site
- name: Install node_modules
run: ./scripts/yarn_install.sh

- uses: actions/setup-go@v2
with:
Expand Down Expand Up @@ -252,13 +250,15 @@ jobs:
with:
node-version: "14"

- run: yarn install
working-directory: site
- name: Install node_modules
run: ./scripts/yarn_install.sh

- run: yarn build
- name: Build frontend
run: yarn build
working-directory: site

- run: yarn storybook:build
- name: Build Storybook
run: yarn storybook:build
working-directory: site

- run: yarn test:coverage
Expand Down
2 changes: 1 addition & 1 deletion develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function create_initial_user() {
}

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

# Do initial build - a dev build for coderd.
# It's OK that we don't build the front-end before - because the front-end
Expand Down
42 changes: 42 additions & 0 deletions scripts/yarn_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
#
# Run "yarn install" with flags appropriate to the environment
# (local development vs build system)
#
# Usage: yarn_install.sh [optional extra flags]

set -euo pipefail

PROJECT_ROOT=$(git rev-parse --show-toplevel)
cd "$PROJECT_ROOT/site"

yarn_flags=(
# Do not execute install scripts
# TODO: check if build works properly with this enabled
# --ignore-scripts

# Check if existing node_modules are valid
# TODO: determine if this is necessary
# --check-files

# Do not install optional dependencies
--ignore-optional
)

if [ -n "${CI:-}" ]; then
yarn_flags+=(
# Install dependencies from lockfile, ensuring builds are fully
# reproducible
--frozen-lockfile
# Suppress progress information
--silent
# Disable interactive prompts for build
--non-interactive
)
fi

# Append whatever is specified on the command line
yarn_flags+=("$@")

echo "+ yarn install ${yarn_flags[*]}"
yarn install "${yarn_flags[@]}"

0 comments on commit 8f843d2

Please sign in to comment.