-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port multiversion test into main EOS pipeline.
- Loading branch information
1 parent
c8517b3
commit 9f558be
Showing
5 changed files
with
220 additions
and
23 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 |
---|---|---|
@@ -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)) |
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 |
---|---|---|
@@ -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 |
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