diff --git a/.circleci/config.yml b/.circleci/config.yml index 9c77986..d9f5d7c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,70 +1,169 @@ ---- -release_tags: &release_tags - tags: - only: /^v\d+(\.\d+){2}(-.*)?$/ - -unit_tests: &unit_tests - steps: - - checkout - - run: npm install - - run: npm run test-only - - run: npm run codecov - -version: 2.0 +version: 2 workflows: version: 2 tests: - jobs: + jobs: &workflow_jobs - node6: - filters: *release_tags + filters: &all_commits + tags: + only: /.*/ - node8: - filters: *release_tags + filters: *all_commits - node10: - filters: *release_tags + filters: *all_commits - lint: requires: - node6 - node8 - node10 - filters: *release_tags - - publish_npm: + filters: *all_commits + - docs: + requires: + - node6 + - node8 + - node10 + filters: *all_commits + - system_tests: requires: - lint + - docs + filters: &master_and_releases + branches: + only: master + tags: &releases + only: '/^v[\d.]+$/' + - sample_tests: + requires: + - lint + - docs + filters: *master_and_releases + - publish_npm: + requires: + - system_tests + - sample_tests filters: branches: ignore: /.*/ - <<: *release_tags - + tags: *releases + nightly: + triggers: + - schedule: + cron: 0 7 * * * + filters: + branches: + only: master + jobs: *workflow_jobs jobs: node6: docker: - - image: node:6 + - image: 'node:6' user: node - <<: *unit_tests + steps: &unit_tests_steps + - checkout + - run: &npm_install_and_link + name: Install and link the module + command: |- + mkdir -p /home/node/.npm-global + npm install + environment: + NPM_CONFIG_PREFIX: /home/node/.npm-global + - run: npm test + - run: node_modules/.bin/codecov + node8: docker: - - image: node:8 + - image: 'node:8' user: node - <<: *unit_tests + steps: *unit_tests_steps node10: docker: - - image: node:10 + - image: 'node:10' user: node - <<: *unit_tests + steps: *unit_tests_steps lint: docker: - - image: node:8 + - image: 'node:8' + user: node + steps: + - checkout + - run: *npm_install_and_link + - run: &samples_npm_install_and_link + name: Link the module being tested to the samples. + command: | + cd samples/ + npm link ../ + npm install + environment: + NPM_CONFIG_PREFIX: /home/node/.npm-global + - run: + name: Run linting. + command: npm run lint + environment: + NPM_CONFIG_PREFIX: /home/node/.npm-global + docs: + docker: + - image: 'node:8' + user: node + steps: + - checkout + - run: *npm_install_and_link + - run: + name: Build documentation. + command: npm run docs + sample_tests: + docker: + - image: 'node:8' + user: node + steps: + - checkout + - run: + name: Decrypt credentials. + command: | + openssl aes-256-cbc -d -in .circleci/key.json.enc \ + -out .circleci/key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: *npm_install_and_link + - run: *samples_npm_install_and_link + - run: + name: Run sample tests. + command: npm run samples-test + environment: + GCLOUD_PROJECT: long-door-651 + GOOGLE_APPLICATION_CREDENTIALS: /home/node/samples/.circleci/key.json + NPM_CONFIG_PREFIX: /home/node/.npm-global + - run: + name: Remove unencrypted key. + command: rm .circleci/key.json + when: always + working_directory: /home/node/samples/ + system_tests: + docker: + - image: 'node:8' user: node steps: - checkout - - run: npm install - - run: npm run check + - run: + name: Decrypt credentials. + command: | + openssl aes-256-cbc -d -in .circleci/key.json.enc \ + -out .circleci/key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: *npm_install_and_link + - run: + name: Run system tests. + command: npm run system-test + environment: + GOOGLE_APPLICATION_CREDENTIALS: .circleci/key.json + - run: + name: Remove unencrypted key. + command: rm .circleci/key.json + when: always publish_npm: docker: - - image: node8 + - image: 'node:8' user: node steps: - checkout - - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc - - run: npm install - - run: npm publish + - npm install + - run: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc' + - run: npm publish --access=public diff --git a/.circleci/key.json.enc b/.circleci/key.json.enc new file mode 100644 index 0000000..5136c55 Binary files /dev/null and b/.circleci/key.json.enc differ diff --git a/package.json b/package.json index e868538..c9716a4 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,11 @@ "prepare": "npm run compile", "pretest-only": "npm run compile", "posttest": "npm run check", - "license-check": "jsgl --local ." + "license-check": "jsgl --local .", + "samples-test": "mocha samples/system-test", + "system-test": "mocha build/system-test", + "lint": "npm run check", + "docs": "echo no docs 👩‍⚕️" }, "files": [ "LICENSE", diff --git a/samples/.eslintrc.yml b/samples/.eslintrc.yml new file mode 100644 index 0000000..282535f --- /dev/null +++ b/samples/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/samples/package.json b/samples/package.json new file mode 100644 index 0000000..a6efb14 --- /dev/null +++ b/samples/package.json @@ -0,0 +1,19 @@ +{ + "description": "Samples for the google-p12-pem npm module.", + "license": "MIT", + "author": "Google LLC", + "engines": { + "node": ">=8" + }, + "repository": "google/google-p12-pem", + "private": true, + "scripts": { + "test": "mocha system-test" + }, + "dependencies": { + "google-p12-pem": "*" + }, + "devDependencies": { + "mocha": "^5.2.0" + } +} diff --git a/src/bin/gp12-pem.ts b/src/bin/gp12-pem.ts index ee71330..a14113b 100755 --- a/src/bin/gp12-pem.ts +++ b/src/bin/gp12-pem.ts @@ -1,4 +1,12 @@ #!/usr/bin/env node + +/** + * Copyright 2018 Google LLC + * + * Distributed under MIT license. + * See file LICENSE for detail or copy at https://opensource.org/licenses/MIT + */ + import * as gp12 from '../index'; const argv = process.argv; diff --git a/src/index.ts b/src/index.ts index b564f8d..78b1925 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,10 @@ +/** + * Copyright 2018 Google LLC + * + * Distributed under MIT license. + * See file LICENSE for detail or copy at https://opensource.org/licenses/MIT + */ + import * as fs from 'fs'; import * as forge from 'node-forge'; import * as pify from 'pify'; diff --git a/synth.py b/synth.py new file mode 100644 index 0000000..76fcb26 --- /dev/null +++ b/synth.py @@ -0,0 +1,7 @@ +import synthtool as s +import synthtool.gcp as gcp +import logging +logging.basicConfig(level=logging.DEBUG) +common_templates = gcp.CommonTemplates() +templates = common_templates.node_library() +s.copy(templates) diff --git a/system-test/.eslintrc.yml b/system-test/.eslintrc.yml new file mode 100644 index 0000000..282535f --- /dev/null +++ b/system-test/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/system-test/system.ts b/system-test/system.ts new file mode 100644 index 0000000..8aeb0d3 --- /dev/null +++ b/system-test/system.ts @@ -0,0 +1,8 @@ +/** + * Copyright 2018 Google LLC + * + * Distributed under MIT license. + * See file LICENSE for detail or copy at https://opensource.org/licenses/MIT + */ + +console.warn(`no system tests available 👻`); diff --git a/test/index.ts b/test/index.ts index 79a8d00..bd15c7c 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,3 +1,10 @@ +/** + * Copyright 2018 Google LLC + * + * Distributed under MIT license. + * See file LICENSE for detail or copy at https://opensource.org/licenses/MIT + */ + import * as assert from 'assert'; import * as fs from 'fs'; import {getPem} from '../src/index'; diff --git a/tsconfig.json b/tsconfig.json index c47ad1d..044a672 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "src/*.ts", "src/**/*.ts", "test/*.ts", - "test/**/*.ts" + "system-test/*.ts" ], "exclude": [ "node_modules"