From 6c3e65a878e43feb37941001bb9646c828f90689 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Tue, 16 Jul 2024 14:48:15 -0700 Subject: [PATCH] infra: prerelease dep checking on release (#23269) --- .../scripts/check_prerelease_dependencies.py | 35 +++++++++++++++++++ .github/workflows/_release.yml | 5 +++ 2 files changed, 40 insertions(+) create mode 100644 .github/scripts/check_prerelease_dependencies.py diff --git a/.github/scripts/check_prerelease_dependencies.py b/.github/scripts/check_prerelease_dependencies.py new file mode 100644 index 0000000000..1d4703e48a --- /dev/null +++ b/.github/scripts/check_prerelease_dependencies.py @@ -0,0 +1,35 @@ +import sys +import tomllib + +if __name__ == "__main__": + # Get the TOML file path from the command line argument + toml_file = sys.argv[1] + + # read toml file + with open(toml_path, "rb") as file: + toml_data = tomllib.load(file) + + # see if we're releasing an rc + version = toml_data["tool"]["poetry"]["version"] + releasing_rc = "rc" in version + + # if not, iterate through dependencies and make sure none allow prereleases + if not releasing_rc: + dependencies = toml_data["tool"]["poetry"]["dependencies"] + for lib in dependencies: + dep_version = dependencies[lib] + dep_version_string = ( + dep_version["version"] if isinstance(dep_version, dict) else dep_version + ) + + if "rc" in dep_version_string: + raise ValueError( + f"Dependency {lib} has a prerelease version. Please remove this." + ) + + if isinstance(dep_version, dict) and dep_version.get( + "allow-prereleases", False + ): + raise ValueError( + f"Dependency {lib} has allow-prereleases set to true. Please remove this." + ) diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index b24d5f39f2..c9cdd23700 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -221,6 +221,11 @@ jobs: run: make tests working-directory: ${{ inputs.working-directory }} + - name: Check for prerelease versions + working-directory: ${{ inputs.working-directory }} + run: | + poetry run python $GITHUB_WORKSPACE/.github/scripts/check_prerelease_dependencies.py pyproject.toml + - name: Get minimum versions working-directory: ${{ inputs.working-directory }} id: min-version