From a83d5077db19fdbc57372f71e9883405899be0b4 Mon Sep 17 00:00:00 2001 From: Dalton Lang <35282898+GrammAcc@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:09:23 -0600 Subject: [PATCH] Add GitHub Actions CI Workflow I added a github actions workflow for running the test suite on PRs and direct pushes to both dev and main. For some reason, the bash shell on the windows runner doesn't work when the shell script is a string in the hatch run command, but it works when it's executed as a script, so I also added a `test-suite.sh` script that is run by hatch in order to get the same test suite behavior on Linux, MacOS, and Windows. I also added an exit code to the `checkresults.py` script so that failed tests will properly trigger a failure in the CI. --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ pyproject.toml | 5 +---- test-suite.sh | 7 +++++++ testsuite/checkresults.py | 7 +++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 test-suite.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7e4c8e6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: Modulr CI + +on: + push: + branches: ["main", "dev"] + pull_request: + branches: ["main", "dev"] + +jobs: + ci: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: | + 3.12 + - name: Install Hatch + run: pipx install hatch + - name: Run Hatch CI + run: hatch run test + shell: bash diff --git a/pyproject.toml b/pyproject.toml index bc8095b..d32ae29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,8 +29,5 @@ python = "3.12" dependencies = ["black"] [tool.hatch.envs.default.scripts] -test = """for dir in testsuite/*/; do - python modulr.py $dir 1>/dev/null - python testsuite/checkresults.py $dir -done""" +test = "bash test-suite.sh" format = "black ." diff --git a/test-suite.sh b/test-suite.sh new file mode 100644 index 0000000..137dcce --- /dev/null +++ b/test-suite.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +for dir in testsuite/*/; do + python modulr.py $dir 1>/dev/null + python testsuite/checkresults.py $dir +done + diff --git a/testsuite/checkresults.py b/testsuite/checkresults.py index 7f75f29..a6c19cb 100644 --- a/testsuite/checkresults.py +++ b/testsuite/checkresults.py @@ -16,6 +16,8 @@ output_root = testrun_root / "site" expect_root = testrun_root / "expected" +has_failures: bool = False + for root, dirs, files in output_root.walk(on_error=print): filepaths = [root / file for file in files] for fp in filepaths: @@ -27,6 +29,7 @@ try: assert output_file.read() == expect_file.read() except AssertionError: + has_failures = True print( f"Test {str(testrun_root).removeprefix('testsuite/')} - {fp}: Fail" ) @@ -34,3 +37,7 @@ print( f"Test {str(testrun_root).removeprefix('testsuite/')} - {fp}: Pass" ) +if has_failures: + sys.exit(1) +else: + sys.exit(0)