Skip to content

Commit

Permalink
Add GitHub Actions CI Workflow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GrammAcc committed Feb 27, 2024
1 parent 65a47af commit a83d507
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
7 changes: 7 additions & 0 deletions test-suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

for dir in testsuite/*/; do
python modulr.py $dir 1>/dev/null
python testsuite/checkresults.py $dir
done

7 changes: 7 additions & 0 deletions testsuite/checkresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -27,10 +29,15 @@
try:
assert output_file.read() == expect_file.read()
except AssertionError:
has_failures = True
print(
f"Test {str(testrun_root).removeprefix('testsuite/')} - {fp}: Fail"
)
else:
print(
f"Test {str(testrun_root).removeprefix('testsuite/')} - {fp}: Pass"
)
if has_failures:
sys.exit(1)
else:
sys.exit(0)

0 comments on commit a83d507

Please sign in to comment.