diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 05d3c9b..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,99 +0,0 @@ -version: 2.1 -tagged_build_filters: &tagged_build_filters - branches: - ignore: /.*/ - tags: - only: /v[0-9]+\.[0-9]+\.[0-9]+/ -test_build_filters: &test_build_filters - branches: - only: /.*/ - tags: - ignore: /v[0-9]+\.[0-9]+\.[0-9]+/ -jobs: - test: - docker: - - image: circleci/node:10 - steps: - - checkout - - run: npm install - - run: npm run lint - - run: npm run test - build: - docker: - - image: circleci/node:10 - steps: - - checkout - - run: - name: Check Tagged Push - command: | - PKG_VERSION=$(grep version package.json | cut -d'"' -f4) - if [[ "${CIRCLE_TAG}" != "v${PKG_VERSION}" ]]; then - echo "There is mismatch:" - echo " TAG_VERSION: ${CIRCLE_TAG}" - echo " PKG_VERSION: v${PKG_VERSION}" - exit 1 - fi - - run: npm install --production - - run: zip logdna.zip -r node_modules/ index.js package.json lib/*.js - - persist_to_workspace: - root: . - paths: - - ./logdna.zip - release: - docker: - - image: circleci/golang:1.12 - steps: - - attach_workspace: - at: . - - run: go get -u github.com/tcnksm/ghr - - run: - name: Create a Release - command: | - ghr \ - -n "LogDNA Node.js Logger ${CIRCLE_TAG}" \ - -t ${GITHUB_TOKEN} \ - -u ${CIRCLE_PROJECT_USERNAME} \ - -r ${CIRCLE_PROJECT_REPONAME} \ - -draft ${CIRCLE_TAG} ./logdna.zip - approve: - machine: true - steps: - - attach_workspace: - at: . - - persist_to_workspace: - root: . - paths: - - ./logdna.zip - publish: - docker: - - image: circleci/node:10 - steps: - - checkout - - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc - - run: npm publish -workflows: - update: - jobs: - - test: - filters: *tagged_build_filters - - build: - requires: - - test - filters: *tagged_build_filters - - release: - requires: - - build - filters: *tagged_build_filters - - approve: - type: approval - requires: - - release - filters: *tagged_build_filters - - publish: - requires: - - approve - filters: *tagged_build_filters - test: - jobs: - - test: - filters: *test_build_filters diff --git a/.gitignore b/.gitignore index 34c6f93..f4e3ecf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ logs *.log npm-debug.log* package-lock.json +.tap-output # Runtime data pids diff --git a/.taprc b/.taprc index 72a642c..fa1de4d 100644 --- a/.taprc +++ b/.taprc @@ -3,6 +3,7 @@ ts: false jsx: false check-coverage: true reporter: tap +output-file: .tap-output jobs: 2 nyc-arg: - --all=true diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8a88ae3 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,141 @@ +library 'magic-butler-catalogue' + +def PROJECT_NAME = "nodejs-client-legacy" +def TRIGGER_PATTERN = ".*@logdnabot.*" +def CURRENT_BRANCH = [env.CHANGE_BRANCH, env.BRANCH_NAME]?.find{branch -> branch != null} +def DEFAULT_BRANCH = 'master' +def CHANGE_ID = env.CHANGE_ID == null ? '' : env.CHANGE_ID + +pipeline { + agent none + + options { + timestamps() + ansiColor 'xterm' + } + + triggers { + issueCommentTrigger(TRIGGER_PATTERN) + } + + environment { + GITHUB_TOKEN = credentials('github-api-token') + NPM_TOKEN = credentials('npm-publish-token') + NPM_CONFIG_CACHE = '.npm' + NPM_CONFIG_USERCONFIG = '.npmrc' + SPAWN_WRAP_SHIM_ROOT = '.npm' + } + + stages { + stage('Validate PR Source') { + when { + expression { env.CHANGE_FORK } + not { + triggeredBy 'issueCommentCause' + } + } + steps { + error("A maintainer needs to approve this PR for CI by commenting") + } + } + + stage('Test Suite') { + matrix { + axes { + axis { + name 'NODE_VERSION' + values '12', '14', '15' + } + } + + when { + not { + changelog '\\[skip ci\\]' + } + } + + agent { + docker { + image "us.gcr.io/logdna-k8s/node:${NODE_VERSION}-ci" + } + } + + stages { + stage('Test') { + steps { + sh "mkdir -p ${NPM_CONFIG_CACHE} coverage" + sh 'npm install' + sh 'npm run test:ci' + } + + post { + always { + junit 'coverage/test.xml' + + publishHTML target: [ + allowMissing: false, + alwaysLinkToLastBuild: false, + keepAll: true, + reportDir: 'coverage/lcov-report', + reportFiles: 'index.html', + reportName: "coverage-node-v${NODE_VERSION}" + ] + } + } + } + } + } + } + + stage('Test Release') { + when { + beforeAgent true + not { + branch DEFAULT_BRANCH + } + } + + agent { + docker { + image "us.gcr.io/logdna-k8s/node:14-ci" + customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}" + } + } + + environment { + GIT_BRANCH = "${CURRENT_BRANCH}" + BRANCH_NAME = "${CURRENT_BRANCH}" + CHANGE_ID = "" + } + + steps { + sh "mkdir -p ${NPM_CONFIG_CACHE}" + sh 'npm install' + sh "npm run release:dry" + } + } + + stage('Release') { + when { + beforeAgent true + branch DEFAULT_BRANCH + not { + changelog '\\[skip ci\\]' + } + } + + agent { + docker { + image "us.gcr.io/logdna-k8s/node:14-ci" + customWorkspace "${PROJECT_NAME}-${BUILD_NUMBER}" + } + } + + steps { + sh "mkdir -p ${NPM_CONFIG_CACHE}" + sh 'npm install' + sh 'npm run release' + } + } + } +} diff --git a/package.json b/package.json index feaeabf..be57b84 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,20 @@ "scripts": { "lint": "eslint .", "pretest": "npm run lint", - "test": "tap" + "test": "tap", + "pretest:ci": "npm run lint", + "test:ci": "tools/test-ci.sh", + "release": "semantic-release", + "release:dry": "semantic-release --dry-run --no-ci --branches=${BRANCH_NAME:-master}" }, + "files": [ + "lib/", + "index.js", + "types.d.ts", + "README.md", + "LICENSE", + "CHANGELOG.md" + ], "repository": { "type": "git", "url": "git+https://github.com/logdna/nodejs.git" @@ -28,6 +40,12 @@ "logger", "javascript" ], + "release": { + "branches": [ + "master" + ], + "extends": "semantic-release-config-logdna" + }, "author": { "name": "LogDNA Inc.", "email": "help@logdna.com" @@ -71,6 +89,10 @@ "mocha": "^5.2.0", "nock": "^13.0.2", "nyc": "^14.1.1", - "tap": "^14.10.7" + "semantic-release": "^17.4.7", + "semantic-release-config-logdna": "^1.3.0", + "tap": "^14.10.7", + "tap-parser": "^10.1.0", + "tap-xunit": "^2.4.1" } } diff --git a/tools/test-ci.sh b/tools/test-ci.sh new file mode 100755 index 0000000..ea5148e --- /dev/null +++ b/tools/test-ci.sh @@ -0,0 +1,7 @@ +#!/bin/bash +mkdir -p coverage +tap + +code=$? +cat .tap-output | ./node_modules/.bin/tap-parser -t -f | ./node_modules/.bin/tap-xunit > coverage/test.xml +exit $code