forked from fabric8-ui/fabric8-planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcico_build_deploy.sh
executable file
·129 lines (105 loc) · 4.39 KB
/
cico_build_deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# This file is supposed to be executed by CICO build (ci.centos.org/view/Devtools/)
# It will:
# 1. Build fabric8-planner
# 2. Update Tag on github
# 3. Push fabric8-planner to npmjs.org
# 4. Create PR with new planner version on fabric8-npm-dependencies repo
# 5. Merge the PR on fabric8-npm-dependencies repo
# 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
. cico_setup.sh
setup;
# Build fabric8-planner image
docker build -t fabric8-planner-builder .
# User root is required to run webdriver-manager update.
# This shouldn't be a problem for CI containers
# Chrome crashes on low size of /dev/shm. We need the --shm-size=256m flag.
CID=$(docker run --detach=true \
--shm-size=256m \
-u $(shell id -u $(USER)):$(shell id -g $(USER)) \
-v $(pwd)/fabric8-ui-dist:/home/fabric8/fabric8-planner/fabric8-ui-dist:Z \
--cap-add=SYS_ADMIN \
-t fabric8-planner-builder)
build_planner;
run_unit_tests;
run_functional_tests;
build_fabric8_ui;
# 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 {
# extract version number from latest git tag
new_planner_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_planner_version=$( grep fabric8-planner package.json \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[:space:]' )
echo "New Planner version:" $new_planner_version
echo "Current Planner version:" $current_planner_version
if [ "$new_planner_version" == "$current_planner_version" ]; then
echo "Skippping as fabric8-planner is already on version $new_planner_version"
exit 0
fi
git config --global user.email [email protected]
git config --global user.name fabric8-release
message="fix(version): update package.json fabric8-planner to ${new_planner_version}"
updatePackageJSONVersion "$new_planner_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 fabric8-planner's version in package.json file
function updatePackageJSONVersion {
local f="package.json"
local p="fabric8-planner"
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
}