Skip to content

Commit

Permalink
Using workflows and greenkeeper-lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dolezel committed Jun 22, 2018
1 parent b0132c5 commit 2cef5a6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 38 deletions.
122 changes: 95 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
version: 2

job_common: &job_common
docker:
- image: circleci/node:6

save: &save
save_cache:
key: code-{{ .Revision }}
paths:
- .
- ".git"

restore: &restore
restore_cache:
key: code-{{ .Revision }}

jobs:
build:
docker:
- image: circleci/node:6
environment:
- NODE_ENV=test
- DATABASE_URL_POSTGRES=postgres://ubuntu@localhost:5432/circle_test
- DATABASE_URL_COCKROACH=postgresql://root@localhost:26257/circle_test
- image: postgres:10.4-alpine
environment:
- POSTGRES_USER=ubuntu
- POSTGRES_DB=circle_test
- image: cockroachdb/cockroach:v1.1.8
command: ['start', '--insecure', '--host=localhost']
steps:
- checkout
- run:
install:
<<: *job_common
steps:
- checkout
- run:
name: update-npm
command: |
mkdir ~/.npm-global
Expand All @@ -24,21 +29,84 @@ jobs:
echo 'export PATH=~/.npm-global/bin:$PATH' >> $BASH_ENV
source $BASH_ENV
npm install -g [email protected]
- restore_cache:
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: install-npm
command: npm ci
- save_cache:
- run:
name: install-greenkeeper
command: |
npm install -g greenkeeper-lockfile
greenkeeper-lockfile-update
- run: npm i
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: lint
command: npm run lint
- run:
- <<: *save
lint:
<<: *job_common
steps:
- <<: *restore
- run: npm run lint
test:
<<: *job_common
steps:
- <<: *restore
- run: npm test
test-pg:
<<: *job_common
docker:
- image: postgres:10.4-alpine
environment:
- POSTGRES_USER=ubuntu
- POSTGRES_DB=circle_test
steps:
- <<: *restore
- run:
name: test
environment:
- DATABASE_URL=postgres://ubuntu@localhost:5432/circle_test
command: npm run migrate up -- -m test/migrations && npm run migrate down 0 -- -m test/migrations --timestamps
test-cocroach:
<<: *job_common
docker:
- image: cockroachdb/cockroach:v1.1.8
command: ['start', '--insecure', '--host=localhost']
steps:
- <<: *restore
- run:
name: create-cockroach-db
command: node -e '(new require("pg").Pool({connectionString:process.env.DATABASE_URL_COCKROACH})).query("CREATE DATABASE circle_test").then(function(){process.exit(0)})'
- run:
- run:
name: test
command: npm test
environment:
- DATABASE_URL=postgresql://root@localhost:26257/circle_test
command: npm run migrate up -- -m test/cockroach -s '' --migrations-schema circle_test --no-lock && npm run migrate down 0 -- -m test/cockroach -s '' --migrations-schema circle_test --no-lock --timestamps
- run: greenkeeper-lockfile-upload
finish:
<<: *job_common
steps:
- <<: *restore
- run: greenkeeper-lockfile-upload

workflows:
version: 2
main_workflow:
jobs:
- install
- lint:
requires:
- install
- test:
requires:
- install
- test-pg:
requires:
- install
- test-cocroach:
requires:
- install
- finish:
requires:
- test
- test-pg
- test-cocroach
12 changes: 1 addition & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,8 @@
"scripts": {
"precommit": "lint-staged",
"compile": "babel lib/ -d dist/ && cp lib/migration-template.* dist/",
"test:mocha": "cross-env NODE_ENV=test mocha --opts ./mocha.opts test",
"test": "cross-env NODE_ENV=test mocha --opts ./mocha.opts test",
"migrate": "babel-node bin/node-pg-migrate",
"migrate:postgres":
"DATABASE_URL=$DATABASE_URL_POSTGRES npm run migrate -- -m test/migrations",
"migrate:cockroach":
"DATABASE_URL=$DATABASE_URL_COCKROACH npm run migrate -- -m test/cockroach -s '' --migrations-schema circle_test --no-lock",
"test:postgres":
"npm run migrate:postgres up && npm run migrate:postgres down 0 -- --timestamps",
"test:cockroach":
"npm run migrate:cockroach up && npm run migrate:cockroach down 0 -- --timestamp",
"test":
"npm run test:mocha && npm run test:postgres && npm run test:cockroach",
"lint": "eslint -c eslintrc.js . bin/*",
"lintfix":
"npm run lint -- --fix && prettier --write *.json *.md docs/*.md",
Expand Down

0 comments on commit 2cef5a6

Please sign in to comment.