@@ -6,62 +6,172 @@ set -x
66# Exit on error
77set -e
88
9+ # GitHub user
10+ REPO_OWNER=" minishift"
11+ REPO_NAME=" minishift-centos-iso"
12+
13+ # #######################################################
14+ # Exit with message on failure of last executed command
15+ # Arguments:
16+ # $1 - Exit code of last executed command
17+ # $2 - Error message
18+ # #######################################################
19+ function exit_on_failure() {
20+ if [[ " $1 " != 0 ]]; then
21+ echo " $2 "
22+ exit 1
23+ fi
24+ }
25+
926# Source environment variables of the jenkins slave
1027# that might interest this worker.
11- if [ -e " jenkins-env" ]; then
12- cat jenkins-env \
13- | grep -E " (JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY)=" \
14- | sed ' s/^/export /g' \
15- > ~ /.jenkins-env
16- source ~ /.jenkins-env
17- fi
28+ function load_jenkins_vars() {
29+ if [ -e " jenkins-env" ]; then
30+ cat jenkins-env \
31+ | grep -E " (JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY|GITHUB_TOKEN|JOB_NAME|RELEASE_VERSION)=" \
32+ | sed ' s/^/export /g' \
33+ > ~ /.jenkins-env
34+ source ~ /.jenkins-env
35+ fi
36+
37+ echo ' CICO: Jenkins ENVs loaded'
38+ }
39+
40+ function install_required_packages() {
41+ # Install EPEL repo
42+ yum -y install epel-release
43+ # Get all the deps in
44+ yum -y install make \
45+ git \
46+ curl \
47+ kvm \
48+ qemu-kvm \
49+ libvirt \
50+ python-requests \
51+ libvirt-devel \
52+ git \
53+ jq \
54+ gcc \
55+ https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.rpm
56+
57+ echo ' CICO: Required packages installed'
58+ }
59+
60+ function create_required_files() {
61+ mkdir -p /opt/fedora
62+ cp -r * /opt/fedora
63+ cd /opt/fedora
64+ }
65+
66+ function start_libvirt() {
67+ systemctl start libvirtd
68+ }
69+
70+ function install_vagrant_plugin() {
71+ vagrant plugin install vagrant-libvirt
72+ vagrant plugin install vagrant-sshfs
73+ }
74+
75+ function vagrant_up_and_destroy() {
76+ vagrant up
77+ vagrant destroy -f || true
78+ }
79+
80+ function setup_kvm_machine_driver() {
81+ curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-centos7 > /usr/local/bin/docker-machine-driver-kvm && \
82+ chmod +x /usr/local/bin/docker-machine-driver-kvm
83+ }
84+
85+ function perform_artifacts_upload() {
86+ rm -rf build/bin # Don't upload bin folder
87+ set +x
88+
89+ # For PR build, GIT_BRANCH is set to branch name other than origin/master
90+ if [[ " $GIT_BRANCH " = " origin/master" ]]; then
91+ # http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
92+ mkdir -p minishift-centos-iso/master/$BUILD_NUMBER /
93+ cp build/* minishift-centos-iso/master/$BUILD_NUMBER /
94+ RSYNC_PASSWORD=
$1 rsync -a --relative minishift-centos-iso/master/
$BUILD_NUMBER /
[email protected] ::minishift/
95+ echo " Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER} /${REPO_NAME} /master/$BUILD_NUMBER ."
96+ else
97+ # http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
98+ mkdir -p minishift-centos-iso/pr/$ghprbPullId /
99+ cp build/* minishift-centos-iso/pr/$ghprbPullId /
100+ RSYNC_PASSWORD=
$1 rsync -a --relative minishift-centos-iso/pr/
$ghprbPullId /
[email protected] ::minishift/
101+ echo " Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER} /${REPO_NAME} /pr/$ghprbPullId ."
102+ fi
103+ }
104+
105+ function create_release_commit() {
106+ # Create master branch as git clone in CI doesn't create it
107+ git checkout -b master
108+ # Bump version and commit
109+ sed -i " s|VERSION=.*|VERSION=$RELEASE_VERSION |" Makefile
110+ git add Makefile
111+ git commit -m " cut v$RELEASE_VERSION "
112+ git push https://$REPO_OWNER :$GITHUB_TOKEN @github.com/$REPO_OWNER /$REPO_NAME master
113+ }
114+
115+ function add_release_notes() {
116+ release_id=$( curl -s " https://api.github.com/repos/${REPO_OWNER} /${REPO_NAME} /releases" | jq --arg release " v$RELEASE_VERSION " -r ' .[] | if .name == $release then .id else empty end' )
117+
118+ if [[ " $release_id " != " " ]]; then
119+ MILESTONE_ID=` curl -s https://api.github.com/repos/minishift/${REPO_NAME} /milestones? state=all | jq --arg version " v$RELEASE_VERSION " -r ' .[] | if .title == $version then .number else empty end' `
120+
121+ if [[ " $MILESTONE_ID " != " " ]]; then
122+ # Generate required json payload for release note
123+ ./scripts/release/issue-list.sh -r $REPO_NAME -m $MILESTONE_ID | jq -Rn ' inputs + "\n"' | jq -s ' {body: add }' > json_payload.json
124+ # Add release notes
125+ curl -H " Content-Type: application/json" -H " Authorization: token $GITHUB_TOKEN " \
126+ --data @json_payload.json https://api.github.com/repos/${REPO_OWNER} /${REPO_NAME} /releases/$release_id
127+
128+ echo " Release notes of Minishift CentOS ISO v$RELEASE_VERSION has been successfully updated. Find the release notes here https://github.com/${REPO_OWNER} /${REPO_NAME} /releases/tag/v$RELEASE_VERSION ."
129+ else
130+ echo " Failed to get milestone ID for Minishift CentOS ISO v$RELEASE_VERSION . Use manual approach to update the release notes here https://github.com/${REPO_OWNER} /${REPO_NAME} /releases/tag/v$RELEASE_VERSION ."
131+ fi
132+ else
133+ return 1
134+ fi
135+ }
136+
137+ function perform_release() {
138+ create_release_commit
139+ exit_on_failure " $? " " Unable to create release commit."
140+
141+ make release
142+ exit_on_failure " $? " " Failed to release Minishift CentOS ISO v$RELEASE_VERSION . Try to release manually."
143+ echo " Minishift CentOS ISO v$RELEASE_VERSION has been successfully released. Find the latest release here https://github.com/$REPO_OWNER /$REPO_NAME /releases/tag/v$RELEASE_VERSION ."
144+
145+ add_release_notes;
146+ exit_on_failure " $? " " Failed to update release notes of Minishift CentOS ISO v$RELEASE_VERSION . Try to manually update the release notes here - https://github.com/$REPO_OWNER /$REPO_NAME /releases/tag/v$RELEASE_VERSION ."
147+ }
148+
149+ # Execution starts here
150+ load_jenkins_vars
151+ install_required_packages
152+ create_required_files
153+ start_libvirt
154+ install_vagrant_plugin
155+ vagrant_up_and_destroy
156+ setup_kvm_machine_driver
157+
158+ # Set Terminal
159+ export TERM=xterm-256color
160+ # Add git a/c identity
161+ git config --global user.email
" [email protected] " 162+ git config --global user.name " Minishift Bot"
163+
164+ # Build ISO and test
165+ make test
166+
167+ # Retrieve password for rsync
168+ CICO_PASS=$( echo $CICO_API_KEY | cut -d' -' -f1-2)
169+ # Export GITHUB_ACCESS_TOKEN to prevent Github rate limit and push to master during release job
170+ export GITHUB_ACCESS_TOKEN=$GITHUB_TOKEN
18171
19- # Get all the deps in
20- yum -y install \
21- make \
22- git \
23- epel-release \
24- livecd-tools \
25- curl \
26- docker \
27- parted \
28- kvm \
29- qemu-kvm \
30- libvirt
31-
32- # Start Libvirt
33- sudo systemctl start libvirtd
34-
35- # Install Avocado
36- sudo curl https://repos-avocadoproject.rhcloud.com/static/avocado-el.repo -o /etc/yum.repos.d/avocado.repo
37- sudo yum install -y avocado
38-
39- # Setup test drivers
40- curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.7.0/docker-machine-driver-kvm > /usr/local/bin/docker-machine-driver-kvm && \
41- chmod +x /usr/local/bin/docker-machine-driver-kvm
42-
43- # Prepare ISO for testing
44- make centos_iso
45-
46- # Let's test with showing log enabled
47- SHOW_LOG=--show-job-log make test
48-
49- # On reaching successfully at this point, upload artifacts
50- PASS=$( echo $CICO_API_KEY | cut -d' -' -f1-2)
51-
52- rm -rf build/bin # Don't upload bin folder
53- set +x
54- # For PR build, GIT_BRANCH is set to branch name other than origin/master
55- if [[ " $GIT_BRANCH " = " origin/master" ]]; then
56- # http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
57- mkdir -p minishift-centos-iso/master/$BUILD_NUMBER /
58- cp build/* minishift-centos-iso/master/$BUILD_NUMBER /
59- RSYNC_PASSWORD=
$PASS rsync -a --relative minishift-centos-iso/master/
$BUILD_NUMBER /
[email protected] ::minishift/
60- echo " Find Artifacts here http://artifacts.ci.centos.org/minishift/minishift-centos-iso/master/$BUILD_NUMBER ."
172+ if [[ " $JOB_NAME " = " minishift-centos-iso-release" ]]; then
173+ perform_release
61174else
62- # http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
63- mkdir -p minishift-centos-iso/pr/$ghprbPullId /
64- cp build/* minishift-centos-iso/pr/$ghprbPullId /
65- RSYNC_PASSWORD=
$PASS rsync -a --relative minishift-centos-iso/pr/
$ghprbPullId /
[email protected] ::minishift/
66- echo " Find Artifacts here http://artifacts.ci.centos.org/minishift/minishift-centos-iso/pr/$ghprbPullId ."
175+ # Runs for both PR and master jobs
176+ perform_artifacts_upload $CICO_PASS
67177fi
0 commit comments