From 8a03414ea14c87799f7e2330489b81cf05b7beec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Krzy=C5=9Bk=C3=B3w?= Date: Sat, 21 Sep 2024 18:44:00 +0200 Subject: [PATCH] ci: pyproject tests --- .github/scripts/compare_pyproject.py | 46 ++++++++++++++++++++++++++++ .github/workflows/test_dev.yml | 29 ++++++++++++++---- 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 .github/scripts/compare_pyproject.py diff --git a/.github/scripts/compare_pyproject.py b/.github/scripts/compare_pyproject.py new file mode 100644 index 0000000..8fa47aa --- /dev/null +++ b/.github/scripts/compare_pyproject.py @@ -0,0 +1,46 @@ +import argparse +import sys +import tomllib + + +def main(): + parser = argparse.ArgumentParser( + description="Compare versions in [project] section of main and dev TOML files." + ) + parser.add_argument("--dev-toml", help="Path to the dev branch TOML file") + parser.add_argument("--main-toml", help="Path to the main branch TOML file") + + args = parser.parse_args() + + try: + with open(args.dev_toml, "rb") as file: + dev_toml = tomllib.load(file) + except FileNotFoundError: + sys.exit(f"File not found: {args.dev_toml}") + except Exception as e: + sys.exit(f"Error reading file {args.dev_toml}: {e}") + + try: + with open(args.main_toml, "rb") as file: + main_toml = tomllib.load(file) + except FileNotFoundError: + sys.exit(f"File not found: {args.main_toml}") + except Exception as e: + sys.exit(f"Error reading file {args.main_toml}: {e}") + + # Extracting versions + dev_version = dev_toml.get("project").get("version") + main_version = main_toml.get("project").get("version") + + print(f"{dev_version=}") + print(f"{main_version=}") + + if dev_version == main_version: + sys.exit( + "Versions between dev and main branch match." + "\nThe version needs to be bumped to make sure it will be installed." + ) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/test_dev.yml b/.github/workflows/test_dev.yml index 56d7823..45ed592 100644 --- a/.github/workflows/test_dev.yml +++ b/.github/workflows/test_dev.yml @@ -10,14 +10,26 @@ jobs: style-check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Checkout Dev + uses: actions/checkout@v4 + - name: Checkout Main + run: git clone --depth 1 https://github.com/nypesap/mkdocs-nype.git main-branch + - name: Install Python + uses: actions/setup-python@v5 with: python-version: 3 cache: pip - - run: pip install isort black - - run: isort mkdocs_nype/ --check - - run: black mkdocs_nype/ --check + - name: Install style-check deps + run: pip install isort black + - name: Run style-check tests + run: | + isort mkdocs_nype/ --check + black mkdocs_nype/ --check + - name: Check package version when contents change + if: "hashFiles('mkdocs_nype') != hashFiles('main-branch/mkdocs_nype')" + run: | + wget -O main_pyproject.toml https://raw.githubusercontent.com/nypesap/mkdocs-nype/refs/heads/main/pyproject.toml + python .github/scripts/compare_pyproject.py --dev-toml pyproject.toml --main-toml main_pyproject.toml check-repos: needs: style-check runs-on: ubuntu-latest @@ -30,4 +42,9 @@ jobs: - https://github.com/fioriroletesting/fioriroletesting.github.io.git steps: - uses: actions/checkout@v4 - - run: echo "${{ matrix.repo }}" \ No newline at end of file + - run: echo "${{ matrix.repo }}" + after-repos: + needs: check-repos + runs-on: ubuntu-latest + steps: + - run: echo "Success" \ No newline at end of file