Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Test for IBM Pipelines #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .ibm/pipelines/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Install the ibmcloud cli,
# install the plugins passed as parameters
# and connect to the Cloud
# Env vars:
# API_KEY: IBM Cloud API Key
# IBM_REGION: IBM Cloud region
install_ibmcloud() {
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
for plugin in "$@"
do
ibmcloud plugin install -f "${plugin}"
done
ibmcloud login --apikey "${API_KEY}" -r "${IBM_REGION}"
}

install_kubectl() {
curl -sLO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl
mv kubectl /usr/local/bin/
}

install_oc() {
curl -sLO https://raw.githubusercontent.com/cptmorgan-rh/install-oc-tools/master/install-oc-tools.sh > /dev/null
chmod +x install-oc-tools.sh
./install-oc-tools.sh --latest 4.7
}

install_gh() {
curl -sLO https://github.com/cli/cli/releases/download/v2.1.0/gh_2.1.0_linux_amd64.deb
apt install ./gh_2.1.0_linux_amd64.deb
}

# Save the logs from the file passed as parameter #1
# and send a message to GitHub PR using parameter #2 as name of test
# Env vars:
# IBM_RESOURCE_GROUP: Resource group of the Cloud ObjectStorage
# IBM_COS: Cloud Object Storage containing the bucket on which to save logs
# IBM_BUCKET: Bucket name on which to save logs
save_logs() {
LOGFILE="$1"
NAME="$2"
apt update
apt install jq colorized-logs --yes

ansi2html < "/tmp/${LOGFILE}" > "/tmp/${LOGFILE}.html"
ansi2txt < "/tmp/${LOGFILE}" > "/tmp/${LOGFILE}.txt"

ibmcloud target -g "${IBM_RESOURCE_GROUP}"
CRN=$(ibmcloud resource service-instance ${IBM_COS} --output json | jq -r .[0].guid)
ibmcloud cos config crn --crn "${CRN}"

ibmcloud cos upload --bucket "${IBM_BUCKET}" --key "${LOGFILE}.html" --file "/tmp/${LOGFILE}.html"
ibmcloud cos upload --bucket "${IBM_BUCKET}" --key "${LOGFILE}.txt" --file "/tmp/${LOGFILE}.txt"

echo -n ${GITHUB_TOKEN} | gh auth login --with-token
BASE_URL="https://s3.${IBM_REGION}.cloud-object-storage.appdomain.cloud/${IBM_BUCKET}"
cat <<EOF | gh pr comment ${GIT_PR_NUMBER} --body-file -
${NAME} finished.
View logs: [TXT](${BASE_URL}/${LOGFILE}.txt) [HTML](${BASE_URL}/${LOGFILE}.html)
EOF
}
25 changes: 25 additions & 0 deletions .ibm/pipelines/kubernetes-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

LOGFILE="pr-${GIT_PR_NUMBER}-kubernetes-tests-${BUILD_NUMBER}"

source .ibm/pipelines/functions.sh

install_ibmcloud cloud-object-storage kubernetes-service

ibmcloud ks cluster config --cluster "${IBM_KUBERNETES_ID}" --admin

install_kubectl

(
set -e
make install
make test-integration-devfile
make test-e2e-devfile
make test-cmd-project
) |& tee "/tmp/${LOGFILE}"
RESULT=${PIPESTATUS[0]}

install_gh
save_logs "${LOGFILE}" "Kubernetes Tests"

exit ${RESULT}
27 changes: 27 additions & 0 deletions .ibm/pipelines/openshift-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

LOGFILE="pr-${GIT_PR_NUMBER}-openshift-tests-${BUILD_NUMBER}"

source .ibm/pipelines/functions.sh

install_oc

oc login -u apikey -p "${API_KEY}" "${IBM_OPENSHIFT_ENDPOINT}"

(
set -e
make install
make test-integration
make test-integration-devfile
make test-operator-hub
make test-cmd-login-logout
make test-cmd-project
make test-e2e-devfile
) |& tee "/tmp/${LOGFILE}"
RESULT=${PIPESTATUS[0]}

install_ibmcloud cloud-object-storage
install_gh
save_logs "${LOGFILE}" "OpenShift Tests"

exit ${RESULT}
19 changes: 19 additions & 0 deletions .ibm/pipelines/unit-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

LOGFILE="pr-${GIT_PR_NUMBER}-unit-tests-${BUILD_NUMBER}"

source .ibm/pipelines/functions.sh

(
set -e
make goget-tools
make validate
make test
) |& tee "/tmp/$LOGFILE"
RESULT=${PIPESTATUS[0]}

install_ibmcloud cloud-object-storage
install_gh
save_logs "${LOGFILE}" "Unit Tests"

exit ${RESULT}