Skip to content

Commit

Permalink
Added CI scripts, and created a version checking file
Browse files Browse the repository at this point in the history
Build, lint, and unit tests now running and reporting correctly to 8ac0n.

- 8ac0n works now!
- Wrote a version checker that outputs checkstyle (checked in lint)

RELATED TO OKTA-68828
8ac0n: test

OKTA-68828
<<<Jenkins Check-In of Tested SHA: 450e7b3 for rchild@okta.com>>> 
Artifact: okta-core.webapp
  • Loading branch information
rchild-okta committed Feb 8, 2016
1 parent 862536f commit 68f88ea
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# 1.1.0
- Initial copy from okta-core
33 changes: 31 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ module.exports = function (grunt) {
SASS = ASSETS + 'sass',
SCSSLINT_OUT_FILE = 'build2/loginscss-checkstyle-result.xml',
CSS = 'target/css',
VERSION_OUT_FILE = 'build2/loginversion-checkstyle-result.xml',
COPYRIGHT_TEXT = grunt.file.read('src/widget/copyright.frag'),
WIDGET_RC = '.widgetrc',
DEFAULT_SERVER_PORT = 1804;

var hasCheckStyle = process.argv.indexOf('--checkstyle') > -1;
var hasPublished = process.argv.indexOf('--published=1') > -1;

// .widgetrc is a json file that can be used by a dev to override
// things like the widget options in the test server, the server port, etc
Expand Down Expand Up @@ -264,6 +266,23 @@ module.exports = function (grunt) {
}
},

'check-version': {
options: (function () {
if (hasCheckStyle) {
return {
force: true,
reporter: 'checkstyle',
reporterOutput: VERSION_OUT_FILE
};
}
else {
return {
force: false
};
}
}())
},

exec: {
build: 'node buildtools/r.js -o target/js/build.js'
},
Expand Down Expand Up @@ -385,6 +404,7 @@ module.exports = function (grunt) {
grunt.loadTasks('buildtools/JSONtoJs');
grunt.loadTasks('buildtools/phonecodes');
grunt.loadTasks('buildtools/scsslint');
grunt.loadTasks('buildtools/checkversion');

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');
Expand Down Expand Up @@ -439,7 +459,7 @@ module.exports = function (grunt) {
});

