A GitHub Action that installs mortise, the command line tool of
Mortise, from a release. It downloads the archive for the runner,
checks its SHA-256 against the sums file of the release, and puts mortise on PATH. It needs no Rust
toolchain and takes a few seconds.
mortise check reads a Laravel app that uses
nwidart/laravel-modules, without PHP, and fails the job
when a boundary rule breaks. mortise push sends one read of the app to
Mortise Cloud.
# .github/workflows/mortise.yml
name: Mortise
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
mortise:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: mortise-dev/setup-mortise@v1
- name: Send the snapshot to Mortise Cloud
run: mortise push .
env:
MORTISE_TOKEN: ${{ secrets.MORTISE_TOKEN }}
- name: Check the boundary rules
run: mortise check . --format githubfetch-depth: 0 gives mortise push the full history. Full history gives commits per module and lets Mortise fill
past history. A depth of 1 is faster and leaves both out.
On a large repository, add filter: blob:none beside fetch-depth: 0:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: blob:noneThe checkout then gets every commit, and the file contents of the commit it checks out only. A clone of
two large repositories took about half the time and half the space this way, and gave the same commits per module.
Mortise 1.1.0 and earlier let git download a few more files while they count the commits, so leave
persist-credentials of the checkout at its default.
mortise push needs a token of Mortise Cloud in the secret MORTISE_TOKEN.
Without the cloud, leave that step out: mortise check needs no token.
Coverage comes from a clover report, so the tests run first. The checkout keeps fetch-depth: 0, for the same reason:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
coverage: pcov
- run: composer install --no-interaction --no-progress
- run: cp .env.example .env && php artisan key:generate
- run: vendor/bin/phpunit --coverage-clover build/coverage/clover.xml
- uses: mortise-dev/setup-mortise@v1
- name: Send the snapshot to Mortise Cloud
run: mortise push . --coverage build/coverage/clover.xml
env:
MORTISE_TOKEN: ${{ secrets.MORTISE_TOKEN }}
- name: Check the boundary rules
run: mortise check . --coverage build/coverage/clover.xml --format githubbackfill: true fills the past weeks of the app in Mortise Cloud with
mortise backfill, so the charts do not start on the day of the first push:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: mortise-dev/setup-mortise@v1
with:
backfill: true
path: .
env:
MORTISE_TOKEN: ${{ secrets.MORTISE_TOKEN }}
- name: Send the snapshot to Mortise Cloud
run: mortise push .
env:
MORTISE_TOKEN: ${{ secrets.MORTISE_TOKEN }}- The backfill runs in the post step of the action, after the other steps of the job, so the push of the commit that is checked out arrives first. It reads one commit per past week and sends each one.
- It runs only on a
pushto the default branch of the repository, and only whenMORTISE_TOKENis set. On every other run, such as a pull request, it does nothing and prints nothing. - It runs also when a step before it failed, such as
mortise checkon a problem of the app. It does not run when the job is cancelled, and it does nothing when the action did not installmortise. When the step ofmortise pushfailed or did not run, the backfill still sends the past weeks, and the next push sends the commit that is checked out. - The backfill never fails the job. When Mortise Cloud refuses it, is out of reach, or the token is wrong, the step prints a warning and the job goes on. The next run tries again.
- The input can stay in the workflow. Once the past weeks are filled, a run costs one request.
- The post step reads
MORTISE_TOKEN, andMORTISE_CLOUD_URLwhen it is set, from theenvof thesetup-mortisestep or of the job. A token set only on the step ofmortise pushdoes not reach it. pathis the app folder, relative to the workspace. It is the folder thatmortise pushreads.- It needs Mortise 1.3.0 or later. With an older pinned
version, the step prints a warning and sends nothing.
The backfill needs the full history: keep fetch-depth: 0. On a shallow clone it sends nothing and says so.
With filter: blob:none, the clone has no file contents of past commits, so mortise backfill downloads
them for each commit it reads, with the credentials of the checkout. Leave persist-credentials at its
default: with persist-credentials: false on a private repository, every past commit is left out.
| Input | Default | Meaning |
|---|---|---|
version |
latest |
The release to install: latest, or a tag such as v0.3.0 (0.3.0 works too) |
token |
${{ github.token }} |
A token for the GitHub API. It is used only to find the newest release when version is latest. Without one the API allows 60 calls an hour per address |
backfill |
false |
true runs mortise backfill after the steps of the job, on a push to the default branch with MORTISE_TOKEN set. See With past history |
path |
. |
The app folder that mortise backfill reads, relative to the workspace |
Pin a version for builds that must not change on their own:
- uses: mortise-dev/setup-mortise@v1
with:
version: v0.3.0| Output | Meaning |
|---|---|
version |
The tag of the installed release, such as v0.3.0 |
| Runner | Archive |
|---|---|
Linux, x64 (ubuntu-latest) |
mortise-vX.Y.Z-linux-x86_64.tar.gz, static |
Linux, arm64 (ubuntu-24.04-arm) |
mortise-vX.Y.Z-linux-arm64.tar.gz, static |
macOS, Apple silicon (macos-latest) |
mortise-vX.Y.Z-macos-arm64.zip, signed and notarized |
Windows, x64 (windows-latest) |
mortise-vX.Y.Z-windows-x64.zip |
The action runs on Node 24, which every runner of GitHub has. A self-hosted runner needs version 2.328 or later of the runner.
On another runner, such as macOS on Intel, the action fails and says so. Install the tool there with
cargo install --locked mortise-cli.
- It downloads the archive and
Mortise-vX.Y.Z-SHA256SUMS.txtfrom the release of mortise-dev/mortise. - It compares the SHA-256 of the archive with the archive's line in the sums file. A missing line or
another sum fails the step, and nothing goes on
PATH. - It unpacks the archive into the temporary folder of the runner and runs
mortise --version, which must print the version of the release. - It adds that folder to
PATHfor the later steps of the job.
The sums file and the archive come from the same release, so the check catches a broken or changed download, not a changed release. Pin the action to a commit to trust only code you have read.
MIT, see LICENSE.