Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,12 @@ jobs:
app/_build
key: ${{ runner.os }}-mix-${{ hashFiles('app/mix.lock') }}
-
run: mix deps.get
-
run: mix format --check-formatted
-
# Catches drift introduced within this PR (e.g. an ash/oban bump
# without re-running the sync) - see #79. The reactive auto-fix
# for drift from any other source lives in its own workflow
# (usage-rules-sync.yaml), not here.
run: mix usage_rules.sync --check
-
run: mix test
# mix ci covers deps.get, format --check-formatted,
# usage_rules.sync --check (catches dep-bump drift, see #79),
# and mix test. Runs from the repo root; cd: app/ is handled
# inside the task itself.
run: mix ci
working-directory: .

conventional_commits:
if: inputs.skip_commit_validation != true
Expand Down
41 changes: 41 additions & 0 deletions lib/mix/tasks/ci.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
defmodule Mix.Tasks.Ci do
@shortdoc "Runs the complete quality gate against app/"

@moduledoc """
#{@shortdoc}.

mix ci

Runs every check `.github/workflows/ci.yaml`'s `test` job runs on a pull
request, in the same order, so a green `mix ci` locally predicts a green
CI run — and CI itself calls this task, so there's one place to fix if
either ever breaks:

1. `mix deps.get` — ensure deps are present
2. `mix format --check-formatted` — code is formatted
3. `mix usage_rules.sync --check` — usage rules are in sync with deps
(catches drift introduced by a dep bump without re-running the sync;
see #79)
4. `mix test` — all tests pass

All steps run inside `app/`.
"""

use Mix.Task

alias RepoTasks.Shell

@impl Mix.Task
def run(argv) do
run(argv, &Shell.run!/3)
end

@doc false
def run(_argv, shell) do
shell.("mix", ["deps.get"], cd: "app")
shell.("mix", ["format", "--check-formatted"], cd: "app")
shell.("mix", ["usage_rules.sync", "--check"], cd: "app")
shell.("mix", ["test"], cd: "app")
:ok
end
end
21 changes: 21 additions & 0 deletions test/mix/tasks/ci_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Mix.Tasks.CiTest do
use ExUnit.Case, async: true

alias Mix.Tasks.Ci

test "runs all quality gate steps in order" do
caller = self()

shell = fn cmd, args, opts ->
send(caller, {:run, cmd, args, opts})
:ok
end

assert :ok = Ci.run([], shell)

assert_receive {:run, "mix", ["deps.get"], [cd: "app"]}
assert_receive {:run, "mix", ["format", "--check-formatted"], [cd: "app"]}
assert_receive {:run, "mix", ["usage_rules.sync", "--check"], [cd: "app"]}
assert_receive {:run, "mix", ["test"], [cd: "app"]}
end
end