From 91745377cf74ec556c3a4555af028bb6372c723b Mon Sep 17 00:00:00 2001 From: Mike Greenberg Date: Tue, 14 Sep 2021 19:31:28 -0400 Subject: [PATCH] feat(ci): include version/cli checks in tagged releases --- .circleci/config.yml | 6 ++++++ .circleci/template.yml | 6 ++++++ scripts/version-check.sh | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100755 scripts/version-check.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index cdc81979319..81bc59cf46f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,6 +92,9 @@ jobs: - run: sudo apt-get install npm - run: command: make buildall + - run: + name: check tag and version output match + command: ./scripts/version-check.sh ./lotus - store_artifacts: path: lotus - store_artifacts: @@ -383,6 +386,9 @@ jobs: - run: command: make build no_output_timeout: 30m + - run: + name: check tag and version output match + command: ./scripts/version-check.sh ./lotus - store_artifacts: path: lotus - store_artifacts: diff --git a/.circleci/template.yml b/.circleci/template.yml index 70f7ea51afe..a7bbf8d0a55 100644 --- a/.circleci/template.yml +++ b/.circleci/template.yml @@ -92,6 +92,9 @@ jobs: - run: sudo apt-get install npm - run: command: make buildall + - run: + name: check tag and version output match + command: ./scripts/version-check.sh ./lotus - store_artifacts: path: lotus - store_artifacts: @@ -383,6 +386,9 @@ jobs: - run: command: make build no_output_timeout: 30m + - run: + name: check tag and version output match + command: ./scripts/version-check.sh ./lotus - store_artifacts: path: lotus - store_artifacts: diff --git a/scripts/version-check.sh b/scripts/version-check.sh new file mode 100755 index 00000000000..15f4f37abe1 --- /dev/null +++ b/scripts/version-check.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +set -ex + +# Validate lotus version matches the current tag +# $1 - lotus path to execute +# $2 - lotus git tag for this release +function validate_lotus_version_matches_tag(){ + # sanity checks + if [[ $# != 2 ]]; then + echo "expected 2 args for validate_lotus_version, got ${$#}" + exit 100 + fi + + # extract version from `lotus --version` response + lotus_path=$1 + # get version + lotus_raw_version=`${lotus_path} --version` + # trim leading unwanted text ('lotus version ' literal) + lotus_headtrimmed_version=${lotus_raw_version#lotus version } + # trim tailing unwanted text (everything after 1st '+') + lotus_actual_version=${lotus_headtrimmed_version%%+*} + + # trim leading 'v' + tag=${2#v} + # trim possible -rc[0-9] + expected_version=${tag%-*} + + # check the versions are consistent + if [[ ${expected_version} != ${lotus_actual_version} ]]; then + echo "lotus version does not match build tag" + exit 101 + fi +} + +_lotus_path=$1 + +if [[ ! -z "${CIRCLE_TAG}" ]]; then + validate_lotus_version_matches_tag "${_lotus_path}" "${CIRCLE_TAG}" +else + echo "No CI tag found. Skipping version check." +fi