diff --git a/.ci/README.md b/.ci/README.md index e646bc3..06f845b 100644 --- a/.ci/README.md +++ b/.ci/README.md @@ -1,5 +1,5 @@ # homebrew-eosio -The [homebrew-eosio](https://buildkite.com/EOSIO/homebrew-eosio) pipeline runs on the `master` branch of the [homebrew-eosio](https://github.com/EOSIO/homebrew-eosio) repo to verify that the [EOSIO](https://github.com/EOSIO/eos) packages we are providing via the [Homebrew](https://brew.sh) package manager on macOS are functional. +The [homebrew-eosio](https://buildkite.com/EOSIO/homebrew-eosio) pipeline verifies that [EOSIO](https://github.com/EOSIO/eos) [Homebrew](https://brew.sh) packages for macOS are functional.
See More @@ -16,9 +16,15 @@ The [homebrew-eosio](https://buildkite.com/EOSIO/homebrew-eosio) pipeline runs o This pipeline will parse the [eosio.rb](https://github.com/EOSIO/homebrew-eosio/blob/master/eosio.rb) ruby file in the root of this repo and generate a pipeline step to run a clean Anka VM for each macOS version found. Each step performs the following: 1. Verify the SHA-256 of the bottle attached to the release on GitHub at `root_url` in the ruby file matches the hash defined in the ruby file 1. Tap EOSIO - ```bash - brew tap EOSIO/eosio - ``` + 1. On master branch: + ```bash + brew tap EOSIO/eosio + ``` + 1. On any non-master branch: + ```bash + + brew tap + ``` 1. Install EOSIO ```bash brew install eosio @@ -27,21 +33,16 @@ This pipeline will parse the [eosio.rb](https://github.com/EOSIO/homebrew-eosio/ ```bash which nodeos ``` -1. Invoke the [full-version-label.sh](https://github.com/EOSIO/eos/blob/master/tests/full-version-label.sh) test on that binary +1. Invoke the [full-version-label.sh](https://github.com/EOSIO/eos/blob/master/tests/full-version-label.sh) test on that binary. All of these must pass for the Buildkite job step to pass. # Configuration -There are no user-configurable options for this pipeline at this time. The functionality of this pipeline is based entirely on the `eosio.rb` ruby file in the root of [homebrew-eosio](https://github.com/EOSIO/homebrew-eosio) on the `master` branch. +There are no user-configurable options for this pipeline at this time. ## Variables There are no configurable variables intended for the end-user at this time. -Because this pipeline runs against published release packages, it doesn't make sense to run it on feature branches. If you try, the pipeline fails with a useful error message. We did create a flag to bypass this so engineers can test changes to the CI code on feature branches. -```bash -DEBUG='true|false' # run this pipeline on feature branches, for testing CI changes -``` - # See Also - Buildkite - [DevDocs](https://github.com/EOSIO/devdocs/wiki/Buildkite) diff --git a/.ci/anka.yml b/.ci/anka.yml index d1cf57e..5f2c746 100644 --- a/.ci/anka.yml +++ b/.ci/anka.yml @@ -1,7 +1,7 @@ - label: ":darwin: macOS ${OS_STYLIZED} - ${LABEL}" - command: - - "git clone --recursive --single-branch --branch '${BUILDKITE_BRANCH}' '${BUILDKITE_REPO}'" - - "./${BUILDKITE_PIPELINE_SLUG}/.ci/test.sh" + command: | + git clone --recursive --single-branch --branch '${BUILDKITE_BRANCH}' '${BUILDKITE_REPO}' + if [[ "${BUILDKITE_BRANCH}" == 'master' ]] ; then ./${BUILDKITE_PIPELINE_SLUG}/.ci/test-prod-tap.sh ; else ./${BUILDKITE_PIPELINE_SLUG}/.ci/test-local-tap.sh ; fi env: BIN: "${BIN}" BOTTLE: "${BOTTLE}" diff --git a/.ci/libfunctions.sh b/.ci/libfunctions.sh new file mode 100755 index 0000000..4fc583b --- /dev/null +++ b/.ci/libfunctions.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +function perform { + echo "$ $1" + eval $1 +} + +function test_bottle { + echo '+++ :hash: Verify Package Hash - SHA-256' + pushd "$BUILDKITE_PIPELINE_SLUG" # same as repo name + perform "curl -fsSL -o './$BOTTLE' '$ROOT_URL/$BOTTLE'" + FILE_HASH="openssl dgst -sha256 '$BOTTLE'" + echo "$ $FILE_HASH" + BOTTLE_HASH="$(eval $FILE_HASH | tee >(cat - >&9) | awk '{print $2}')" + RUBY_LINE="cat '$RUBY_FILE' | grep 'sha256' | grep '$OS'" + echo "$ $RUBY_LINE" + RUBY_HASH="$(eval $RUBY_LINE | tee >(cat - >&9) | awk '{print $3}' | tr -d '"')" + if [[ "$BOTTLE_HASH" == "$RUBY_HASH" ]]; then + echo "Pass: $BOTTLE_HASH = $RUBY_HASH" + else + echo "+++ :x: Failed to Verify Bottle Hash" + FAIL_MSG="$BOTTLE hash $BOTTLE_HASH ≠ $RUBY_FILE::$OS hash $RUBY_HASH"'!' + echo "FAILURE: $FAIL_MSG" + [[ "$BUILDKITE" == 'true' ]] && echo "**FAILURE:** $FAIL_MSG" | buildkite-agent annotate --style 'error' --context "wrong-hash-$OS" + exit 2 + fi + mv $BOTTLE .. + popd +} + +function test_binary_exists { + WHICH_BIN="which '$BIN'" + echo "$ $WHICH_BIN" + export BUILD_ROOT="$(eval $WHICH_BIN | tee >(cat - >&9) | sed "s_/bin/${BIN}__g")" + if [[ -z "$BUILD_ROOT" ]]; then + FAIL_MSG="'$BIN' binary not found after homebrew installation on $OS_STYLIZED"'!' + echo "FAILURE: $FAIL_MSG" + [[ "$BUILDKITE" == 'true' ]] && echo "**FAILURE:** $FAIL_MSG" | tr "'" '`' | buildkite-agent annotate --style 'error' --context "no-binary-$OS" + exit 3 + else + echo "Found '$BIN' at \"$BUILD_ROOT/bin/$BIN\"." + fi +} + +function test_full_version_matches { + echo "Using git tag '$REPO_UNDER_TEST:$GIT_TAG'." + perform "git clone --quiet --recursive --single-branch --branch '${GIT_TAG}' '${REPO_UNDER_TEST}' > /dev/null" + pushd $(echo ${REPO_UNDER_TEST} | sed 's/.*\/\(.*\)\.git/\1/') + + export BUILDKITE_COMMIT="$(git rev-parse HEAD)" # override homebrew-eosio commit with eos tag commit + echo "Found git commit '$REPO_UNDER_TEST:$BUILDKITE_COMMIT'." + unset BUILDKITE_TAG + export CMAKE_SOURCE_DIR="$(pwd)" + echo "Set CMAKE_SOURCE_DIR to \"$CMAKE_SOURCE_DIR\"." + TEST="./tests/full-version-label.sh '$GIT_TAG'" + echo "$ $TEST" + set +e + eval $TEST + EXIT_STATUS="$?" + set -e + if [[ "$EXIT_STATUS" != '0' ]]; then + FAIL_MSG="Version label test failed on $OS_STYLIZED"'!' + echo "FAILURE: $FAIL_MSG" + [[ "$BUILDKITE" == 'true' ]] && echo "**FAILURE:** $FAIL_MSG" | buildkite-agent annotate --style 'error' --context "test-failure-$OS" + exit "$EXIT_STATUS" + fi + popd +} diff --git a/.ci/pipeline-upload.sh b/.ci/pipeline-upload.sh index b08052f..f77cc78 100755 --- a/.ci/pipeline-upload.sh +++ b/.ci/pipeline-upload.sh @@ -23,17 +23,6 @@ if [[ "$BUILDKITE" == 'true' && "$RETRY" == '0' ]]; then elif [[ "$BUILDKITE" == 'true' ]]; then printf "Skipping \033]1339;url=$DOCS_URL;content=documentation\a upload for job retry number $RETRY.\n" >&2 fi -# only run on master -if [[ "$BUILDKITE_BRANCH" != 'master' && "$DEBUG" != 'true' ]]; then - ERROR_MSG='This pipeline currently does nothing on branches besides `master`!' - echo "ERROR: $ERROR_MSG" | tr -d '`' | cat >&2 - [[ "$BUILDKITE" == 'true' && "$RETRY" == '0' ]] && echo "**ERROR:** $ERROR_MSG" | buildkite-agent annotate --style 'error' --context 'not-master' - exit 1 -elif [[ "$DEBUG" == 'true' ]]; then - WARNING_MSG='Running on non-`master` branch because `DEBUG` is set to "true".' - echo "WARNING: $WARNING_MSG" | tr -d '`' | cat >&2 - [[ "$BUILDKITE" == 'true' && "$RETRY" == '0' ]] && echo "**WARNING:** $WARNING_MSG" | tr '"' '`' | buildkite-agent annotate --style 'warning' --context 'not-master' -fi echo '+++ :yaml: Generating Pipeline Steps' >&2 # yaml header cat <&1 # enable tee to write to STDOUT as a file +[[ -n "$BOTTLE" ]] && test_bottle + +echo '+++ :beer: Homebrew Tap and Install' +perform 'brew update' +perform "brew tap eosio/eosio ${BUILDKITE_PIPELINE_SLUG}" +perform "brew install '$PACKAGE'" + +echo '+++ :label: Full Version Label Test' +test_binary_exists +test_full_version_matches + +echo '--- :white_check_mark: Done!' +echo 'Done.' diff --git a/.ci/test-prod-tap.sh b/.ci/test-prod-tap.sh new file mode 100755 index 0000000..1671e35 --- /dev/null +++ b/.ci/test-prod-tap.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -eo pipefail +. "${0%/*}/libfunctions.sh" + +echo '--- :evergreen_tree: Configuring Environment' +exec 9>&1 # enable tee to write to STDOUT as a file +[[ -n "$BOTTLE" ]] && test_bottle + +echo '+++ :beer: Homebrew Tap and Install' +perform 'brew update' +perform "brew tap '$TAP'" +perform "brew install '$PACKAGE'" + +echo '+++ :label: Full Version Label Test' +test_binary_exists +test_full_version_matches + +echo '--- :white_check_mark: Done!' +echo 'Done.' diff --git a/.ci/test.sh b/.ci/test.sh deleted file mode 100755 index 69a1102..0000000 --- a/.ci/test.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash -set -eo pipefail -echo '--- :evergreen_tree: Configuring Environment' -exec 9>&1 # enable tee to write to STDOUT as a file -echo "Using git tag '$REPO_UNDER_TEST:$GIT_TAG'." -CLONE="git clone --recursive --single-branch --branch '${GIT_TAG}' '${REPO_UNDER_TEST}'" -echo "$ $CLONE" -eval $CLONE -BREW_UPDATE='brew update' -echo "$ $BREW_UPDATE" -eval $BREW_UPDATE -if [[ ! -z "$BOTTLE" ]]; then - echo '+++ :hash: Verify Package Hash - SHA-256' - cd "$BUILDKITE_PIPELINE_SLUG" # same as repo name - DOWNLOAD="curl -fsSL -o './$BOTTLE' '$ROOT_URL/$BOTTLE'" - echo "$ $DOWNLOAD" - eval $DOWNLOAD - FILE_HASH="openssl dgst -sha256 '$BOTTLE'" - echo "$ $FILE_HASH" - BOTTLE_HASH="$(eval $FILE_HASH | tee >(cat - >&9) | awk '{print $2}')" - RUBY_LINE="cat '$RUBY_FILE' | grep 'sha256' | grep '$OS'" - echo "$ $RUBY_LINE" - RUBY_HASH="$(eval $RUBY_LINE | tee >(cat - >&9) | awk '{print $3}' | tr -d '"')" - if [[ "$BOTTLE_HASH" == "$RUBY_HASH" ]]; then - echo "Pass: $BOTTLE_HASH = $RUBY_HASH" - else - echo "+++ :x: Failed to Verify Bottle Hash" - FAIL_MSG="$BOTTLE hash $BOTTLE_HASH ≠ $RUBY_FILE::$OS hash $RUBY_HASH"'!' - echo "FAILURE: $FAIL_MSG" - [[ "$BUILDKITE" == 'true' ]] && echo "**FAILURE:** $FAIL_MSG" | buildkite-agent annotate --style 'error' --context "wrong-hash-$OS" - exit 2 - fi - cd .. -fi -echo '+++ :beer: Homebrew Tap and Install' -BREW_TAP="brew tap '$TAP'" -echo "$ $BREW_TAP" -eval $BREW_TAP -BREW_INSTALL="brew install '$PACKAGE'" -echo "$ $BREW_INSTALL" -eval $BREW_INSTALL -echo '+++ :label: Full Version Label Test' -cd eos -WHICH_BIN="which '$BIN'" -echo "$ $WHICH_BIN" -export BUILD_ROOT="$(eval $WHICH_BIN | tee >(cat - >&9) | sed "s_/bin/${BIN}__g")" -if [[ -z "$BUILD_ROOT" ]]; then - FAIL_MSG="'$BIN' binary not found after homebrew installation on $OS_STYLIZED"'!' - echo "FAILURE: $FAIL_MSG" - [[ "$BUILDKITE" == 'true' ]] && echo "**FAILURE:** $FAIL_MSG" | tr "'" '`' | buildkite-agent annotate --style 'error' --context "no-binary-$OS" - exit 3 -else - echo "Found '$BIN' at \"$BUILD_ROOT/bin/$BIN\"." -fi -export BUILDKITE_COMMIT="$(git rev-parse HEAD)" # override homebrew-eosio commit with eos tag commit -echo "Found git commit '$REPO_UNDER_TEST:$BUILDKITE_COMMIT'." -unset BUILDKITE_TAG -export CMAKE_SOURCE_DIR="$(pwd)" -echo "Set CMAKE_SOURCE_DIR to \"$CMAKE_SOURCE_DIR\"." -TEST="./tests/full-version-label.sh '$GIT_TAG'" -echo "$ $TEST" -set +e -eval $TEST -EXIT_STATUS="$?" -set -e -if [[ "$EXIT_STATUS" != '0' ]]; then - FAIL_MSG="Version label test failed on $OS_STYLIZED"'!' - echo "FAILURE: $FAIL_MSG" - [[ "$BUILDKITE" == 'true' ]] && echo "**FAILURE:** $FAIL_MSG" | buildkite-agent annotate --style 'error' --context "test-failure-$OS" - exit "$EXIT_STATUS" -fi -echo '--- :white_check_mark: Done!' -echo 'Done.'