Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Dec 9, 2021
1 parent 70a9bcd commit 1c3b526
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
15 changes: 7 additions & 8 deletions tests/python/unittest/test_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
# specific language governing permissions and limitations
# under the License.

import os
import pathlib
import pytest
import shutil
import subprocess
import tempfile
import json
import sys
import tempfile

import pytest

REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent.parent


def test_skip_ci():
skip_ci_script = REPO_ROOT / "tests" / "scripts" / "git_skip_ci.sh"
skip_ci_script = REPO_ROOT / "tests" / "scripts" / "git_skip_ci.py"

class TempGit:
def __init__(self, cwd):
Expand All @@ -47,14 +43,17 @@ def test(commands, should_skip, why):
# Jenkins git is too old and doesn't have 'git init --initial-branch'
git.run("init")
git.run("checkout", "-b", "main")
git.run("remote", "add", "origin", "https://github.com/apache/tvm.git")
git.run("config", "user.name", "ci")
git.run("config", "user.email", "[email protected]")
git.run("commit", "--allow-empty", "--message", "base commit")
for command in commands:
git.run(*command)
pr_number = "1234"
proc = subprocess.run([str(skip_ci_script), pr_number], cwd=dir)
expected = 1 if should_skip else 0
proc = subprocess.run(
[str(skip_ci_script), "--pr", pr_number, "--pr-title", "[skip ci] test"], cwd=dir
)
expected = 0 if should_skip else 1
assert proc.returncode == expected, why

test(
Expand Down
16 changes: 12 additions & 4 deletions tests/scripts/git_skip_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def git(command):
parser = argparse.ArgumentParser(description=help)
parser.add_argument("--pr", required=True)
parser.add_argument("--remote", default="origin", help="ssh remote to parse")
parser.add_argument(
"--pr-title", help="(testing) PR title to use instead of fetching from GitHub"
)
args = parser.parse_args()

branch = git(["rev-parse", "--abbrev-ref", "HEAD"])
Expand All @@ -83,10 +86,15 @@ def git(command):
def check_pr_title():
remote = git(["config", "--get", f"remote.{args.remote}.url"])
user, repo = parse_remote(remote)
github = GitHubRepo(token=os.environ["TOKEN"], user=user, repo=repo)
pr = github.get(f"pulls/{args.pr}")
print("pr title:", pr["title"])
return pr["title"].startswith("[skip ci]")

if args.pr_title:
title = args.pr_title
else:
github = GitHubRepo(token=os.environ["TOKEN"], user=user, repo=repo)
pr = github.get(f"pulls/{args.pr}")
title = pr["title"]
print("pr title:", title)
return title.startswith("[skip ci]")

if (
args.pr != "null"
Expand Down

0 comments on commit 1c3b526

Please sign in to comment.