Browse Source

Merge branch 'fix/validate-jenkins-tests-behaviour' into 'develop'

Fix/validate jenkins tests behaviour

See merge request ecentrics/concordia!21
develop
Apostolos Fanakis 4 years ago
parent
commit
62557580b7
  1. 14
      docker/concordia-contracts/test-contracts.sh
  2. 2
      docker/env/ganache.test.env
  3. 78
      jenkins/Jenkinsfile

14
docker/concordia-contracts/test-contracts.sh

@ -3,11 +3,17 @@
export CHAIN_HOST="$TEST_CHAIN_HOST"
export CHAIN_PORT="$TEST_CHAIN_PORT"
yarn _eslint -f html -o /mnt/concordia/test-reports/concordia-contracts-eslint.html --no-color &&
(yarn _solhint >/mnt/concordia/test-reports/concordia-contracts-solhint.report) &&
(yarn test --network env >/mnt/concordia/test-reports/concordia-contracts-truffle-tests.report)
yarn _eslint -f html -o /mnt/concordia/test-reports/concordia-contracts-eslint.html --no-color
ESLINT_EXIT_STATUS=$?
if [ $? -eq 0 ]; then
yarn _solhint >/mnt/concordia/test-reports/concordia-contracts-solhint.report
SOLHINT_EXIT_STATUS=$?
yarn test --network env >/mnt/concordia/test-reports/concordia-contracts-truffle-tests.report
grep -qE failing /mnt/concordia/test-reports/concordia-contracts-truffle-tests.report
TRUFFLE_TEST_FAILING=$?
if [ $ESLINT_EXIT_STATUS -eq 0 ] && [ "$SOLHINT_EXIT_STATUS" -eq 0 ] && [ "$TRUFFLE_TEST_FAILING" -eq 1 ]; then
echo "TESTS RAN SUCCESSFULLY!"
exit 0
else

2
docker/env/ganache.test.env

@ -1,5 +1,5 @@
ACCOUNTS_NUMBER=5
ACCOUNTS_ETHER=1
ACCOUNTS_ETHER=100
MNEMONIC="myth like bonus scare over problem client lizard pioneer submit female collect"
HOST=0.0.0.0
PORT=8546

78
jenkins/Jenkinsfile

