Skip to content

Commit

Permalink
Merge pull request #2331 from civicrm/staging
Browse files Browse the repository at this point in the history
Sync master with staging
  • Loading branch information
davialexandre authored Nov 27, 2017
2 parents 45b2bc2 + 9f011bd commit 3dcb560
Show file tree
Hide file tree
Showing 605 changed files with 25,539 additions and 12,793 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ hrabsence/build

# Exclude sass cache from all extension directories
*/.sass-cache/

# Exclude temporary JS build files
**/js/build.tmp.js

# Exclude all JS source map files
*.js.map
106 changes: 67 additions & 39 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pipeline {
CIVICRM_EXT_ROOT = "$DRUPAL_MODULES_ROOT/civicrm/tools/extensions"
WEBURL = "http://jenkins.compucorp.co.uk:8900"
ADMIN_PASS = credentials('CVHR_ADMIN_PASS')
KARMA_TESTS_REPORT_FOLDER = "reports/js-karma"
PHPUNIT_TESTS_REPORT_FOLDER = "reports/phpunit"
}

stages {
Expand All @@ -30,6 +32,12 @@ pipeline {

// Test build tools
sh 'amp test'

// Cleanup old Karma test reports
sh "rm -f $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER/* || true"

// Cleanup old PHPUnit test reports
sh "rm -f $WORKSPACE/$PHPUNIT_TESTS_REPORT_FOLDER/* || true"
}
}

Expand All @@ -43,7 +51,13 @@ pipeline {
def buildBranch = params.CIVIHR_BRANCH != '' ? params.CIVIHR_BRANCH : env.CHANGE_TARGET != null ? env.CHANGE_TARGET : env.BRANCH_NAME != null ? env.BRANCH_NAME : 'staging'

// Build site with CV Buildkit
sh "civibuild create ${params.CIVIHR_BUILDNAME} --type hr16 --civi-ver 4.7.22 --hr-ver ${buildBranch} --url $WEBURL --admin-pass $ADMIN_PASS"
sh "civibuild create ${params.CIVIHR_BUILDNAME} --type hr17 --civi-ver 4.7.27 --hr-ver ${buildBranch} --url $WEBURL --admin-pass $ADMIN_PASS"
sh """
cd $DRUPAL_MODULES_ROOT/civicrm
wget -O attachments.patch https://gist.githubusercontent.com/davialexandre/199b3ebb2c69f43c07dde0f51fb02c8b/raw/0f11edad8049c6edddd7f865c801ecba5fa4c052/attachments-4.7.27.patch
patch -p1 -i attachments.patch
rm attachments.patch
"""

// Change git remote of civihr ext to support dev version of Jenkins pipeline
changeCivihrGitRemote()
Expand Down Expand Up @@ -107,43 +121,37 @@ pipeline {
tools: [
[
$class: 'JUnitType',
pattern: 'reports/phpunit/*.xml'
pattern: env.PHPUNIT_TESTS_REPORT_FOLDER + '/*.xml'
]
]
])
}
}
}

