Skip to content

Instantly share code, notes, and snippets.

@robwierzbowski
Created November 30, 2021 17:21
Show Gist options
  • Save robwierzbowski/d31435fb12c6ad9fb9a22cc4791f14b9 to your computer and use it in GitHub Desktop.
Save robwierzbowski/d31435fb12c6ad9fb9a22cc4791f14b9 to your computer and use it in GitHub Desktop.
version: 2.1
###################
# SHARED COMMANDS #
###################
cache_key: &cache_key dependency-cache-{{ checksum "yarn.lock" }}
# Docker build environment images
build_env: &build_env
image: cimg/node:current-browsers
# Settings common to each job
# TODO: Can we add checkout_code, run_install_nvm_and_node, restore_cache,
# install_deps, and save_cache to this defaults array?
job_defaults: &job_defaults
working_directory: ~/event-reporter
docker:
- *build_env
checkout_code: &checkout_code
checkout:
# After checkout, rebase on top of main. By default, PRs are not rebased on top of
# the parent branch (usually main), which we want. See https://discuss.circleci.com/t/1662
# TODO: VS Code throws a property is not allowed error for post. Determine
# if it can be renamed.
post: git pull --ff-only origin "refs/pull/${CIRCLE_PULL_REQUEST//*pull\//}/merge"
run_install_nvm_and_node: &run_install_nvm_and_node
run:
name: Install and initialize NVM
command: |
# https://discuss.circleci.com/t/how-to-change-node-version-in-circleci-2-0/17455
set +e # https://github.com/creationix/nvm/issues/993#issue-130348877
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
# Use the .nvmrc node version in tests. `nvm alias default` persists node
# version across shells. `use` and `alias` must be on the same line so
# they're executed in the same shell.
echo 'nvm install' >> $BASH_ENV
echo 'nvm alias default $(node --version)' >> $BASH_ENV
restore_cache: &restore_cache
restore_cache:
key: *cache_key
save_cache: &save_cache
save_cache:
key: *cache_key
paths:
- ./node_modules
- ./.cache/yarn
install_deps: &install_deps
run:
name: Install node module dependencies
command: yarn install --frozen-lockfile
commands:
setup_environment:
description: Set up code, runtime, and dependencies
steps:
- *checkout_code
- *run_install_nvm_and_node
- *restore_cache
- *install_deps
- *save_cache
jobs:
lint:
<<: *job_defaults
steps:
- setup_environment
- run:
name: Run lint
command: yarn lint:js
type_check:
<<: *job_defaults
steps:
- setup_environment
- run:
name: Check types
command: yarn type-check
test:
<<: *job_defaults
steps:
- setup_environment
- run:
name: Run tests
command: yarn test
release:
<<: *job_defaults
steps:
- setup_environment
- run:
name: Release @stitch-fix/event-reporter
command: npx semantic-release
deploy_preview:
<<: *job_defaults
steps:
- setup_environment
- run:
name: Deploy Preview
command: |
yarn storybook:build
mkdir storybook-static/.circleci
cp .circleci/no-op.yml storybook-static/.circleci/config.yml
npx gh-pages --dist storybook-static --dotfiles --branch "$CIRCLE_BRANCH-site" --user "CI Auto Deploy <[email protected]>"
workflows:
version: 2
on_commit:
jobs:
- lint:
context: org-global
- type_check:
context: org-global
- test:
context: org-global
- deploy_preview:
context: org-global
requires:
- lint
- type_check
- test
# The release job is run on every branch, but `semantic-release`
# only deploys to npm on the valid release branches. It uses
# the `NPM_TOKEN` from the global context
- release:
context: org-global
requires:
- lint
- type_check
- test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment