Skip to content

Commit

Permalink
Port multiversion test into main EOS pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottarnette committed Jan 22, 2020
1 parent c8517b3 commit 9f558be
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 23 deletions.
37 changes: 17 additions & 20 deletions .cicd/generate-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ EOF
echo ''
fi
done
# Execute multiversion test
if ( [[ ! $PINNED == false ]] ); then
cat <<EOF
- label: ":pipeline: Multiversion Test"
command:
- "buildkite-agent artifact download build.tar.gz . --step ':ubuntu: Ubuntu 18.04 - Build' && tar -xzf build.tar.gz"
- ./.cicd/test.sh .cicd/multiversion.sh
env:
IMAGE_TAG: "ubuntu-18.04-pinned"
PLATFORM_TYPE: "pinned"
agents:
queue: "$BUILDKITE_TEST_AGENT_QUEUE"
timeout: ${TIMEOUT:-30}
skip: ${SKIP_LINUX}${SKIP_UBUNTU_18_04}${SKIP_MULTIVERSION_TEST}
EOF
fi
# trigger eosio-lrt post pr
if [[ -z $BUILDKITE_TRIGGERED_FROM_BUILD_ID && $TRIGGER_JOB == "true" ]]; then
if ( [[ ! $PINNED == false ]] ); then
Expand All @@ -458,26 +475,6 @@ if [[ -z $BUILDKITE_TRIGGERED_FROM_BUILD_ID && $TRIGGER_JOB == "true" ]]; then
SKIP_WASM_SPEC_TESTS: "true"
PINNED: "${PINNED}"
EOF
fi
fi
# trigger multiversion post pr
if [[ -z $BUILDKITE_TRIGGERED_FROM_BUILD_ID && $TRIGGER_JOB = "true" ]]; then
if ( [[ ! $PINNED == false ]] ); then
cat <<EOF
- label: ":pipeline: Trigger Multiversion Test"
trigger: "eos-multiversion-tests"
async: true
build:
message: "Triggered by $BUILDKITE_PIPELINE_SLUG build $BUILDKITE_BUILD_NUMBER"
commit: "${BUILDKITE_COMMIT}"
branch: "${BUILDKITE_BRANCH}"
env:
BUILDKITE_PULL_REQUEST: "${BUILDKITE_PULL_REQUEST}"
BUILDKITE_PULL_REQUEST_BASE_BRANCH: "${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
BUILDKITE_PULL_REQUEST_REPO: "${BUILDKITE_PULL_REQUEST_REPO}"
BUILDKITE_TRIGGERED_FROM_BUILD_URL: "${BUILDKITE_BUILD_URL}"
EOF
fi
fi
Expand Down
138 changes: 138 additions & 0 deletions .cicd/helpers/multi_eos_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/env python

import configparser
import os
import re
import requests
import shutil
import subprocess
import sys
import tarfile


def is_tag(ref):
regex = re.compile('v[0-9]+\.[0-9]+\..*')
return regex.match(ref)

def get_commit_for_branch(branch):
commit = None
r = requests.get('https://api.github.com/repos/EOSIO/eos/git/refs/heads/{}'.format(branch))
if r.status_code == 200:
commit = r.json().get('object').get('sha')

return commit

def get_commit_for_tag(tag):
commit = None
r = requests.get('https://api.github.com/repos/EOSIO/eos/git/refs/tags/{}'.format(tag))
if r.status_code == 200:
commit = r.json().get('object').get('sha')

return commit

def sanitize_label(label):
invalid = [' ', '..', '.', '/', '~', '=']
for c in invalid:
label = label.replace(c, '-')

return label.strip('-')

CURRENT_COMMIT = os.environ.get('BUILDKITE_COMMIT')
BK_TOKEN = os.environ.get('BUILDKITE_API_KEY')
if not BK_TOKEN:
sys.exit('Buildkite token not set')
headers = {
'Authorization': 'Bearer {}'.format(BK_TOKEN)
}

try:
shutil.rmtree('builds')
except OSError:
pass
os.mkdir('builds')

existing_build_found = False
if CURRENT_COMMIT:
print 'Attempting to get build directory for this branch ({})...'.format(CURRENT_COMMIT)
r = requests.get('https://api.buildkite.com/v2/organizations/EOSIO/pipelines/eosio/builds?commit={}'.format(CURRENT_COMMIT), headers=headers)
if r.status_code == 200:
resp = r.json()
if resp:
build = resp.pop(0)
for job in build.get('jobs'):
job_name = job.get('name')
if job_name == ':ubuntu: 18.04 Build':
dir_r = requests.get(job.get('artifacts_url'), headers=headers)
if dir_r.status_code == 200:
download_url = dir_r.json().pop().get('download_url')
if download_url:
dl_r = requests.get(download_url, headers=headers)
open('current_build.tar.gz', 'wb').write(dl_r.content)
tar = tarfile.open('current_build.tar.gz')
tar.extractall(path='builds/current')
tar.close()
os.remove('current_build.tar.gz')
existing_build_found = True
else:
print 'No builds found for this branch ({})'.format(CURRENT_COMMIT)

if not os.path.exists('../tests/multiversion.conf'):
sys.exit('Unable to find config file')

commits = {}
config = configparser.ConfigParser()
config.read('../tests/multiversion.conf')
for item in config.items('eosio'):
label = sanitize_label(item[0])
if is_tag(item[1]):
commits[label] = get_commit_for_tag(item[1])
elif get_commit_for_branch(item[1]):
commits[label] = get_commit_for_branch(item[1])
else:
commits[label] = item[1]

PWD = os.getcwd()
config_path = '../tests/multiversion_paths.conf'
if existing_build_found:
config_path = '{0}/builds/current/build/tests/multiversion_paths.conf'.format(PWD)

with open(config_path, 'w') as fp:
fp.write('[eosio]\n')
for label in commits.keys():
fp.write('{}={}/builds/{}/build\n'.format(label, PWD, label))

print 'Getting build data...'
artifact_urls = {}
for label, commit in commits.items():
r = requests.get('https://api.buildkite.com/v2/organizations/EOSIO/pipelines/eosio/builds?commit={}'.format(commit), headers=headers)
if r.status_code == 200:
resp = r.json()
if resp:
build = resp.pop(0)
for job in build.get('jobs'):
job_name = job.get('name')
if job_name == ':ubuntu: 18.04 Build':
artifact_urls[label] = job.get('artifacts_url')
else:
print 'No builds found for {}'.format(label)
else:
print r.text
sys.exit('Something went wrong getting build data for {}'.format(label))

print 'Downloading and extracting build directories...'
for label, artifact_url in artifact_urls.items():
print ' +++ {}'.format(label)
r = requests.get(artifact_url, headers=headers)
if r.status_code == 200:
download_url = r.json().pop().get('download_url')
if download_url:
dl_r = requests.get(download_url, headers=headers)
open('{}_build.tar.gz'.format(label), 'wb').write(dl_r.content)
tar = tarfile.open('{}_build.tar.gz'.format(label))
tar.extractall(path='builds/{}'.format(label))
tar.close()
os.remove('{}_build.tar.gz'.format(label))
else:
sys.exit('Unable to get artifact download url for {}'.format(label))
else:
sys.exit('Something went wrong getting artifact data for {}'.format(label))
61 changes: 61 additions & 0 deletions .cicd/multiversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
set -eo pipefail # exit on failure of any "simple" command (excludes &&, ||, or | chains)
# variables
GIT_ROOT="$(dirname $BASH_SOURCE[0])/.."
cd $GIT_ROOT
echo "+++ $([[ "$BUILDKITE" == 'true' ]] && echo ':evergreen_tree: ')Configuring Environment"
[[ "$PIPELINE_CONFIG" == '' ]] && export PIPELINE_CONFIG='pipeline.json'
[[ "$RAW_PIPELINE_CONFIG" == '' ]] && export RAW_PIPELINE_CONFIG='pipeline.jsonc'
[[ ! -d $GIT_ROOT/eos_multiversion_builder ]] && mkdir $GIT_ROOT/eos_multiversion_builder
# pipeline config
echo 'Reading pipeline configuration file...'
[[ -f "$RAW_PIPELINE_CONFIG" ]] && cat "$RAW_PIPELINE_CONFIG" | grep -Po '^[^"/]*("((?<=\\).|[^"])*"[^"/]*)*' | jq -c .\"eos-multiversion-tests\" > "$PIPELINE_CONFIG"
if [[ -f "$PIPELINE_CONFIG" ]]; then
[[ "$DEBUG" == 'true' ]] && cat "$PIPELINE_CONFIG" | jq .
# export environment
if [[ "$(cat "$PIPELINE_CONFIG" | jq -r '.environment')" != 'null' ]]; then
for OBJECT in $(cat "$PIPELINE_CONFIG" | jq -r '.environment | to_entries | .[] | @base64'); do
KEY="$(echo $OBJECT | base64 --decode | jq -r .key)"
VALUE="$(echo $OBJECT | base64 --decode | jq -r .value)"
[[ ! -v $KEY ]] && export $KEY="$VALUE"
done
fi
# export multiversion.conf
echo '[eosio]' > multiversion.conf
for OBJECT in $(cat "$PIPELINE_CONFIG" | jq -r '.configuration | .[] | @base64'); do
echo "$(echo $OBJECT | base64 --decode)" >> multiversion.conf # outer echo adds '\n'
done
mv -f $GIT_ROOT/multiversion.conf $GIT_ROOT/tests
elif [[ "$DEBUG" == 'true' ]]; then
echo 'Pipeline configuration file not found!'
echo "PIPELINE_CONFIG = \"$PIPELINE_CONFIG\""
echo "RAW_PIPELINE_CONFIG = \"$RAW_PIPELINE_CONFIG\""
echo '$ pwd'
pwd
echo '$ ls'
ls
echo 'Skipping that step...'
fi
# multiversion
cd $GIT_ROOT/eos_multiversion_builder
echo 'Downloading other versions of nodeos...'
python2.7 $GIT_ROOT/.cicd/helpers/multi_eos_docker.py
cd $GIT_ROOT
cp $GIT_ROOT/tests/multiversion_paths.conf $GIT_ROOT/build/tests
cd $GIT_ROOT/build
# count tests
echo "+++ $([[ "$BUILDKITE" == 'true' ]] && echo ':microscope: ')Running Multiversion Test"
TEST_COUNT=$(ctest -N -L mixed_version_tests | grep -i 'Total Tests: ' | cut -d ':' -f 2 | awk '{print $1}')
if [[ $TEST_COUNT > 0 ]]; then
echo "$TEST_COUNT tests found."
else
echo "+++ $([[ "$BUILDKITE" == 'true' ]] && echo ':no_entry: ')ERROR: No tests registered with ctest! Exiting..."
exit 1
fi
# run tests
set +e # defer ctest error handling to end
echo "$ ctest -L mixed_version_tests --output-on-failure -T Test"
ctest -L mixed_version_tests --output-on-failure -T Test
EXIT_STATUS=$?
echo 'Done running multiversion test.'
exit $EXIT_STATUS
3 changes: 2 additions & 1 deletion .cicd/platforms/pinned/ubuntu-18.04-pinned.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ RUN apt-get update && \
apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y git make \
bzip2 automake libbz2-dev libssl-dev doxygen graphviz libgmp3-dev \
autotools-dev libicu-dev python2.7 python2.7-dev python3 python3-dev \
autotools-dev libicu-dev python2.7 python2.7-dev python3 \
python3-dev python-configparser python-requests python-pip \
autoconf libtool g++ gcc curl zlib1g-dev sudo ruby libusb-1.0-0-dev \
libcurl4-gnutls-dev pkg-config patch ccache vim-common jq
# build cmake.
Expand Down
4 changes: 2 additions & 2 deletions .cicd/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ if [[ $(uname) == 'Darwin' ]]; then # macOS
else # Linux
COMMANDS="$MOUNTED_DIR/$@"
. $HELPERS_DIR/file-hash.sh $CICD_DIR/platforms/$PLATFORM_TYPE/$IMAGE_TAG.dockerfile
echo "$ docker run --rm --init -v $(pwd):$MOUNTED_DIR $(buildkite-intrinsics) -e JOBS $FULL_TAG bash -c \"$COMMANDS\""
echo "$ docker run --rm --init -v $(pwd):$MOUNTED_DIR $(buildkite-intrinsics) -e JOBS -e BUILDKITE_API_KEY $FULL_TAG bash -c \"$COMMANDS\""
set +e # defer error handling to end
eval docker run --rm --init -v $(pwd):$MOUNTED_DIR $(buildkite-intrinsics) -e JOBS $FULL_TAG bash -c \"$COMMANDS\"
eval docker run --rm --init -v $(pwd):$MOUNTED_DIR $(buildkite-intrinsics) -e JOBS -e BUILDKITE_API_KEY $FULL_TAG bash -c \"$COMMANDS\"
EXIT_STATUS=$?
fi
# buildkite
Expand Down

0 comments on commit 9f558be

Please sign in to comment.