diff --git a/.circleci/config.yml b/.circleci/config.yml index 60d131332..84ed49047 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -507,7 +507,7 @@ jobs: git pull origin main cp .env.sample .env env GITHUB_BEARER_TOKEN="${GH_TOKEN}" make fetch_external_resources - if (($(git status --porcelain | wc -c) > 0)) + if ./experimenter/bin/should-pr.py then git checkout -B external-config git add . diff --git a/experimenter/bin/should-pr.py b/experimenter/bin/should-pr.py new file mode 100755 index 000000000..23da7d6d9 --- /dev/null +++ b/experimenter/bin/should-pr.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import subprocess +import sys +from pathlib import Path + +MANIFEST_DIR = ( + Path(__file__) + .parent.parent.joinpath("experimenter", "features", "manifests") + .resolve() +) + + +def changed_files() -> list[Path]: + output = subprocess.check_output(["git", "status", "--porcelain"], encoding="utf-8") + files = [Path(line[3:]) for line in output.splitlines()] + return files + + +def is_ref_cache(path: Path): + return path.name == ".ref-cache.yaml" and path.resolve().is_relative_to(MANIFEST_DIR) + + +def main() -> int: + files = [f for f in changed_files() if not is_ref_cache(f)] + + return int(not len(files)) + + +if __name__ == "__main__": + sys.exit(main())