Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Demo PR for using CircleCI to continuously deploy to Vercel Now #50

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions .circleci/config.ch4.yml

This file was deleted.

85 changes: 0 additions & 85 deletions .circleci/config.ch9.yml

This file was deleted.

215 changes: 49 additions & 166 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,42 @@
version: 2.1
orbs:
coveralls: coveralls/coveralls@1.0.4
commands:
install:
description: 'Install project dependencies'
parameters:
warm-cache:
type: boolean
default: false
jobs:
build:
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- node_modules-{{ checksum "package-lock.json" }}
- when:
condition: << parameters.warm-cache >>
steps:
- run: npm install
# Pre-build Angular modules
- run: npx ngcc --properties es2015 --async false # async false is temp CI build fix
# force update the webdriver, so it runs with latest version of Chrome
- run: cd ./node_modules/protractor && npm i webdriver-manager@latest
- save_cache:
key: node_modules-{{ checksum "package-lock.json" }}
paths:
- node_modules
lint:
description: 'Check for code style and linting errors'
steps:
- v1-dependencies-{{ checksum "package-lock.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: npm ci

# force update the webdriver, so it runs with latest version of Chrome
- run: cd ./node_modules/protractor && npm i webdriver-manager@latest

# because we use "npm ci" to install NPM dependencies
# we cache "~/.npm" folder
- save_cache:
paths:
- ~/.npm
key: v1-dependencies-{{ checksum "package-lock.json" }}

- run: npm run style
- run: npm run lint
build_and_test:
description: 'Build command that accepts Angular project name as parameter'
parameters:
project:
type: string
default: 'local-weather-app'
run-tests:
type: boolean
default: true
steps:
- run: npx ng build --prod --project << parameters.project >>
- when:
condition: << parameters.run-tests >>
steps:
- run: npx ng test --code-coverage --watch=false --project << parameters.project >>
- run: npx ng e2e << parameters.project >>
store:
description: 'Stores build_and_test artifacts'
parameters:
project:
type: string
default: 'local-weather-app'
steps:

- run: npx ng build ch6 --prod
- run: npx ng test --watch=false --project ch6
- run: npx ng e2e --project ch6

- store_test_results:
path: ./test_results
- store_artifacts:
path: ./coverage

# upload coverage report to coveralls for readme badge support
# requires config.yml version 2.1 and orbs: coveralls: coveralls/coveralls@1.0.4
# requires coveralls account and token named COVERALLS_REPO_TOKEN specific to repo to be stored in CircleCI
- coveralls/upload

- run:
name: Tar & Gzip compiled app
command: tar zcf dist.tar.gz dist/<< parameters.project >>
command: tar zcf dist.tar.gz dist/ch6
- store_artifacts:
path: dist.tar.gz

Expand All @@ -74,127 +45,39 @@ commands:
command: |
set -exu
mkdir -p /tmp/workspace/dist
mv dist/<< parameters.project >> /tmp/workspace/dist/
mv dist/ch6 /tmp/workspace/dist/
- persist_to_workspace:
root: /tmp/workspace
paths:
- dist/<< parameters.project >>
deploy_now:
description: 'Deploys project to Zeit Now --> https://now.sh'
parameters:
project:
type: string
default: 'local-weather-app'
steps:
- attach_workspace:
at: /tmp/workspace
- run: npx now --token $NOW_TOKEN --platform-version 2 --prod /tmp/workspace/dist/<< parameters.project >> --confirm
jobs:
initialize:
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install:
warm-cache: true
default:
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- lint
- build_and_test
- store
- dist/ch6
deploy:
docker:
- image: circleci/node:lts
working_directory: ~/repo
steps:
- deploy_now
- attach_workspace:
at: /tmp/workspace
- run: npx now --token $NOW_TOKEN --platform-version 2 --prod /tmp/workspace/dist/ch6 --confirm

ch2: # this job is only here to verify sample code from the book, remove it in your own projects
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- build_and_test:
project: 'ch2'
ch3: # this job is only here to verify sample code from the book, remove it in your own projects
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- build_and_test:
project: 'ch3'
run-tests: false
ch4: # this job is only here to verify sample code from the book, remove it in your own projects
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- build_and_test:
project: 'ch4'
ch5: # this job is only here to verify sample code from the book, remove it in your own projects
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- build_and_test:
project: 'ch5'
ch6: # this job is only here to verify sample code from the book, remove it in your own projects
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- build_and_test:
project: 'ch6'
ch12: # this job is only here to verify sample code from the book, remove it in your own projects
docker:
- image: circleci/node:lts-browsers
working_directory: ~/repo
steps:
- install
- build_and_test:
project: 'ch12'
workflows:
version: 2
build-test-and-approval-deploy:
build-test-and-deploy:
jobs:
- initialize
- default:
requires:
- initialize
- ch2: # this job is only here to verify sample code from the book, remove it in your own projects
requires:
- initialize
- ch3: # this job is only here to verify sample code from the book, remove it in your own projects
requires:
- initialize
- ch4: # this job is only here to verify sample code from the book, remove it in your own projects
requires:
- initialize
- ch5: # this job is only here to verify sample code from the book, remove it in your own projects
requires:
- initialize
- ch6: # this job is only here to verify sample code from the book, remove it in your own projects
requires:
- initialize
# - ch12: # this job is only here to verify sample code from the book, remove it in your own projects
# requires:
# - initialize
- hold:
type: approval
requires:
- default
filters:
branches:
only: master
- build
- deploy:
requires:
- hold
- build
# Example of conditional deployments and branch filtering
# build-test-and-approval-deploy:
# jobs:
# - build
# - hold:
# type: approval
# requires:
# - build
# filters:
# branches:
# only: master
# - deploy:
# requires:
# - hold