Skip to content

Commit

Permalink
feat(CI) - add possibility to point harmony-test repo to non-master b…
Browse files Browse the repository at this point in the history
…ranch via CI, add MAIN_REPO_BRANCH to point exaclty the same repo version in the test run instead of hardcoded main branch, cover local runs of travis_rosetta_checker.sh and travis_rpc_checker.sh
  • Loading branch information
mur-me committed Aug 9, 2024
1 parent 6b25283 commit 8b1cda4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ install:
# /home/travis/gopath/src/github.com/harmony-one/harmony
# https://docs.travis-ci.com/user/languages/go/#go-import-path
- echo $TRAVIS_PULL_REQUEST_BRANCH
- TEST_REPO_BRANCH="master"
- git clone https://github.com/harmony-one/mcl.git $GOPATH/src/github.com/harmony-one/mcl
- git clone https://github.com/harmony-one/bls.git $GOPATH/src/github.com/harmony-one/bls
- git clone https://github.com/harmony-one/harmony-test.git $GOPATH/src/github.com/harmony-one/harmony-test
- git clone --branch $TEST_REPO_BRANCH https://github.com/harmony-one/harmony-test.git $GOPATH/src/github.com/harmony-one/harmony-test
- (cd $GOPATH/src/github.com/harmony-one/mcl; make -j4)
- (cd $GOPATH/src/github.com/harmony-one/bls; make BLS_SWAP_G=1 -j4)
# - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,13 @@ travis_go_checker:
bash ./scripts/travis_go_checker.sh

travis_rpc_checker:
# value from command line will override this value, use point test to non-default
TEST_REPO_BRANCH='master'
bash ./scripts/travis_rpc_checker.sh

travis_rosetta_checker:
# value from command line will override this value, use point test to non-default
TEST_REPO_BRANCH='master'
bash ./scripts/travis_rosetta_checker.sh

debug_external: clean
Expand Down
41 changes: 31 additions & 10 deletions scripts/travis_rosetta_checker.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
#!/usr/bin/env bash
set -e

echo $TRAVIS_PULL_REQUEST_BRANCH
TEST_REPO_BRANCH=${TEST_REPO_BRANCH:-master}
# handle for the Travis build run:
# * uses TRAVIS_PULL_REQUEST_BRANCH for RP branch
# * uses TRAVIS_BRANCH for simple branch builds
MAIN_REPO_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}
# handle for the local run, covers:
# * branch exist on remote - will use it in the tests
# * branch exists locally - will use dev as base branch in test
if [[ -z "$MAIN_REPO_BRANCH" ]]; then
MAIN_REPO_BRANCH=${MAIN_REPO_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
git ls-remote --exit-code --heads origin "${MAIN_REPO_BRANCH}" >/dev/null 2>&1 || EXIT_CODE=$?
if [[ $EXIT_CODE == '0' ]]; then
echo "[INFO] - Git branch '$MAIN_REPO_BRANCH' exists in the remote repository"
elif [[ $EXIT_CODE == '2' ]]; then
echo "[WARN] - Git branch '$MAIN_REPO_BRANCH' does not exist in the remote repository, using" \
"'dev' branch as a workaround for a local-only branch"
MAIN_REPO_BRANCH='dev'
fi
fi

echo "[harmony-test repo] - working on '${TEST_REPO_BRANCH}' branch"
echo "[harmony repo] - working on '${MAIN_REPO_BRANCH}' branch"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
echo $DIR
echo $GOPATH
cd $GOPATH/src/github.com/harmony-one/harmony-test
git fetch
git pull
git checkout $TRAVIS_PULL_REQUEST_BRANCH || true
git branch --show-current
echo "Working dir is ${DIR}"
echo "GOPATH is ${GOPATH}"
cd "${GOPATH}/src/github.com/harmony-one/harmony-test"
# cover possible force pushes to remote branches - just rebase local on top of origin
git checkout "${TEST_REPO_BRANCH}"
git pull --rebase=true
cd localnet
docker build -t harmonyone/localnet-test .
docker run -v "$DIR/../:/go/src/github.com/harmony-one/harmony" harmonyone/localnet-test -r
docker build --build-arg MAIN_REPO_BRANCH="${MAIN_REPO_BRANCH}" -t harmonyone/localnet-test .
# WARN: this is the place where LOCAL repository is provided to the harmony-tests repo
docker run -v "$DIR/../:/go/src/github.com/harmony-one/harmony" harmonyone/localnet-test -r
41 changes: 31 additions & 10 deletions scripts/travis_rpc_checker.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
#!/usr/bin/env bash
set -e

echo $TRAVIS_PULL_REQUEST_BRANCH
TEST_REPO_BRANCH=${TEST_REPO_BRANCH:-master}
# handle for the Travis build run:
# * uses TRAVIS_PULL_REQUEST_BRANCH for RP branch
# * uses TRAVIS_BRANCH for simple branch builds
MAIN_REPO_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}
# handle for the local run, covers:
# * branch exist on remote - will use it in the tests
# * branch exists locally - will use dev as base branch in test
if [[ -z "$MAIN_REPO_BRANCH" ]]; then
MAIN_REPO_BRANCH=${MAIN_REPO_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
git ls-remote --exit-code --heads origin "${MAIN_REPO_BRANCH}" >/dev/null 2>&1 || EXIT_CODE=$?
if [[ $EXIT_CODE == '0' ]]; then
echo "[INFO] - Git branch '$MAIN_REPO_BRANCH' exists in the remote repository"
elif [[ $EXIT_CODE == '2' ]]; then
echo "[WARN] - Git branch '$MAIN_REPO_BRANCH' does not exist in the remote repository, using" \
"'dev' branch as a workaround for a local-only branch"
MAIN_REPO_BRANCH='dev'
fi
fi

echo "[harmony-test repo] - working on '${TEST_REPO_BRANCH}' branch"
echo "[harmony repo] - working on '${MAIN_REPO_BRANCH}' branch"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
echo $DIR
echo $GOPATH
cd $GOPATH/src/github.com/harmony-one/harmony-test
git fetch
git checkout $TRAVIS_PULL_REQUEST_BRANCH || true
git pull
git branch --show-current
echo "Working dir is ${DIR}"
echo "GOPATH is ${GOPATH}"
cd "${GOPATH}/src/github.com/harmony-one/harmony-test"
# cover possible force pushes to remote branches - just rebase local on top of origin
git checkout "${TEST_REPO_BRANCH}"
git pull --rebase=true
cd localnet
docker build -t harmonyone/localnet-test .
docker run -v "$DIR/../:/go/src/github.com/harmony-one/harmony" harmonyone/localnet-test -n
docker build --build-arg MAIN_REPO_BRANCH="${MAIN_REPO_BRANCH}" -t harmonyone/localnet-test .
# WARN: this is the place where LOCAL repository is provided to the harmony-tests repo
docker run -v "$DIR/../:/go/src/github.com/harmony-one/harmony" harmonyone/localnet-test -n

0 comments on commit 8b1cda4

Please sign in to comment.