From f498d840f37f0c8eee0a55b7ab53cf7093638401 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Thu, 6 Feb 2020 17:36:09 +0100 Subject: [PATCH] simplify ci --- Jenkinsfile | 23 +++-------------------- jenkins.js | 23 ++++++++++++++++------- package.json | 3 ++- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 21e7890..81d532c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,37 +3,20 @@ pipeline { environment { VERSION = VersionNumber([ - versionNumberString: + versionNumberString: '${BUILDS_ALL_TIME}', versionPrefix: '1.0.', worstResultForIncrement: 'SUCCESS' ]) - publish = 0 } 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 } - } - } - } - 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 25e1e78..1c33f2a 100644 --- a/jenkins.js +++ b/jenkins.js @@ -1,16 +1,25 @@ -/* - * Copyright (C) Sapphirecode - All Rights Reserved - * This file is part of snippeteer which is released under BSD-3-Clause. - * See file 'LICENSE' for full license details. - * Created by Timo Hocker , January 2020 - */ - +/* eslint-disable no-process-exit */ +/* 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.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 402d1c4..312ad84 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "snippeteer": "./index.js" }, "scripts": { - "lint": "eslint --fix ." + "lint": "eslint --fix .", + "ci": "yarn --frozen-lockfile && node jenkins.js" }, "repository": { "type": "git",