From 0def0132ae610d71bf333a01d6f82fba12224f6e Mon Sep 17 00:00:00 2001 From: Barret Rennie Date: Wed, 22 Nov 2023 13:46:35 -0500 Subject: [PATCH] feat(nimbus): don't open PRs for just ref-cache changes (#9807) Because - we only want to merge PRs that have feature configuration changes this commit - adds a script to check if there are only `.ref-cache` changes; - updates the `update_external_configs` CI job to call that script and; - only push to the `external-config` branch and open PRs if that script reports changes. Fixes #9806 --- .circleci/config.yml | 2 +- experimenter/bin/should-pr.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 experimenter/bin/should-pr.py 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())