This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,414 additions
and
1,158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# Abort script on first failure | ||
set -e | ||
|
||
function deploy() { | ||
if [ "$1" != "porcelain" ]; | ||
then | ||
echo "Executing Maven deploy (${TRAVIS_BRANCH})..." | ||
mvn clean deploy -B -Dcodebase.directory=$(pwd) -Dcoverage.reports.dir=$(pwd)/target/all --settings config/src/main/resources/ci/settings.xml | ||
else | ||
echo "Skipped Maven deploy (${TRAVIS_BRANCH}): Porcelain" | ||
fi | ||
} | ||
|
||
function install() { | ||
if [ "$1" != "porcelain" ]; | ||
then | ||
echo "Executing Maven install (${TRAVIS_BRANCH})..." | ||
mvn clean install -B -Dcoverage.reports.dir=$(pwd)/target/all --settings config/src/main/resources/ci/settings.xml | ||
else | ||
echo "Skipped Maven install (${TRAVIS_BRANCH}): Porcelain" | ||
fi | ||
} | ||
|
||
function runBuild() { | ||
mode=$1 | ||
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; | ||
then | ||
case "${TRAVIS_BRANCH}" in | ||
master | develop ) deploy "$mode";; | ||
feature\/* ) install "$mode";; | ||
* ) install "$mode";; | ||
esac | ||
else | ||
install "$mode" | ||
fi | ||
} | ||
|
||
function skipBuild() { | ||
echo "Skipping build..." | ||
} | ||
|
||
if [ "${DEBUG}" = "trace" ]; | ||
then | ||
set -x | ||
fi | ||
|
||
case "${CI}" in | ||
skip ) skipBuild ;; | ||
porcelain ) runBuild porcelain ;; | ||
* ) runBuild "$1" ;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#!/bin/bash | ||
# Avoid aborting script on failure | ||
set +e | ||
|
||
function logCheckResults() { | ||
case "${DEBUG}" in | ||
trace | verbose ) | ||
echo "-> Trace:" | ||
cat log.txt | ||
echo "-> Response:" | ||
cat data.txt | ||
;; | ||
* ) | ||
: | ||
;; | ||
esac | ||
} | ||
|
||
function checkWithCurl() { | ||
if [ "${DEBUG}" = "verbose" ]; | ||
then | ||
curl --version | ||
fi | ||
curl --head --silent --verbose --connect-timeout 5 "$1" > data.txt 2> log.txt | ||
error=$? | ||
logCheckResults | ||
return "$error" | ||
} | ||
|
||
function checkWithWget() { | ||
if [ "${DEBUG}" = "verbose" ]; | ||
then | ||
wget --version | ||
fi | ||
# Write response (and headers) to 'data.txt', (verbose) activity to 'log.txt' | ||
# including additional debug entries (e.g., requests and responses), with a | ||
# generic timeout of 5s, and retry only once. | ||
# In addition, discard the additional output (both standard and error) | ||
wget --output-document=data.txt --output-file=log.txt --verbose --debug --timeout=5 --tries 1 --save-headers "$1" > error.log 2>&1 | ||
error=$? | ||
if [ "$error" != "0" ]; | ||
then | ||
# If a failure happens, but the server sent a response... | ||
if [ "$(grep -c "response begin" log.txt)" -gt 0 ] | ||
then | ||
# ... we extract the response from the log... | ||
from=$(awk '/response begin/{ print NR; exit }' log.txt) | ||
to=$(awk '/response end/{ print NR; exit }' log.txt) | ||
head -n $((to - 1)) log.txt | tail -n $((to - from - 1)) > data.txt | ||
# ... and clear the failure status. | ||
error=0 | ||
fi | ||
fi | ||
logCheckResults | ||
return "$error" | ||
} | ||
|
||
function checkSonarQubeServer() { | ||
echo "Checking SonarQube Server..." | ||
|
||
case "${CHECKER}" in | ||
curl ) checkWithCurl "$1";; | ||
* ) checkWithWget "$1";; | ||
esac | ||
|
||
error=$? | ||
if [ "$error" = "0" ]; | ||
then | ||
status=$(head -n 1 data.txt | awk '{print $2}') | ||
if [ "$status" != "200" ]; | ||
then | ||
echo "SonarQube Server is not available (response status code: $status)" | ||
error=1 | ||
fi | ||
else | ||
echo "Could not connect to SonarQube Server: " | ||
cat log.txt | ||
error=2 | ||
fi | ||
rm data.txt | ||
rm log.txt | ||
return "$error" | ||
} | ||
|
||
function analyzeBranch() { | ||
checkSonarQubeServer "$1" | ||
if [ "$?" = "0" ]; | ||
then | ||
if [ "$2" != "porcelain" ]; | ||
then | ||
echo "Executing SonarQube analysis (${TRAVIS_BRANCH})..." | ||
# If SSL network failures happen, execute the analysis with -Djavax.net.debug=all | ||
mvn sonar:sonar -B -Dsonar.branch="$TRAVIS_BRANCH" -Dcoverage.reports.dir="$(pwd)/target/all" --settings config/src/main/resources/ci/settings.xml | ||
else | ||
echo "Skipped SonarQube analysis (${TRAVIS_BRANCH}): Porcelain" | ||
fi | ||
else | ||
echo "Skipped SonarQube analysis (${TRAVIS_BRANCH})" | ||
fi | ||
} | ||
|
||
function skipBranchAnalysis() { | ||
echo "Skipped SonarQube analysis (${TRAVIS_BRANCH}): Non Q.A. branch" | ||
} | ||
|
||
function skipPullRequestAnalysis() { | ||
echo "Skipped SonarQube analysis (${TRAVIS_BRANCH}): Pull request" | ||
} | ||
|
||
function skipBuild() { | ||
echo "Skipping build..." | ||
} | ||
|
||
function skipSonarQubeAnalysis() { | ||
echo "Skipping SonarQube analysis..." | ||
} | ||
|
||
function runSonarQubeAnalysis() { | ||
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; | ||
then | ||
case "${TRAVIS_BRANCH}" in | ||
master | develop ) analyzeBranch "$1" "$2";; | ||
feature\/* ) analyzeBranch "$1" "$2";; | ||
* ) skipBranchAnalysis ;; | ||
esac | ||
else | ||
skipPullRequestAnalysis | ||
fi | ||
} | ||
|
||
if [ "${DEBUG}" = "trace" ]; | ||
then | ||
set -x | ||
fi | ||
|
||
server=http://www.smartdeveloperhub.org/sonar/ | ||
|
||
case "${CI}" in | ||
skip ) skipBuild ;; | ||
noqa ) skipSonarQubeAnalysis ;; | ||
porcelain ) runSonarQubeAnalysis "$server" porcelain ;; | ||
* ) runSonarQubeAnalysis "$server" "$1" ;; | ||
esac | ||
|
||
set +x | ||
|
||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/bin/bash | ||
# Abort script on first failure | ||
set -e | ||
|
||
function backupMavenRepo() { | ||
if [ "$1" != "porcelain" ]; | ||
then | ||
mkdir /tmp/cache-trick | ||
mv "$HOME/.m2/repository/org/smartdeveloperhub" /tmp/cache-trick/ | ||
else | ||
echo "Skipped Maven Repo backup" | ||
fi | ||
} | ||
|
||
function restoreMavenRepo() { | ||
if [ "$1" != "porcelain" ]; | ||
then | ||
mv /tmp/cache-trick/smartdeveloperhub "$HOME/.m2/repository/org/" | ||
else | ||
echo "Skipped Maven Repo restoration" | ||
fi | ||
} | ||
|
||
function fail() { | ||
echo "ERROR: Unknown command '${1}'." | ||
return 1 | ||
} | ||
|
||
function beginSensibleBlock() { | ||
set +x | ||
if [ "${DEBUG}" = "trace" ]; | ||
then | ||
set -v | ||
fi | ||
} | ||
|
||
function endSensibleBlock() { | ||
set +v | ||
if [ "${DEBUG}" = "trace" ]; | ||
then | ||
set -x | ||
fi | ||
} | ||
|
||
function unshallowGitRepository() { | ||
if [[ -a .git/shallow ]]; | ||
then | ||
echo "- Unshallowing Git repository..." | ||
set +e | ||
git fetch --unshallow --verbose; | ||
set -e | ||
error=$? | ||
if [[ $error -ne 0 ]]; | ||
then | ||
echo "Unshallowing failed with $error status code" | ||
git --version | ||
return $error | ||
fi | ||
fi | ||
} | ||
|
||
function prepareBuild() { | ||
endSensibleBlock | ||
|
||
if [ "$#" != "2" ]; | ||
then | ||
echo "ERROR: No encryption password specified." | ||
return 2 | ||
fi | ||
|
||
if [ "$1" != "porcelain" ]; | ||
then | ||
beginSensibleBlock | ||
|
||
echo "Preparing Build's bill-of-materials..." | ||
echo "- Decrypting private key..." | ||
openssl aes-256-cbc -pass pass:"$2" -in config/src/main/resources/ci/secring.gpg.enc -out local.secring.gpg -d | ||
echo "- Decrypting public key..." | ||
openssl aes-256-cbc -pass pass:"$2" -in config/src/main/resources/ci/pubring.gpg.enc -out local.pubring.gpg -d | ||
|
||
endSensibleBlock | ||
|
||
unshallowGitRepository | ||
else | ||
echo "Skipped preparation of the Build's bill-of-materials" | ||
fi | ||
} | ||
|
||
function runUtility() { | ||
beginSensibleBlock | ||
|
||
mode=$1 | ||
if [ "$mode" != "porcelain" ]; | ||
then | ||
mode=${CI} | ||
fi | ||
|
||
check=$1 | ||
shift | ||
if [ "$check" = "porcelain" ]; | ||
then | ||
action=$1 | ||
shift | ||
else | ||
action=$check | ||
fi | ||
|
||
case "$action" in | ||
backup-maven-repo ) | ||
endSensibleBlock | ||
backupMavenRepo "$mode" "$@" | ||
;; | ||
restore-maven-repo) | ||
endSensibleBlock | ||
restoreMavenRepo "$mode" "$@" | ||
;; | ||
prepare-build-bom ) | ||
prepareBuild "$mode" "$@" | ||
;; | ||
* ) | ||
endSensibleBlock | ||
fail "$action" | ||
;; | ||
esac | ||
} | ||
|
||
function skipBuild() { | ||
echo "Skipping build..." | ||
} | ||
|
||
case "${CI}" in | ||
skip ) skipBuild ;; | ||
* ) runUtility "$@" ;; | ||
esac |
Oops, something went wrong.