typescript, interactive
This commit is contained in:
78
lib/snippets/jenkins/index.js
Normal file
78
lib/snippets/jenkins/index.js
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, March 2020
|
||||
*/
|
||||
|
||||
/* eslint-disable no-sync */
|
||||
/* eslint-disable no-console */
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require ('fs-extra');
|
||||
const path = require ('path');
|
||||
|
||||
/**
|
||||
* copies the full template to a new folder named after arg[0]
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @param {Array} args function arguments
|
||||
*/
|
||||
function run (folder, args) {
|
||||
const is_node = args.length === 1 && (/^node$/ui).test (args[0]);
|
||||
|
||||
const template = path.join (
|
||||
__dirname,
|
||||
'template',
|
||||
is_node
|
||||
? 'node'
|
||||
: 'general'
|
||||
);
|
||||
|
||||
for (const f of fs.readdirSync (template)) {
|
||||
fs.copy (
|
||||
path.join (template, f),
|
||||
path.join (folder, f),
|
||||
{ filter: (src, dest) => !fs.existsSync (dest) }
|
||||
);
|
||||
}
|
||||
|
||||
if (is_node) {
|
||||
const pkg = path.join (folder, 'package.json');
|
||||
if (fs.existsSync (pkg)) {
|
||||
const json = JSON.parse (fs.readFileSync (pkg, 'utf-8'));
|
||||
json.scripts.ci = 'yarn && node jenkins.js';
|
||||
fs.writeFileSync (pkg, JSON.stringify (json, null, 2), 'utf-8');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the arguments meet the requirements
|
||||
*
|
||||
* @param {string} folder folder to run in
|
||||
* @returns {boolean} true if arguments match requirements
|
||||
*/
|
||||
function assert (folder) {
|
||||
const tests = [
|
||||
{
|
||||
f: () => (typeof folder === 'string'),
|
||||
reason: 'cwd is not a folder (internal error)'
|
||||
},
|
||||
{
|
||||
f: () => (fs.existsSync (folder)),
|
||||
reason: 'cwd does not exist (internal error)'
|
||||
}
|
||||
];
|
||||
for (const test of tests) {
|
||||
if (!test.f ()) {
|
||||
console.log (test.reason);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = { run, assert };
|
39
lib/snippets/jenkins/template/general/Jenkinsfile
vendored
Normal file
39
lib/snippets/jenkins/template/general/Jenkinsfile
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.0.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
publish = 0
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Setup') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
echo 'Setting up test environment'
|
||||
sh 'echo setup'
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
script {
|
||||
publish = sh script: "git log -1 | grep '\\[no publish\\]'", returnStatus: true
|
||||
if (publish != 0) {
|
||||
echo 'Deploying'
|
||||
sh 'echo deploy'
|
||||
} else {
|
||||
echo 'Build successful, Commit not marked for deploying'
|
||||
currentBuild.result = "UNSTABLE"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
lib/snippets/jenkins/template/node/Jenkinsfile
vendored
Normal file
23
lib/snippets/jenkins/template/node/Jenkinsfile
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
VERSION = VersionNumber([
|
||||
versionNumberString:
|
||||
'${BUILDS_ALL_TIME}',
|
||||
versionPrefix: '1.0.',
|
||||
worstResultForIncrement: 'SUCCESS'
|
||||
])
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Building') {
|
||||
steps {
|
||||
script {
|
||||
currentBuild.displayName = env.VERSION
|
||||
}
|
||||
sh 'yarn ci ${VERSION}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
lib/snippets/jenkins/template/node/jenkins.js
Normal file
33
lib/snippets/jenkins/template/node/jenkins.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 <timo@scode.ovh>, March 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' });
|
||||
if (typeof pkg.scripts !== 'undefined' && typeof pkg.scripts.test === 'string')
|
||||
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');
|
||||
process.exit (1);
|
||||
}
|
||||
else { child_process.execSync ('yarn publish'); }
|
||||
});
|
Reference in New Issue
Block a user