Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
refactor(npm-scripts): parametric tests, CI/CD fixes & reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
debloper committed Jan 12, 2018
1 parent ffed64a commit 11a1061
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 53 deletions.
28 changes: 12 additions & 16 deletions deploy/release.groovy
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/usr/bin/groovy
def ci (){
stage('build planner npm'){
stage('Setup & Build'){
container('ui'){
sh 'npm install'
sh 'npm run build'
sh 'npm pack dist/'
}
}

stage('unit test'){
stage('Unit Tests'){
container('ui'){
sh 'npm run test:unit'
sh 'npm run tests -- --unit'
}
}

stage('func test'){
stage('Functional Tests'){
dir('runtime'){
container('ui'){
sh '''
Expand All @@ -27,38 +26,35 @@ def ci (){
}

def ciBuildDownstreamProject(project){
stage('build fabric8-ui npm'){
stage('Build fabric8-ui'){
return buildSnapshotFabric8UI{
pullRequestProject = project
}
}
}

def buildImage(imageName){
stage('build snapshot image'){
stage('Snapshot Image'){
sh "cd fabric8-ui && docker build -t ${imageName} -f Dockerfile.deploy ."
}

stage('push snapshot image'){
sh "cd fabric8-ui && docker push ${imageName}"
}
}

def cd (b){
stage('fix git repo'){
stage('Repo Fix'){
sh './scripts/fix-git-repo.sh'
}

stage('build'){
stage('Setup & Build'){
sh 'npm install'
sh 'npm run build'
}

stage('unit test'){
sh 'npm run test:unit'
stage('Unit Tests'){
sh 'npm run tests -- --unit'
}

stage('func test'){
stage('Functional Tests'){
dir('runtime'){
container('ui'){
sh '''
Expand All @@ -69,7 +65,7 @@ def cd (b){
}
}

stage('release'){
stage('Release'){
def published = npmRelease{
branch = b
}
Expand Down
74 changes: 40 additions & 34 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
*/

// Require primitives
var del = require('del')
var del = require('del')
, path = require('path')
, argv = require('yargs').argv
, process = require('child_process')
, runSequence = require('run-sequence')
, proc = require('child_process')
;

// Require gulp extension modules
// Require gulp & its extension modules
var gulp = require('gulp')
, ngc = require('gulp-ngc')
, ngc = require('gulp-ngc')
, less = require('gulp-less')
, util = require('gulp-util')
, changed = require('gulp-changed')
, lesshint = require('gulp-lesshint')
, concat = require('gulp-concat-css')
, sourcemaps = require('gulp-sourcemaps')
, replace = require('gulp-string-replace')

, changed = require('gulp-changed')
, lesshint = require('gulp-lesshint')
, concat = require('gulp-concat-css')
, srcmaps = require('gulp-sourcemaps')
, replace = require('gulp-string-replace')
;

// Requirements with special treatments
var KarmaServer = require('karma').Server
, LessAutoprefix = require('less-plugin-autoprefix')
, autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] })
var KarmaServer = require('karma').Server
, LessAutoprefix = require('less-plugin-autoprefix')
, autoprefix = new LessAutoprefix({ browsers: ['last 2 versions'] })
;

// Not sure if var or const
var appSrc = 'src';
var distPath = 'dist';
var appSrc = 'src';
var distPath = 'dist';
var distWatch = 'watch';

/*
Expand Down Expand Up @@ -92,10 +92,10 @@ mach.transpileLESS = function (src, debug) {
}))
.pipe(lesshint.reporter()) // Leave empty to use the default, "stylish"
.pipe(lesshint.failOnError()) // Use this to fail the task on lint errors
.pipe(sourcemaps.init())
.pipe(srcmaps.init())
.pipe(less(opts))
//.pipe(concat('styles.css'))
.pipe(sourcemaps.write())
.pipe(srcmaps.write())
.pipe(gulp.dest(function (file) {
return distPath + file.base.slice(__dirname.length + 'src/'.length);
}));
Expand All @@ -109,7 +109,7 @@ mach.transpileLESS = function (src, debug) {
gulp.task('build', function () {

// app (default)
mach.transpileTS(); // Transpile ts sources to js using the tsconfig
mach.transpileTS(); // Transpile *.ts sources to *.js using the tsconfig
mach.transpileLESS(appSrc + '/**/*.less'); // Transpile and minify less, storing results in distPath.
mach.copyToDist(['src/**/*.html']); // Copy template html files to distPath
gulp.src(['LICENSE', 'README.adoc', 'package.json']).pipe(gulp.dest(distPath)); // Copy static assets to distPath
Expand Down Expand Up @@ -173,7 +173,7 @@ gulp.task('clean', function () {
}

// cache
if (argv.cache) process.exec('npm cache clean');
if (argv.cache) proc.exec('npm cache clean');

// config
// if (argv.config) { subroutine to clean config - not yet needed }
Expand All @@ -184,25 +184,25 @@ gulp.task('clean', function () {
// images
if (argv.images) {
// Get ID of the images having 'fabric8-planner' in its name
process.exec('sudo docker ps -aq --filter "name=fabric8-planner"', function (e, containerID) {
proc.exec('sudo docker ps -aq --filter "name=fabric8-planner"', function (e, containerID) {
if (e) {
console.log(e);
return;
}

// @TODO: wrap this in a try-catch block to avoid unexpected behavior
process.exec('sudo docker stop ' + containerID);
process.exec('sudo docker rm ' + containerID);
proc.exec('sudo docker stop ' + containerID);
proc.exec('sudo docker rm ' + containerID);

// Container has been killed, safe to remove image(s) with 'fabric8-planner-*' as part of their ref
process.exec('sudo docker images -aq --filter "reference=fabric8-planner-*"', function (e, imageID) {
proc.exec('sudo docker images -aq --filter "reference=fabric8-planner-*"', function (e, imageID) {
if (e) {
console.log(e);
return;
}

// @TODO: wrap this in a try-catch block to avoid unexpected behavior
process.exec('sudo docker rmi ' + imageID);
proc.exec('sudo docker rmi ' + imageID);
});
});
}
Expand All @@ -214,15 +214,21 @@ gulp.task('clean', function () {
if (argv.temp) del(['tmp', 'coverage', 'typings', '.sass-cache']);
});

// Deletes and re-installs dependencies.
gulp.task('reinstall', ['clean:all'], function () {
return cp.execFile('npm install');
});
// Test
gulp.task('tests', function () {

// unit
if (argv.unit) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function (code) {
process.exit(code);
}).start();
}

// Run unit tests.
gulp.task('test:unit', function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
// func
if (argv.unit) {
// subroutine to run functional tests
}
});
6 changes: 3 additions & 3 deletions scripts/run-planner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ eval set -- "$TEMP"
# reinstall Planner and Platform
function reinstallPlatformIntegrated {
echo "Reinstalling Planner in $PLANNER_HOME"
cd $PLANNER_HOME && npm run reinstall &
cd $PLANNER_HOME && npm run clean -- --cache --modules && npm install &
echo "Reinstalling Platform in $PLATFORM_HOME"
cd $PLATFORM_HOME && npm run reinstall &
wait
Expand All @@ -40,7 +40,7 @@ function reinstallPlatformIntegrated {
# reinstall Planner and Runtime
function reinstallStandalone {
echo "Reinstalling Planner in $PLANNER_HOME"
cd $PLANNER_HOME && npm run reinstall &
cd $PLANNER_HOME && npm run clean -- --cache --modules && npm install &
echo "Reinstalling Runtime in $PLANNER_HOME/runtime"
cd $PLANNER_HOME/runtime && npm run reinstall &
wait
Expand Down Expand Up @@ -75,7 +75,7 @@ function runPlanner {
echo "Running Planner in $PLANNER_HOME"
# as the watch task has to be started in the backgound, we need to create a minimal
# dist-watch directory befor launching it otherwise the following linking gets confused.
cd $PLANNER_HOME && mkdir -p dist-watch && cp package.json dist-watch/ && npm run watch:library &
cd $PLANNER_HOME && mkdir -p dist-watch && cp package.json dist-watch/ && npm run build -- --watch &
}

# extract options and their arguments into variables.
Expand Down

0 comments on commit 11a1061

Please sign in to comment.