grunt.task.registerTask(
'dist',
'package',
'Generates versioned assets and copies them to the dist/ dir',
[
'prebuild:minified',
Expand All @@ -452,6 +472,15 @@ module.exports = function (grunt) {
grunt.task.registerTask('start-server', ['copy:server', 'connect:server']);
grunt.task.registerTask('start-server-open', ['copy:server', 'connect:open']);

grunt.task.registerTask('lint', ['jshint', 'scss-lint']);
grunt.task.registerTask('lint', function () {
var tasks = ['jshint', 'scss-lint'];
if (!hasPublished) {
// Because of the build order, we only want to run the check-version
// script if we have not just published to npm.
tasks.push('check-version');
}
grunt.task.run(tasks);
});

grunt.task.registerTask('default', ['lint', 'test']);
};
77 changes: 77 additions & 0 deletions buildtools/checkversion/check-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*global module */
var semver = require('semver'),
exec = require('child_process').exec;

var failMessage = 'Package version must be > latest package version';

module.exports = function (grunt) {

function writeCheckStyle(file, hasError) {
var checkStyle = [
'<?xml version="1.0" encoding="utf-8"?>',
'<checkstyle version="1.5.6">'
];
if (hasError) {
checkStyle.push(
'<file name="package.json">',
'<error severity="warning" message="' + failMessage + '" />',
'</file>'
);
}
checkStyle.push('</checkstyle>');
grunt.log.ok('Writing results to', file);
grunt.file.write(file, checkStyle.join(''));
}

grunt.registerTask(

'check-version',

'Fails task if package version is <= latest published module',

function () {
var done = this.async(),
options = this.options(),
reporter = options.reporter,
reporterOutput = options.reporterOutput,
hasReporter = reporter && reporterOutput,
force = options.force,
currentPackage = grunt.config('pkg'),
cmd = 'npm view ' + currentPackage.name + ' version';

grunt.log.ok('Running', cmd);

exec(cmd, {}, function (err, latestPublishedVersion) {

if (err) {
grunt.fail.fatal(err);
}

grunt.log.ok('Package version: ', currentPackage.version);
grunt.log.ok('Latest published version: ', latestPublishedVersion);

var isOkay = semver.gt(currentPackage.version, latestPublishedVersion);

if (hasReporter) {
writeCheckStyle(reporterOutput, !isOkay);
}

if (isOkay) {
grunt.log.ok('Package version is > latest package version');
done();
}
else if (force) {
grunt.log.error(failMessage);
done();
}
else {
grunt.fail.fatal(failMessage);
}

});

}

);

};
96 changes: 96 additions & 0 deletions ci-scripts/okta-signin-widget-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash -vx
JOB_NAME=`basename $0`
LOGDIRECTORY=/tmp/ci-builder
mkdir -p $LOGDIRECTORY
LOGFILE=$LOGDIRECTORY/$JOB_NAME.log
exec > >(tee $LOGFILE)
exec 2>&1
set -e

# Bacon does not pass a parameter, so default to the one we want (deploy)
TASK="${1:-deploy}"
PUBLISHED=0

BUILD_TEST_SUITE_ID=D33E21EE-E0D0-401D-8162-56B9A7BA0539
LINT_TEST_SUITE_ID=2D4D1259-92C2-45BA-A74D-E665B7EC17FB
UNIT_TEST_SUITE_ID=12DFDE73-F3D5-4EEB-BF12-DDE72E66DE61

REGISTRY=https://artifacts.aue1d.saasure.com/artifactory/api/npm/npm-okta

function usage() {
OUTPUTCODE=$1
echo """
USAGE:
./okta-signin-widget-build.sh {TASK}
Example:
./okta-signin-widget-build.sh build
TASKS:
help Prints this guide.
deploy Publishes widget to NPM after successful build
Requires valid Artifactory credentials.
"""
[ -z $OUTPUTCODE ] && OUTPUTCODE=0
exit $OUTPUTCODE
}

function publish() {
if [ "$BRANCH" == "master" ]; then
echo "Publishing master build"
if npm publish --registry ${REGISTRY}; then
PUBLISHED=1
echo "Publish Success"
else
echo "Publish Failed"
fi
fi
}

function build() {
start_test_suite ${BUILD_TEST_SUITE_ID}
if bundle install && npm install && npm run package && publish; then
echo "Finishing up test suite $BUILD_TEST_SUITE_ID"
finish_test_suite "build"
else
echo "Build failed"
finish_failed_test_suite "build"
exit 1
fi
}

function lint() {
start_test_suite ${LINT_TEST_SUITE_ID}
if npm run lint:report -- --published=${PUBLISHED}; then
echo "Finishing up test suite $LINT_TEST_SUITE_ID"
finish_test_suite "checkstyle" "okta-signin-widget/build2/"
else
echo "Lint failed"
finish_failed_test_suite "checkstyle" "okta-signin-widget/build2/"
fi
}

function unit() {
start_test_suite ${UNIT_TEST_SUITE_ID}
if npm test; then
echo "Finishing up test suite $UNIT_TEST_SUITE_ID"
finish_test_suite "jsunit" "okta-signin-widget/build2/reports/jasmine/"
else
echo "Unit failed"
finish_failed_test_suite "jsunit" "okta-signin-widget/build2/reports/jasmine/"
fi
}

case $TASK in
help)
usage
;;
deploy)
build
lint
unit
;;
*)
usage $TASK
;;
esac
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"name": "okta-signin-widget",
"name": "@okta/okta-signin-widget",
"description": "The Okta Sign-In Widget",
"version": "1.1.0",
"homepage": "http://developer.okta.com/docs/guides/okta_sign-in_widget.html",
"homepage": "https://github.com/okta/okta-signin-widget",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/okta/okta-signin-widget.git"
},
"bugs": {
"url": "https://github.com/okta/okta-signin-widget/issues"
},
"publishConfig": {
"registry": "https://artifacts.aue1d.saasure.com/artifactory/api/npm/npm-okta"
},
"scripts": {
"lint:report": "grunt lint --checkstyle",
"lint": "grunt lint",
Expand All @@ -12,7 +22,7 @@
"build:prod": "grunt build:minified",
"prestart": "npm run build:dev",
"start": "grunt start-server-open",
"prepublish": "grunt dist"
"package": "grunt package"
},
"devDependencies": {
"grunt": "^0.4.5",
Expand All @@ -31,6 +41,7 @@
"handlebars": "^4.0.5",
"lodash": "^4.1.0",
"open": "0.0.5",
"request-promise": "^2.0.0"
"request-promise": "^2.0.0",
"semver": "^5.1.0"
}
}

0 comments on commit 68f88ea

Please sign in to comment.