diff --git a/Jenkinsfile b/Jenkinsfile index 3f9b204..5209b95 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,34 +12,12 @@ pipeline { } stages { - stage('Setup') { + stage('Building') { steps { - echo 'Setting up test environment' - sh 'yarn --frozen-lockfile' - sh 'nodejs jenkins.js ${VERSION}' script { currentBuild.displayName = env.VERSION } - } - } - stage('Testing') { - steps { - echo 'Running tests...' - sh 'npm test' - } - } - } - 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 94b6a1f..ed29440 100644 --- a/jenkins.js +++ b/jenkins.js @@ -1,9 +1,23 @@ +/* eslint-disable no-console */ +/* eslint-disable no-sync */ 'use strict'; 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.execSync ('yarn test', { stdio: 'inherit' }); + +child_process.exec ('git log -1 | grep \'\\[no publish\\]\'') + .addListener ('exit', (code) => { + if (code === 0) + console.log ('build not marked for deployment'); + else + child_process.execSync ('yarn publish'); + }); diff --git a/package.json b/package.json index e678c4c..b55d70e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "mocha", - "lint": "eslint --fix ." + "lint": "eslint --fix .", + "ci": "yarn --frozen-lockfile && node jenkins.js" }, "repository": { "type": "git", @@ -20,9 +21,9 @@ "node": ">=10.0.0" }, "devDependencies": { - "@scode/eslint-config": "^1.2.8", + "@scode/eslint-config": "^1.2.15", "chai": "^4.2.0", "eslint": "^6.8.0", "mocha": "^7.0.1" } -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 16d863e..a79ff60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,7 +18,7 @@ esutils "^2.0.2" js-tokens "^4.0.0" -"@scode/eslint-config@^1.2.8": +"@scode/eslint-config@^1.2.15": version "1.2.15" resolved "https://npm.scode.ovh/@scode%2feslint-config/-/eslint-config-1.2.15.tgz#28728ad7425cb09b84c77a5c885d115f41c1d4c2" integrity sha512-GrgnX9sy/saYzHQZ7GNeO1NZgSenRLz9xBfzX8s2MRBVbYHZlod1rddhiIWSx08cyOaAfvd+QgHX3UgtbNz51Q==