diff --git a/.travis.yml b/.travis.yml index ced7b18..c8764f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,15 +12,10 @@ install: - pip3 install -r requirements.txt before_script: - pip3 install -r ./tests/requirements_dev.txt - - pip3 install anybadge - - git checkout master - - black hyperglass - - python3 ./manage.py pylint-badge --integer-only True - - ./tests/ci_git.sh + - black --check hyperglass + - python3 ./manage.py pylint-check --integer-only True - python3 ./tests/ci_prepare.py script: - nohup python3 ./tests/ci_dev_server.py & - sleep 20 - python3 ./tests/ci_test.py -after_success: - - git push origin master diff --git a/manage.py b/manage.py index 2844cf6..b52a0ee 100755 --- a/manage.py +++ b/manage.py @@ -35,8 +35,7 @@ def construct_test(test_query, location, test_target): def hg(): pass - -@hg.command("pylint-badge", help="Runs Pylint and generates a badge for GitHub") +@hg.command("pylint-check", help="Runs Pylint and generates a badge for GitHub") @click.option( "-i", "--integer-only", @@ -45,7 +44,8 @@ def hg(): default=False, help="Output Pylint score as integer", ) -def pylint_badge(int_only): +@click.option("-b", "--badge", "create_badge", type=bool, default=False, help="Create Pylint badge") +def pylint_check(int_only, create_badge): try: import re import anybadge @@ -58,12 +58,13 @@ def pylint_badge(int_only): ).group(1) if not pylint_score == "10.00": raise RuntimeError(f"Pylint score {pylint_score} not acceptable.") - badge_file = os.path.join(working_directory, "pylint.svg") - if os.path.exists(badge_file): - os.remove(badge_file) - ab_thresholds = {1: "red", 10: "green"} - badge = anybadge.Badge("pylint", pylint_score, thresholds=ab_thresholds) - badge.write_badge("pylint.svg") + if create_badge: + badge_file = os.path.join(working_directory, "pylint.svg") + if os.path.exists(badge_file): + os.remove(badge_file) + ab_thresholds = {1: "red", 10: "green"} + badge = anybadge.Badge("pylint", pylint_score, thresholds=ab_thresholds) + badge.write_badge("pylint.svg") if not int_only: click.secho( f"Created Pylint badge for score: {pylint_score}", fg="blue", bold=True diff --git a/tests/ci_commit.sh b/tests/ci_commit.sh deleted file mode 100755 index bc1ab70..0000000 --- a/tests/ci_commit.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -git_commit() { - git remote add origin https://${GH_TOKEN}@github.com/checktheroads/hyperglass.git > /dev/null 2>&1 - git push --quiet --set-upstream origin master -} - -git_commit diff --git a/tests/ci_git.sh b/tests/ci_git_commit.sh similarity index 65% rename from tests/ci_git.sh rename to tests/ci_git_commit.sh index fc65577..228b522 100755 --- a/tests/ci_git.sh +++ b/tests/ci_git_commit.sh @@ -1,4 +1,4 @@ - #!/bin/sh +#!/bin/sh commit_black() { git add hyperglass/*.py @@ -10,12 +10,6 @@ commit_pylint() { git commit --message "Pylint Badge - travis $TRAVIS_BUILD_NUMBER" } -setup_git() { - git config --global user.email "travis@travis-ci.org" - git config --global user.name "Travis CI" -} - -setup_git commit_black commit_pylint diff --git a/tests/ci_git_prep.sh b/tests/ci_git_prep.sh new file mode 100755 index 0000000..3dc6be5 --- /dev/null +++ b/tests/ci_git_prep.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +echo "Travis Pull Request: $TRAVIS_PULL_REQUEST" +echo "Travis Branch: $TRAVIS_BRANCH" + +git_setup() { + git config user.email "travis@travis-ci.org" + git config user.name "Travis CI" +} + +detect_branch() { + if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then + echo $TRAVIS_BRANCH + else + echo $TRAVIS_PULL_REQUEST_BRANCH + fi +} + +export CURRENT_BRANCH=$(detect_branch) +echo "Detected Branch: $CURRENT_BRANCH" + +echo "Setting git config parameters..." +git_setup +echo "git branches:\n$(git branch -a)" +echo "Initiating git fetch..." +git fetch --depth=1 $GH_TOKEN@github.com:$TRAVIS_PULL_REQUEST_SLUG.git refs/heads/$CURRENT_BRANCH:refs/remotes/origin/$CURRENT_BRANCH > /dev/null 2>&1 +echo "Running git checkout..." +git checkout origin/$CURRENT_BRANCH diff --git a/tests/ci_git_push.sh b/tests/ci_git_push.sh new file mode 100644 index 0000000..186e4f9 --- /dev/null +++ b/tests/ci_git_push.sh @@ -0,0 +1,2 @@ +#!/bin/sh +git push $GH_TOKEN@github.com:$TRAVIS_PULL_REQUEST_SLUG.git origin $CURRENT_BRANCH > /dev/null 2>&1 diff --git a/tests/ci_prepare.py b/tests/ci_prepare.py old mode 100644 new mode 100755