This repository has been archived by the owner on Jan 31, 2021. It is now read-only.
forked from minishift/minishift-fedora-iso
-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
f2797da
commit 65268b6
Showing
5 changed files
with
332 additions
and
187 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 |
---|---|---|
|
@@ -6,62 +6,172 @@ set -x | |
# Exit on error | ||
set -e | ||
|
||
# GitHub user | ||
REPO_OWNER="minishift" | ||
REPO_NAME="minishift-centos-iso" | ||
|
||
######################################################## | ||
# Exit with message on failure of last executed command | ||
# Arguments: | ||
# $1 - Exit code of last executed command | ||
# $2 - Error message | ||
######################################################## | ||
function exit_on_failure() { | ||
if [[ "$1" != 0 ]]; then | ||
echo "$2" | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Source environment variables of the jenkins slave | ||
# that might interest this worker. | ||
if [ -e "jenkins-env" ]; then | ||
cat jenkins-env \ | ||
| grep -E "(JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY)=" \ | ||
| sed 's/^/export /g' \ | ||
> ~/.jenkins-env | ||
source ~/.jenkins-env | ||
fi | ||
function load_jenkins_vars() { | ||
if [ -e "jenkins-env" ]; then | ||
cat jenkins-env \ | ||
| grep -E "(JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY|GITHUB_TOKEN|JOB_NAME|RELEASE_VERSION)=" \ | ||
| sed 's/^/export /g' \ | ||
> ~/.jenkins-env | ||
source ~/.jenkins-env | ||
fi | ||
|
||
echo 'CICO: Jenkins ENVs loaded' | ||
} | ||
|
||
function install_required_packages() { | ||
# Install EPEL repo | ||
yum -y install epel-release | ||
# Get all the deps in | ||
yum -y install make \ | ||
git \ | ||
curl \ | ||
kvm \ | ||
qemu-kvm \ | ||
libvirt \ | ||
python-requests \ | ||
libvirt-devel \ | ||
git \ | ||
jq \ | ||
gcc \ | ||
https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.rpm | ||
|
||
echo 'CICO: Required packages installed' | ||
} | ||
|
||
function create_required_files() { | ||
mkdir -p /opt/fedora | ||
cp -r * /opt/fedora | ||
cd /opt/fedora | ||
} | ||
|
||
function start_libvirt() { | ||
systemctl start libvirtd | ||
} | ||
|
||
function install_vagrant_plugin() { | ||
vagrant plugin install vagrant-libvirt | ||
vagrant plugin install vagrant-sshfs | ||
} | ||
|
||
function vagrant_up_and_destroy() { | ||
vagrant up | ||
vagrant destroy -f || true | ||
} | ||
|
||
function setup_kvm_machine_driver() { | ||
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 && \ | ||
chmod +x /usr/local/bin/docker-machine-driver-kvm | ||
} | ||
|
||
function perform_artifacts_upload() { | ||
rm -rf build/bin # Don't upload bin folder | ||
set +x | ||
|
||
# For PR build, GIT_BRANCH is set to branch name other than origin/master | ||
if [[ "$GIT_BRANCH" = "origin/master" ]]; then | ||
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working | ||
mkdir -p minishift-centos-iso/master/$BUILD_NUMBER/ | ||
cp build/* minishift-centos-iso/master/$BUILD_NUMBER/ | ||
RSYNC_PASSWORD=$1 rsync -a --relative minishift-centos-iso/master/$BUILD_NUMBER/ [email protected]::minishift/ | ||
echo "Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER}/${REPO_NAME}/master/$BUILD_NUMBER ." | ||
else | ||
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working | ||
mkdir -p minishift-centos-iso/pr/$ghprbPullId/ | ||
cp build/* minishift-centos-iso/pr/$ghprbPullId/ | ||
RSYNC_PASSWORD=$1 rsync -a --relative minishift-centos-iso/pr/$ghprbPullId/ [email protected]::minishift/ | ||
echo "Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER}/${REPO_NAME}/pr/$ghprbPullId ." | ||
fi | ||
} | ||
|
||
function create_release_commit() { | ||
# Create master branch as git clone in CI doesn't create it | ||
git checkout -b master | ||
# Bump version and commit | ||
sed -i "s|VERSION=.*|VERSION=$RELEASE_VERSION|" Makefile | ||
git add Makefile | ||
git commit -m "cut v$RELEASE_VERSION" | ||
git push https://$REPO_OWNER:$GITHUB_TOKEN@github.com/$REPO_OWNER/$REPO_NAME master | ||
} | ||
|
||
function add_release_notes() { | ||
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') | ||
|
||
if [[ "$release_id" != "" ]]; then | ||
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'` | ||
|
||
if [[ "$MILESTONE_ID" != "" ]]; then | ||
# Generate required json payload for release note | ||
./scripts/release/issue-list.sh -r $REPO_NAME -m $MILESTONE_ID | jq -Rn 'inputs + "\n"' | jq -s '{body: add }' > json_payload.json | ||
# Add release notes | ||
curl -H "Content-Type: application/json" -H "Authorization: token $GITHUB_TOKEN" \ | ||
--data @json_payload.json https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/$release_id | ||
|
||
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." | ||
else | ||
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." | ||
fi | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
function perform_release() { | ||
create_release_commit | ||
exit_on_failure "$?" "Unable to create release commit." | ||
|
||
make release | ||
exit_on_failure "$?" "Failed to release Minishift CentOS ISO v$RELEASE_VERSION. Try to release manually." | ||
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." | ||
|
||
add_release_notes; | ||
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." | ||
} | ||
|
||
# Execution starts here | ||
load_jenkins_vars | ||
install_required_packages | ||
create_required_files | ||
start_libvirt | ||
install_vagrant_plugin | ||
vagrant_up_and_destroy | ||
setup_kvm_machine_driver | ||
|
||
# Set Terminal | ||
export TERM=xterm-256color | ||
# Add git a/c identity | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Minishift Bot" | ||
|
||
# Build ISO and test | ||
make test | ||
|
||
# Retrieve password for rsync | ||
CICO_PASS=$(echo $CICO_API_KEY | cut -d'-' -f1-2) | ||
# Export GITHUB_ACCESS_TOKEN to prevent Github rate limit and push to master during release job | ||
export GITHUB_ACCESS_TOKEN=$GITHUB_TOKEN | ||
|
||
# Get all the deps in | ||
yum -y install \ | ||
make \ | ||
git \ | ||
epel-release \ | ||
livecd-tools \ | ||
curl \ | ||
docker \ | ||
parted \ | ||
kvm \ | ||
qemu-kvm \ | ||
libvirt | ||
|
||
# Start Libvirt | ||
sudo systemctl start libvirtd | ||
|
||
# Install Avocado | ||
sudo curl https://repos-avocadoproject.rhcloud.com/static/avocado-el.repo -o /etc/yum.repos.d/avocado.repo | ||
sudo yum install -y avocado | ||
|
||
# Setup test drivers | ||
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 && \ | ||
chmod +x /usr/local/bin/docker-machine-driver-kvm | ||
|
||
# Prepare ISO for testing | ||
make centos_iso | ||
|
||
# Let's test with showing log enabled | ||
SHOW_LOG=--show-job-log make test | ||
|
||
# On reaching successfully at this point, upload artifacts | ||
PASS=$(echo $CICO_API_KEY | cut -d'-' -f1-2) | ||
|
||
rm -rf build/bin # Don't upload bin folder | ||
set +x | ||
# For PR build, GIT_BRANCH is set to branch name other than origin/master | ||
if [[ "$GIT_BRANCH" = "origin/master" ]]; then | ||
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working | ||
mkdir -p minishift-centos-iso/master/$BUILD_NUMBER/ | ||
cp build/* minishift-centos-iso/master/$BUILD_NUMBER/ | ||
RSYNC_PASSWORD=$PASS rsync -a --relative minishift-centos-iso/master/$BUILD_NUMBER/ [email protected]::minishift/ | ||
echo "Find Artifacts here http://artifacts.ci.centos.org/minishift/minishift-centos-iso/master/$BUILD_NUMBER ." | ||
if [[ "$JOB_NAME" = "minishift-centos-iso-release" ]]; then | ||
perform_release | ||
else | ||
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working | ||
mkdir -p minishift-centos-iso/pr/$ghprbPullId/ | ||
cp build/* minishift-centos-iso/pr/$ghprbPullId/ | ||
RSYNC_PASSWORD=$PASS rsync -a --relative minishift-centos-iso/pr/$ghprbPullId/ [email protected]::minishift/ | ||
echo "Find Artifacts here http://artifacts.ci.centos.org/minishift/minishift-centos-iso/pr/$ghprbPullId ." | ||
# Runs for both PR and master jobs | ||
perform_artifacts_upload $CICO_PASS | ||
fi |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.