From 59249a3a1c4a261d638386366a5af6e09dadc9aa Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 6 Feb 2020 12:17:07 +0100 Subject: [PATCH] [no publish] simplify ci --- Jenkinsfile | 21 ++------------------- jenkins.js | 28 ++++++++++++++++++++++++---- package.json | 5 +++-- yarn.lock | 2 +- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bdac796..c4cfc1d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,32 +8,15 @@ pipeline { versionPrefix: '1.2.', worstResultForIncrement: 'SUCCESS' ]) - publish = 0 } stages { - stage('Setup') { + stage('Building') { steps { - echo 'Setting up environment' - sh 'yarn --frozen-lockfile' - sh 'nodejs jenkins.js ${VERSION}' script { currentBuild.displayName = env.VERSION } - } - } - } - post { - success { - script { - publish = sh script: "git log -1 | grep '\\[no publish\\]'", returnStatus: true - if (publish != 0) { - echo 'Deploying' - sh 'yarn publish' - } else { - echo 'Build successful, Commit not marked for deploying' - currentBuild.result = "UNSTABLE" - } + sh 'yarn ci ${VERSION}' } } } diff --git a/jenkins.js b/jenkins.js index 7d2ada9..1c33f2a 100644 --- a/jenkins.js +++ b/jenkins.js @@ -1,5 +1,25 @@ -const fs = require('fs') +/* eslint-disable no-process-exit */ +/* eslint-disable no-console */ +/* eslint-disable no-sync */ +'use strict'; -const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')) -pkg.version = process.argv[2] -fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)) +const fs = require ('fs'); +const child_process = require ('child_process'); + +const pkg = JSON.parse (fs.readFileSync ('package.json', 'utf-8')); +[ + ,, pkg.version +] = process.argv; +fs.writeFileSync ('package.json', JSON.stringify (pkg, null, 2)); + +child_process.execSync ('yarn lint', { stdio: 'inherit' }); + +child_process.exec ('git log -1 | grep \'\\[no publish\\]\'') + .addListener ('exit', (code) => { + if (code === 0) { + console.log ('build not marked for deployment'); + process.exit (1); + } + else + child_process.execSync ('yarn publish'); + }); diff --git a/package.json b/package.json index 17df1a8..373efff 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "scode eslint standard configuration", "main": "index.js", "scripts": { - "lint": "eslint --fix ." + "lint": "eslint --fix .", + "ci": "yarn --frozen-lockfile && node jenkins.js" }, "repository": { "type": "git", @@ -26,7 +27,7 @@ "eslint-plugin-standard": "^4.0.1" }, "dependencies": { - "eslint-plugin-import": "^2.20.0", + "eslint-plugin-import": "^2.20.1", "eslint-plugin-jsdoc": "^21.0.0", "eslint-plugin-node": "^11.0.0", "eslint-plugin-sort-requires-by-path": "^1.0.2", diff --git a/yarn.lock b/yarn.lock index 69e545c..cc4b631 100644 --- a/yarn.lock +++ b/yarn.lock @@ -291,7 +291,7 @@ eslint-plugin-es@^3.0.0: eslint-utils "^2.0.0" regexpp "^3.0.0" -eslint-plugin-import@^2.20.0: +eslint-plugin-import@^2.20.1: version "2.20.1" resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.20.1.tgz#802423196dcb11d9ce8435a5fc02a6d3b46939b3" integrity sha512-qQHgFOTjguR+LnYRoToeZWT62XM55MBVXObHM6SKFd1VzDcX/vqT1kAz8ssqigh5eMj8qXcRoXXGZpPP6RfdCw==