/* Testing JS */
// TODO: Execute test and Generate report without stop on fail
stage('Testing JS: Install NPM in parallel') {
/* Testing JS */
stage('Testing JS: Install JS packages') {
steps {
script {
def extensionTestings = [:]

// Install NPM jobs
for (extension in listCivihrExtensions()) {
if(!extension.hasJSTests) {
continue;
}

extensionTestings[extension.shortName] = {
installNPM(extension)
if(extension.hasJSTests) {
installJSPackages(extension);
}
}
// Running install NPM jobs in parallel
parallel extensionTestings
}
}
}

stage('Testing JS: Test JS in sequent') {
stage('Testing JS: Test JS') {
steps {
script {
// Testing JS in sequent
for (extension in listCivihrExtensions) {
if(extension.hasJSTests) {
// This is necessary to avoid an additional loop
// in each extension folder to read the XML.
// After each test we move the reports to this folder
sh "mkdir -p $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER"

for (extension in listCivihrExtensions()) {
if (extension.hasJSTests) {
testJS(extension)
}
}
Expand All @@ -160,19 +168,12 @@ pipeline {
failureThreshold: '1',
unstableNewThreshold: '1',
unstableThreshold: '1'
],
[
$class: 'SkippedThreshold',
failureNewThreshold: '0',
failureThreshold: '0',
unstableNewThreshold: '0',
unstableThreshold: '0'
]
],
tools: [
[
$class: 'JUnitType',
pattern: 'reports/js-karma/*.xml'
pattern: env.KARMA_TESTS_REPORT_FOLDER + '/*.xml'
]
]
])
Expand Down Expand Up @@ -244,18 +245,19 @@ def testPHPUnit(java.util.LinkedHashMap extension) {

sh """
cd $CIVICRM_EXT_ROOT/civihr/${extension.folder}
phpunit4 --log-junit $WORKSPACE/reports/phpunit/result-phpunit_${extension.shortName}.xml || true
phpunit4 --testsuite="Unit Tests" --log-junit $WORKSPACE/$PHPUNIT_TESTS_REPORT_FOLDER/result-phpunit_${extension
.shortName}.xml
"""
}

/*
* Installk JS Testing
* Install JS Testing
* params: extension
*/
def installNPM(java.util.LinkedHashMap extension) {
def installJSPackages(java.util.LinkedHashMap extension) {
sh """
cd $CIVICRM_EXT_ROOT/civihr/${extension.folder}
npm install || true
yarn || true
"""
}

Expand All @@ -266,9 +268,14 @@ def installNPM(java.util.LinkedHashMap extension) {
def testJS(java.util.LinkedHashMap extension) {
echo "JS Testing ${extension.name}"

// We cannot change, using CLI arguments, the place where
// karma stores the junit XML report, so the last command
// here copies the XML from the extension folder to the
// workspace, where Jenkins will read it
sh """
cd $CIVICRM_EXT_ROOT/civihr/${extension.folder}
gulp test || true
gulp test --reporters junit,progress || true
mv test-reports/*.xml $WORKSPACE/$KARMA_TESTS_REPORT_FOLDER/ || true
"""
}

Expand Down Expand Up @@ -296,21 +303,28 @@ def listCivihrExtensions() {
name: 'Job Roles',
shortName: 'hrjobroles',
folder: 'com.civicrm.hrjobroles',
hasJSTests: false,
hasJSTests: true,
hasPHPTests: true
],
[
name: 'Contacts Access Rights',
shortName: 'contactaccessrights',
folder: 'contactaccessrights',
hasJSTests: false,
hasJSTests: true,
hasPHPTests: true
],
[
name: 'Contacts Summary',
shortName: 'contactsummary',
folder: 'contactsummary',
hasJSTests: true,
hasPHPTests: false
],
[
name: 'Job Contracts',
shortName: 'hrjobcontract',
folder: 'hrjobcontract',
hasJSTests: false,
hasJSTests: true,
hasPHPTests: true
],
[
Expand All @@ -325,14 +339,14 @@ def listCivihrExtensions() {
shortName: 'hrreport',
folder: 'hrreport',
hasJSTests: false,
hasPHPTests: true
hasPHPTests: false
],
[
name: 'HR UI',
shortName: 'hrui',
folder: 'hrui',
hasJSTests: false,
hasPHPTests: true
hasPHPTests: false
],
[
name: 'HR Visa',
Expand All @@ -341,6 +355,13 @@ def listCivihrExtensions() {
hasJSTests: false,
hasPHPTests: true
],
[
name: 'Reqangular',
shortName: 'reqangular',
folder: 'org.civicrm.reqangular',
hasJSTests: true,
hasPHPTests: false
],
[
name: 'HRCore',
shortName: 'hrcore',
Expand All @@ -352,7 +373,7 @@ def listCivihrExtensions() {
name: 'Leave and Absences',
shortName: 'hrleaveandabsences',
folder: 'uk.co.compucorp.civicrm.hrleaveandabsences',
hasJSTests: false,
hasJSTests: true,
hasPHPTests: true
],
[
Expand All @@ -361,6 +382,13 @@ def listCivihrExtensions() {
folder: 'uk.co.compucorp.civicrm.hrsampledata',
hasJSTests: false,
hasPHPTests: true
],
[
name: 'Emergency Contacts ',
shortName: 'hremergency',
folder: 'org.civicrm.hremergency',
hasJSTests: false,
hasPHPTests: true
]
]
}
48 changes: 26 additions & 22 deletions bin/build-dao.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,27 @@
# entities (Civi's and your extension), and finally it copies your extension's
# DAOs to your extension CRM/NAMESPACE/DAO directory.

CIVIROOT="$1"
EXTROOT="$2"
NAMESPACE="$3"
EXTSRCDIR="$EXTROOT/CRM/$NAMESPACE"
EXTDAODIR="$EXTSRCDIR/DAO"
XMLBUILD="$EXTROOT/build/xml/schema"

function validateOptions() {
if [ -z "$CIVIROOT" -o ! -d "$CIVIROOT" ]; then
echo "ERROR: invalid civicrm-dir: [$CIVIROOT]"
printUsage
function validatePaths() {
if [ -z "$CIVIROOT" ]; then
echo "ERROR: civicrm-dir couldn't be found"
exit
fi

if [ -z "$EXTROOT" -o ! -d "$EXTROOT" ]; then
echo "ERROR: invalid extension-dir: [$EXTROOT]"
printUsage
if [ -z "$EXTROOT" ]; then
echo "ERROR: it was not possible to find a path to $1"
exit
fi

if [ -z "$NAMESPACE" -o ! -d "$EXTSRCDIR" ]; then
echo "ERROR: invalid namespace: [$NAMESPACE]"
printUsage
if [ -z "$NAMESPACE" ]; then
echo "ERROR: it was not possible for find the namespace of $1"
exit
fi
}

function printUsage() {
echo ""
echo "usage: $0 <civicrm-dir> <extension-dir> <namespace>"
echo "example: $0 /var/www/drupal/sites/all/modules/civicrm /var/www/drupal/sites/all/modules/civicrm/tools/extensions/civihr/your-extension YourNamespace"
echo "usage: $0 <extension-key>"
echo "example: $0 key.of.your.extension"
exit
}

Expand All @@ -62,11 +55,11 @@ function buildDAO() {
popd > /dev/null

[ ! -d "$EXTDAODIR" ] && mkdir -p "$EXTDAODIR"
cp -f "$CIVIROOT/CRM/$NAMESPACE/DAO"/* "$EXTDAODIR/"
cp -f "$CIVIROOT/$NAMESPACE/DAO"/* "$EXTDAODIR/"
}

function cleanup() {
for DIR in "$EXTROOT/build" "$CIVIROOT/CRM/$NAMESPACE" ; do
for DIR in "$EXTROOT/build" "$CIVIROOT/$NAMESPACE" ; do
if [ -e "$DIR" ]; then
echo "Cleanup: removing $DIR"
rm -rf "$DIR"
Expand All @@ -78,7 +71,18 @@ function cleanup() {
##############################
## Main
set -e
validateOptions

if [ -z $1 ]; then
printUsage
fi

CIVIROOT=`cv path -d '[civicrm.root]'`
EXTROOT=`cv path -x $1`
NAMESPACE=`cd $EXTROOT && civix info:get -x civix/namespace`
EXTDAODIR="$EXTROOT/$NAMESPACE/DAO"
XMLBUILD="$EXTROOT/build/xml/schema"

validatePaths
cleanup
buildXmlSchema
buildDAO
Expand Down
Loading

0 comments on commit 3dcb560

Please sign in to comment.