Skip to content

Commit

Permalink
build: transition to circle 2 and cache test fixtures in CI (googleap…
Browse files Browse the repository at this point in the history
…is#634)

PR-URL: googleapis#634

This change migrates Linux-based CI completely to CircleCI (2.0), and adds caching of `node_modules` (invalidated when either `package-lock.json` or `package.json` change) and `build/test/plugins/fixtures` (invalidated when `test/fixtures/plugin-fixtures.json` changes) to both CircleCI and AppVeyor. This results in a 5-8 min speedup for each test run across CircleCI and AppVeyor.

#### `delete all plugin fixtures`
- Removes all directories in [`test/plugins/fixtures`](https://github.com/GoogleCloudPlatform/cloud-trace-nodejs/tree/v2.4.0/test/plugins/fixtures) in favor of [`plugin-fixtures.json`](https://github.com/kjin/cloud-trace-nodejs/blob/circle-2/test/fixtures/plugin-fixtures.json)
  - This is beneficial because CIs generally invalidate caches when a certain file is changed. Coalescing all the information found in the plugin fixtures makes this a lot easier.
#### `fix CI failures`
- Fixes two CI failures introduced with:
  - Node v9
  - TypeScript v???
#### `modify scripts`
- Names exported functions in scripts rather than using `export default`
- Removes some pre-requisite steps in npm scripts for atomicity
- Adds `encrypt-service-account-credentials` script to regenerate encrypted system test credentials (for future use; this is meant to be used manually and infrequently)
- Modifies `init-test-fixtures` script to generate plugin fixtures based off [`plugin-fixtures.json`](https://github.com/kjin/cloud-trace-nodejs/blob/circle-2/test/fixtures/plugin-fixtures.json) file
- Adds `plugin-fixtures.json`
- Changes code coverage reporter to codecov
#### `update system test key file`
- As Travis (rightfully) doesn't allow me to access encryption details for system test credentials, this commit is the result of running `encrypt-service-account-credentials` to regenerate a new encrypted key file (new encryption details have been added to CircleCI as env vars)
#### `update CI configurations`
- Deletes `.travis.yml` and `circle.yml`
- Adds `.circleci/config.yml` (w/ caching)
- Modifies `appveyor.yml` to add caching and change list of commands to run
#### `update package-lock.json`
- Self-explanatory
  • Loading branch information
kjin authored Jan 9, 2018
1 parent 61f620d commit ea3b26e
Show file tree
Hide file tree
Showing 102 changed files with 898 additions and 655 deletions.
121 changes: 121 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
# Constant values.

node_modules_cache_key: &node_modules_cache_key node-modules-cache-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "package.json" }}-{{ checksum "package-lock.json" }}
test_fixtures_cache_key: &test_fixtures_cache_key test-fixtures-cache-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "test/fixtures/plugin-fixtures.json" }}
test_env: &test_env
GCLOUD_PROJECT: 0
GCLOUD_TRACE_NEW_CONTEXT: 1

# Unit test workflow.

unit_tests: &unit_tests
steps:
- checkout
- run:
name: Configure npm to allow running scripts as root
command: npm config set unsafe-perm true
- restore_cache:
key: *node_modules_cache_key
- run:
name: Install modules and dependencies
command: npm install
- save_cache:
key: *node_modules_cache_key
paths:
- node_modules
- run:
name: Check code style and linting
command: npm run check
- run:
name: Compile code
command: npm run compile
- restore_cache:
key: *test_fixtures_cache_key
- run:
name: Install test fixtures
command: npm run init-test-fixtures
- save_cache:
key: *test_fixtures_cache_key
paths:
- build/test/plugins/fixtures
- run:
name: Run unit tests with code coverage
command: npm run coverage
- run:
name: Verify that the package installs OK
command: npm run check-install
- run:
name: Run system tests (skipped for PRs)
command: npm run system-test

# Services needed for unit tests.

mongo_service: &mongo_service
image: mongo

redis_service: &redis_service
image: redis

postgres_service: &postgres_service
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: Password12!
POSTGRES_DB: test

mysql_service: &mysql_service
image: mysql
environment:
MYSQL_ROOT_PASSWORD: Password12!
MYSQL_DATABASE: test

# Main configuration.

version: 2.0
workflows:
version: 2
tests:
jobs:
- node4
- node6
- node8
- node9

jobs:
node4:
docker:
- image: node:4
environment: *test_env
- *mongo_service
- *redis_service
- *postgres_service
- *mysql_service
<<: *unit_tests
node6:
docker:
- image: node:6
environment: *test_env
- *mongo_service
- *redis_service
- *postgres_service
- *mysql_service
<<: *unit_tests
node8:
docker:
- image: node:8
environment: *test_env
- *mongo_service
- *redis_service
- *postgres_service
- *mysql_service
<<: *unit_tests
node9:
docker:
- image: node:9
environment: *test_env
- *mongo_service
- *redis_service
- *postgres_service
- *mysql_service
<<: *unit_tests
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

14 changes: 12 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ environment:
- nodejs_version: "6"
- nodejs_version: "8"

cache:
- node_modules -> package-lock.json, package.json
- build\test\plugins\fixtures -> test\fixtures\plugin-fixtures.json

services:
- mongodb
- mysql
Expand All @@ -19,8 +23,6 @@ install:
- nuget install redis-64 -excludeversion
- redis-64\tools\redis-server.exe --service-install
- redis-64\tools\redis-server.exe --service-start
# install modules
- npm install
- SET GCLOUD_PROJECT=0
- SET GCLOUD_TRACE_NEW_CONTEXT=1

Expand All @@ -34,8 +36,16 @@ before_test:

# Post-install test scripts.
test_script:
# install modules
- npm install
# check code style and linting
- npm run check
# compile the code
- npm run compile
# check that installing this module is OK
- npm run check-install
# initialize test fixtures
- npm run init-test-fixtures
# run tests
- npm run test

Expand Down
8 changes: 0 additions & 8 deletions circle.yml

This file was deleted.

Binary file removed node-team-test-d0b0be11c23d.json.enc
Binary file not shown.
Binary file added node-team-test-de480e4f9023.json.enc
Binary file not shown.
Loading

0 comments on commit ea3b26e

Please sign in to comment.