@ -1,6 +1,7 @@
#!groovy
def cleanSlateEnabled
def sanitizedBranchName
// Package change state
def appPackageChanged
@ -18,9 +19,7 @@ def sharedPackageVersion
// Docker images
def appImage
def appTestsImage
def contractsImage
def contractsTestsImage
def contractsProviderImage
def pinnerImage
@ -84,6 +83,7 @@ pipeline {
steps {
script {
cleanSlateEnabled = sh (script: "git log -1 | grep -qE 'ci: force'", returnStatus: true)
sanitizedBranchName = sh(script: 'echo $GIT_BRANCH | sed -e "s:.*/::g"', returnStdout: true).trim()
appPackageChanged = sh(script: 'bash ./jenkins/check_package_changed.sh app "$GIT_COMMIT" "$GIT_PREVIOUS_COMMIT"', returnStdout: true).trim()
contractsPackageChanged = sh(script: 'bash ./jenkins/check_package_changed.sh contracts "$GIT_COMMIT" "$GIT_PREVIOUS_COMMIT"', returnStdout: true).trim()
@ -111,44 +111,46 @@ pipeline {
stage('TEST CONTRACTS') {
steps {
script {
try {
def ganacheTestPort = sh(script: "bash ./jenkins/hash_build_properties.sh ${BRANCH_NAME} ${BUILD_NUMBER} | xargs bash ./jenkins/map_to_thousand.sh", returnStdout: true).trim()
def ganacheTestPort = sh(script: "bash ./jenkins/hash_build_properties.sh ${BRANCH_NAME} ${BUILD_NUMBER} | xargs bash ./jenkins/map_to_thousand.sh", returnStdout: true).trim()
def ganacheTestImage = docker.build(
"ecentrics/concordia-ganache",
"-f docker/ganache/Dockerfile \
./"
)
def ganacheTestImage = docker.build(
"ecentrics/concordia-ganache",
"-f docker/ganache/Dockerfile \
./"
)
docker.build(
"ecentrics/concordia-contracts-tests:${sanitizedBranchName}-v${contractsPackageVersion}-b${BUILD_NUMBER}-tests",
"-f docker/concordia-contracts/Dockerfile \
./ \
--target test \
--build-arg TZ=Europe/Athens"
)
sh 'docker network create --driver bridge concordia_ganache_test_network || true'
sh 'docker network create --driver bridge concordia_ganache_test_network || true'
ganacheTestImage.withRun("""-d -p 6${ganacheTestPort}:8546 \
ganacheTestImage.withRun("""-d -p 6${ganacheTestPort}:8546 \
--env-file=./jenkins/env/ganache.test.jenkins.env \
--name concordia-ganache-test-6${ganacheTestPort} \
--net=concordia_ganache_test_network""") { concordiaGanacheTest ->
contractsTestsImage = docker.build(
"ecentrics/concordia-contracts-tests:v${contractsPackageVersion}-b${BUILD_NUMBER}-tests",
"-f docker/concordia-contracts/Dockerfile \
./ \
--target test \
--build-arg TZ=Europe/Athens"
)
contractsTestsImage.run("""--rm \
-v ecentrics_janus_common:/mnt/concordia/test-reports/ \
--env-file=./jenkins/env/contracts.test.jenkins.env \
-e WEB3_HOST=concordia-ganache-test-6${ganacheTestPort} \
-e WEB3_PORT=6${ganacheTestPort} \
--net=concordia_ganache_test_network""")
try {
sh """docker run \
--rm \
-v ecentrics_janus_common:/mnt/concordia/test-reports/ \
--env-file=./jenkins/env/contracts.test.jenkins.env \
-e WEB3_HOST=concordia-ganache-test-6${ganacheTestPort} \
-e WEB3_PORT=6${ganacheTestPort} \
--net=concordia_ganache_test_network \
ecentrics/concordia-contracts-tests:${sanitizedBranchName}-v${contractsPackageVersion}-b${BUILD_NUMBER}-tests"""
} catch (e) {
error('Some tests failed!')
error('Aborting the build.')
throw e
} finally {
sh 'mkdir -p ./reports/${BUILD_NUMBER}/contracts'
sh 'find /mnt/janus/common/ -name "concordia-contracts-*" -exec cp \'{}\' ./reports/${BUILD_NUMBER}/contracts/ \\;'
}
} catch (e) {
error('Some tests failed!')
error('Aborting the build.')
throw e
}
}
}
@ -157,8 +159,8 @@ pipeline {
stage('TEST APP') {
steps {
script {
appTestsImage = docker.build(
"ecentrics/concordia-app:v${appPackageVersion}-b${BUILD_NUMBER}-tests",
docker.build(
"ecentrics/concordia-app:${sanitizedBranchName}-v${appPackageVersion}-b${BUILD_NUMBER}-tests",
"-f docker/concordia-app/Dockerfile \
./ \
--target test \
@ -166,15 +168,17 @@ pipeline {
)
try {
appTestsImage.run('--rm \
-v ecentrics_janus_common:/mnt/concordia/test-reports/')
sh 'mkdir -p ./reports/${BUILD_NUMBER}/app'
sh 'find /mnt/janus/common/ -name "concordia-app-*" -exec cp \'{}\' ./reports/${BUILD_NUMBER}/app/ \\;'
sh """docker run \
--rm \
-v ecentrics_janus_common:/mnt/concordia/test-reports/ \
ecentrics/concordia-app:${sanitizedBranchName}-v${appPackageVersion}-b${BUILD_NUMBER}-tests"""
} catch (e) {
error('Some tests failed!')
error('Aborting the build.')
throw e
} finally {
sh 'mkdir -p ./reports/${BUILD_NUMBER}/app'
sh 'find /mnt/janus/common/ -name "concordia-app-*" -exec cp \'{}\' ./reports/${BUILD_NUMBER}/app/ \\;'
}
}
}

Loading…
Cancel
Save