This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): update build to run on cico and not use fabric8-ci
- Loading branch information
1 parent
a35aa54
commit b9e6962
Showing
28 changed files
with
1,022 additions
and
135,666 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,68 +1,13 @@ | ||
#!/bin/bash | ||
|
||
# Show command before executing | ||
set -x | ||
set -ex | ||
|
||
# Exit on error | ||
set -e | ||
. cico_setup.sh | ||
|
||
# Export needed vars | ||
for var in BUILD_NUMBER BUILD_URL JENKINS_URL GIT_BRANCH GH_TOKEN NPM_TOKEN; do | ||
export $(grep ${var} jenkins-env | xargs) | ||
done | ||
export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00 | ||
install_dependencies | ||
|
||
# We need to disable selinux for now, XXX | ||
/usr/sbin/setenforce 0 | ||
run_unit_tests | ||
|
||
# Get all the deps in | ||
yum -y install docker | ||
yum clean all | ||
sed -i '/OPTIONS=.*/c\OPTIONS="--selinux-enabled --log-driver=journald --insecure-registry registry.ci.centos.org:5000"' /etc/sysconfig/docker | ||
service docker start | ||
build_project | ||
|
||
# Build builder image | ||
docker build -t ngx-base-builder -f Dockerfile.builder . | ||
mkdir -p dist && docker run --detach=true --name=ngx-base-builder -e "FABRIC8_WIT_API_URL=http://api.openshift.io/api/" -e JENKINS_URL -e GIT_BRANCH -e "CI=true" -e GH_TOKEN -e NPM_TOKEN -t -v $(pwd)/dist:/dist:Z ngx-base-builder | ||
|
||
# In order to run semantic-release we need a non detached HEAD, see https://github.com/semantic-release/semantic-release/issues/329 | ||
docker exec ngx-base-builder git checkout master | ||
# Try to fix up the git repo so that npm publish can build the gitHead ref in to package.json | ||
docker exec ngx-base-builder ./fix-git-repo.sh | ||
|
||
# Build almigty-ui | ||
docker exec ngx-base-builder npm install | ||
|
||
## Build prod | ||
docker exec ngx-base-builder npm run build | ||
|
||
## Exec functional tests | ||
docker exec ngx-base-builder ./run_unit_tests.sh | ||
|
||
if [ $? -eq 0 ]; then | ||
echo 'CICO: unit tests OK' | ||
else | ||
echo 'CICO: unit tests FAIL' | ||
exit 1 | ||
fi | ||
|
||
## Exec functional tests | ||
docker exec ngx-base-builder ./run_functional_tests.sh | ||
|
||
if [ $? -eq 0 ]; then | ||
echo 'CICO: functional tests OK' | ||
# Don't treat a publish failure as a build failure as this is confusing | ||
set +e | ||
# Publish to npm | ||
docker exec ngx-base-builder npm run semantic-release | ||
if [ $? -eq 0 ]; then | ||
echo 'CICO: module pushed to npmjs.com' | ||
exit 0 | ||
else | ||
echo 'CICO: module push to npmjs.com failed' | ||
exit 0 | ||
fi | ||
else | ||
echo 'CICO: functional tests FAIL' | ||
exit 1 | ||
fi | ||
release |
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,112 @@ | ||
#!/bin/bash | ||
# Show command before executing | ||
set -x | ||
|
||
# Exit on error | ||
set -e | ||
|
||
# This option sets the exit code of a pipeline to that of the rightmost command to exit with a | ||
# non-zero status, or to zero if all commands of the pipeline exit successfully. | ||
set -o pipefail | ||
|
||
function release() { | ||
# add .npmrc file to give permissions | ||
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/.npmrc | ||
|
||
npm whoami | ||
|
||
# Enable verbose output | ||
npm config set loglevel silly | ||
|
||
# check where we are | ||
git branch -va | ||
git remote -v | ||
# Build and Release Planner (It will update the tag on github and push fabric8-planner to npmjs.org) | ||
npm run semantic-release | ||
|
||
# create_merge_PR | ||
} | ||
|
||
# This function raises a PR against fabric8-npm-dependencies | ||
function create_merge_PR { | ||
# Fetch latest tags | ||
git pull --tags origin master | ||
# extract version number from latest git tag | ||
new_version=$(git tag --sort=-v:refname | head -1 | cut -d'v' -f 2) | ||
|
||
# Create PR on fabric8-npm-dependencies and merge it | ||
repo="fabric8-npm-dependencies" | ||
org="fabric8-ui" | ||
project="${org}/${repo}" | ||
baseUrl="https://api.github.com/repos" | ||
id=$(uuidgen) | ||
git clone "https://github.com/${project}.git" | ||
cd ${repo} && git checkout -b versionUpdate"${id}" | ||
|
||
# find fabric8-planner > extract version number > remove ", char > trim whitespacs | ||
current_version=$( grep ngx-login-client package.json \ | ||
| awk -F: '{ print $2 }' \ | ||
| sed 's/[",]//g' \ | ||
| tr -d '[:space:]' ) | ||
echo "New Login-Client version:" new_version | ||
echo "Current Login-Client version:" $current_version | ||
if [ "new_version" == "$current_version" ]; then | ||
echo "Skippping as ngx-login-client is already on version new_version" | ||
exit 0 | ||
fi | ||
|
||
git config --global user.email fabric8cd@gmail.com | ||
git config --global user.name fabric8-cd | ||
# Set authentication credentials to allow "git push" | ||
git remote set-url origin https://fabric8cd:${GH_TOKEN}@github.com/${project}.git | ||
|
||
message="fix(version): update package.json ngx-login-client to ${new_version}" | ||
updatePackageJSONVersion "$new_version" | ||
git add package.json | ||
git commit -m "${message}" | ||
git push origin versionUpdate"${id}" | ||
local body="{ | ||
\"title\": \"${message}\", | ||
\"head\": \"versionUpdate${id}\", | ||
\"base\": \"master\" | ||
}" | ||
|
||
apiUrl="${baseUrl}/${project}/pulls" | ||
echo "Creating PR for ${apiUrl}" | ||
PR_id=$(curl --silent -X POST -H "Authorization: Bearer $GH_TOKEN" -d "${body}" "${apiUrl}" \ | ||
| sed -n 's/.*"number": \(.*\),/\1/p' ) | ||
echo "Received PR id: ${PR_id}" | ||
|
||
# Wait for all CI checks on PR to be successful | ||
waitUntilSuccess "${PR_id}" "${project}" | ||
|
||
# Merge PR | ||
apiUrl="${baseUrl}/${project}/pulls/${PR_id}/merge" | ||
echo "Merging PR ${PR_id}" | ||
curl --silent -X PUT -H "Authorization: Bearer $GH_TOKEN" "${apiUrl}" | ||
} | ||
|
||
# Updates ngx-launcher's version in package.json file | ||
function updatePackageJSONVersion { | ||
local f="package.json" | ||
local p="ngx-login-client" | ||
local v=$1 | ||
sed -i -r "s/\"${p}\": \"[0-9][0-9]{0,2}.[0-9][0-9]{0,2}(.[0-9][0-9]{0,2})?(.[0-9][0-9]{0,2})?(-development)?\"/\"${p}\": \"${v}\"/g" ${f} | ||
} | ||
|
||
# Wait for all CI checks to pass | ||
function waitUntilSuccess { | ||
pr_id=$1 | ||
project=$2 | ||
ref=$( curl --silent -X GET https://api.github.com/repos/"${project}"/pulls/"${pr_id}" \ | ||
| sed -n 's/.*"ref": "\(.*\)",/\1/p' | head -1) # Extract "ref" value from the response | ||
status="NA" | ||
NEXT_WAIT_TIME=0 | ||
# Max wait 720 seconds | ||
until [ "$status" == "success" ] || [ $NEXT_WAIT_TIME -eq 7 ]; do | ||
status=$( curl --silent -X GET https://api.github.com/repos/"${project}"/commits/"${ref}"/status \ | ||
| sed -n 's/.*"state": "\(.*\)",/\1/p') # Extract "state" value from the response | ||
echo "Pull Request status: ${status}. Waiting to merge..." | ||
sleep $(( NEXT_WAIT_TIME++ )) | ||
done | ||
} |
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 |
---|---|---|
@@ -1,37 +1,12 @@ | ||
#!/bin/bash | ||
|
||
# Show command before executing | ||
set -x | ||
set -ex | ||
|
||
# Exit on error | ||
set -e | ||
. cico_setup.sh | ||
|
||
# We need to disable selinux for now, XXX | ||
/usr/sbin/setenforce 0 | ||
install_dependencies | ||
|
||
# Get all the deps in | ||
yum -y install \ | ||
docker \ | ||
make \ | ||
git | ||
service docker start | ||
run_unit_tests | ||
|
||
# Build builder image | ||
docker build -t ngx-base-builder -f Dockerfile.builder . | ||
mkdir -p dist && docker run --detach=true --name=ngx-base-builder -e "API_URL=http://demo.api.almighty.io/api/" -t -v $(pwd)/dist:/dist:Z ngx-base-builder | ||
build_project | ||
|
||
# Build almighty-ui | ||
docker exec ngx-base-builder npm install | ||
|
||
## Exec unit tests | ||
docker exec ngx-base-builder ./run_unit_tests.sh | ||
|
||
if [ $? -eq 0 ]; then | ||
echo 'CICO: unit tests OK' | ||
else | ||
echo 'CICO: unit tests FAIL' | ||
exit 1 | ||
fi | ||
|
||
## Exec functional tests | ||
docker exec ngx-base-builder ./run_functional_tests.sh |
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,87 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
load_jenkins_vars() { | ||
if [ -e "jenkins-env" ]; then | ||
cat jenkins-env \ | ||
| grep -E "(DEVSHIFT_TAG_LEN|DEVSHIFT_USERNAME|DEVSHIFT_PASSWORD|JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|RECOMMENDER_API_TOKEN|NPM_TOKEN|GH_TOKEN)=" \ | ||
| sed 's/^/export /g' \ | ||
> ~/.jenkins-env | ||
source ~/.jenkins-env | ||
|
||
echo "CICO: Jenkins environment variables loaded" | ||
fi | ||
} | ||
|
||
prep() { | ||
yum -y update | ||
yum -y install docker make gcc-c++ bzip2 fontconfig | ||
|
||
# Get and set up git v2.12 | ||
yum -y install centos-release-scl | ||
yum -y install sclo-git212.x86_64 | ||
export PATH=${PATH}:/opt/rh/sclo-git212/root/usr/bin/ | ||
|
||
# Get and set up Nodejs | ||
curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash - | ||
yum -y install nodejs | ||
} | ||
|
||
install_dependencies() { | ||
npm install; | ||
chmod +x /root/payload/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs | ||
|
||
# set up chrome for running tests | ||
cp config/google-chrome.repo /etc/yum.repos.d/google-chrome.repo | ||
yum install -y google-chrome-stable | ||
|
||
# Set the branch as it defaults to the branch 'origin/master' | ||
git checkout master | ||
export GIT_BRANCH=master | ||
# check where we are | ||
git branch -va | ||
git remote -v | ||
|
||
if [ $? -eq 0 ]; then | ||
echo 'CICO: npm install : OK' | ||
else | ||
echo 'CICO: npm install : FAIL' | ||
exit 1 | ||
fi | ||
} | ||
|
||
run_unit_tests() { | ||
# Set up logging | ||
LOGFILE=$(pwd)/unit_tests.log | ||
echo Using logfile $LOGFILE | ||
|
||
# Running npm test | ||
echo Running unit tests... | ||
npm run test:unit | tee $LOGFILE ; UNIT_TEST_RESULT=${PIPESTATUS[0]} | ||
|
||
if [ $? -eq 0 ]; then | ||
echo 'CICO: unit tests OK' | ||
else | ||
echo 'CICO: unit tests FAIL' | ||
exit 2 | ||
fi | ||
} | ||
|
||
build_project() { | ||
# run build | ||
npm run build | ||
|
||
if [ $? -eq 0 ]; then | ||
echo 'CICO: build OK' | ||
else | ||
echo 'CICO: build FAIL' | ||
exit 1 | ||
fi | ||
} | ||
|
||
. cico_release.sh | ||
|
||
load_jenkins_vars | ||
|
||
prep |
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,6 @@ | ||
[google-chrome] | ||
name=google-chrome - \$basearch | ||
baseurl=http://dl.google.com/linux/chrome/rpm/stable/\$basearch | ||
enabled=1 | ||
gpgcheck=1 | ||
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub |
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
Oops, something went wrong.