Skip to content

Check the rules in CI

mortise check reads an app the way the window does and fails when a rule breaks. It runs no PHP and writes nothing in the app, so a CI job needs only the files of the app and the tool. The rules come from mortise.json; without the file the defaults apply.

  1. Check the app on your machine first. From the app folder:

    Terminal window
    mortise check

    Each problem is one line with its file and line. The exit code is 1 when a problem is found. To get the tool, see Install the command line tool.

  2. Add a job to your workflow. This one is for GitHub Actions, with the app at the root of the repository:

    jobs:
    boundaries:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5
    - uses: mortise-dev/setup-mortise@v1
    - run: mortise check --format github

    mortise-dev/setup-mortise downloads the tool of the latest release, checks its SHA-256 and puts it on PATH, in a few seconds and with no Rust toolchain. On another CI, download the archive of the release or run cargo install --locked mortise-cli.

    --format github prints each problem as a workflow command, so GitHub marks the line in the pull request. A file that reads an internal class of another module gets a mark of its own.

  3. Commit mortise.json with the workflow, so that CI checks the rules your team chose.

The job fails on every problem in the commit it checks, not only on the problems the pull request adds. Fix the problems that are there first, or start with Fail CI when a rule breaks off.

The tool and the action work on Linux, macOS and Windows runners. Only runs-on changes:

jobs:
boundaries:
runs-on: windows-latest
steps:
- uses: actions/checkout@v5
- uses: mortise-dev/setup-mortise@v1
with:
version: v0.3.0
- run: mortise check --format github

The paths in the report use / on every platform, so GitHub marks the same lines on each runner. version pins a release. Without it the action installs the latest one.

To see the problems in the CI log without failing the job, turn off Fail CI when a rule breaks in the rules box of the Boundary tab, or set it in mortise.json:

{
"ci": { "fail": false }
}

mortise check then prints the same report, says on standard error that the check passes, and exits 0.

A warning, such as a module under the coverage limit, does not fail the check. Add --fail-on warnings to make it fail. The coverage limit and report come from the coverage object of mortise.json, or from the flags --coverage-limit and --coverage, which win over the file.

The flags and exit codes are in Command line tool.

To send each read to Mortise Cloud as well, see Send a read to Mortise Cloud.