Current section

Files

Jump to
ash_hooks mix.exs
Raw

mix.exs

# SPDX-FileCopyrightText: © 2026 BaseLabs Holdings LLC
#
# SPDX-License-Identifier: MIT

defmodule AshHooks.MixProject do
  use Mix.Project

  @version "4.2.0"
  @source_url "https://github.com/baselabs/ash_hooks"
  # Every Spark extension the package ships. The formatter export and the DSL
  # references are generated from this one list.
  @spark_extensions "AshHooks,AshHooks.Endpoint,AshHooks.Subscription,AshHooks.InboundDelivery,AshHooks.InboundSource,AshHooks.OutboundDelivery,AshHooks.OutboundAttempt,AshHooks.OutboundEvent,AshHooks.KeyRegistry,AshHooks.OutboundOutbox"

  def project do
    [
      app: :ash_hooks,
      version: @version,
      # Consumers use the supported Elixir floor, not the repository's exact pin.
      # .tool-versions pins development; config/config.exs checks supported OTP.
      # CI versions also come from the root and ci/*/.tool-versions files.
      # Repository configuration is excluded from the package.
      # CI exercises the supported consumer graph.
      elixir: "~> 1.20",
      start_permanent: Mix.env() == :prod,
      elixirc_paths: elixirc_paths(Mix.env()),
      consolidate_protocols: Mix.env() != :test,
      # The production consumer is executed separately. Its fetched dependencies
      # and build output are outside this application's ExUnit source surface.
      test_ignore_filters: [
        ~r{\Atest/consumer/(deps|_build)/},
        ~r{\Atest/consumer/(mix|verify)\.exs\z},
        ~r{\Atest/ash_hooks/outbox_(acceptance|process|resources|type_resources)\.exs\z},
        ~r{\Atest/ash_hooks/remote_key_support\.exs\z}
      ],
      deps: deps(),
      package: package(),
      docs: &docs/0,
      aliases: aliases(),
      name: "AshHooks",
      description:
        "Webhooks for Ash Framework: verify and deduplicate inbound webhooks from any sender, and sign and deliver outbound webhooks.",
      source_url: @source_url,
      homepage_url: @source_url,
      # :ecto_sql is explicit because `use AshSqlite.Repo` (test/support)
      # macro-emits Ecto.Adapters.SQL delegations; the deps-PLT app
      # enumeration does not reliably include it, and without it dialyzer
      # reports those delegations as unknown functions. :ash_postgres
      # carries the PG repo's behaviour callbacks (callback_info_missing
      # on a fresh PLT, CI 2026-10-05).
      # Shared test cases run as ordinary functions so coverage sees their code.
      # Their assertions and cleanup callbacks require ExUnit in the test PLT.
      # The documentation gate uses ExDoc's Markdown parser directly.
      # The core PLTs live beside the project PLT in _build, so one build
      # directory carries every PLT the Dialyzer run reads.
      dialyzer: [
        plt_core_path: "_build/#{Mix.env()}",
        plt_add_apps: [:mix, :ash_sqlite, :ash_postgres, :ecto_sql, :ex_unit, :earmark_parser]
      ],
      test_coverage: [summary: [threshold: 100]]
    ]
  end

  def application, do: [extra_applications: [:logger, :crypto, :public_key, :ssl, :inets]]

  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  defp deps do
    # Optional at runtime for CONSUMERS (hex metadata), but listing them here
    # opts THIS dev build into compiling them (Mix builds a root project's own
    # optional deps). ASH_HOOKS_NO_OPTIONAL=1 drops them from the dep list
    # entirely: the CI no-optional leg uses it to prove the package compiles
    # and tests Oban/plug-free (ADR-0004).
    optional_deps =
      if System.get_env("ASH_HOOKS_NO_OPTIONAL") == "1" do
        []
      else
        [
          {:oban, "~> 2.24", optional: true},
          {:plug, ">= 1.20.4 and < 2.0.0-0", optional: true},
          {:req, "~> 0.7.5", optional: true},
          # A real HTTP server and a real Phoenix endpoint and router for the
          # plug's interoperability tests and the documentation's mounting
          # examples. Both depend on Plug, so they leave with it on the
          # no-optional leg; neither is a dependency of the package.
          {:ash_oaskit, "~> 0.5.0", only: :test},
          {:bandit, "~> 1.14", only: :test},
          {:phoenix, "~> 1.8", only: :test}
        ]
      end

    [
      # Runtime
      # The Ash floor excludes releases affected by published advisories and
      # supplies the tenant inverse API. The security job scans the
      # development lock and both locks pinned at this floor.
      {:ash, ">= 3.39.0 and < 4.0.0-0"},
      {:splode, "~> 0.3"},
      {:spark, ">= 2.7.6 and < 3.0.0-0"},
      {:jason, "~> 1.3"},
      {:telemetry, "~> 1.3"}
      | optional_deps
    ] ++
      [
        # Dev/Test
        {:jsv, "~> 0.28.0", only: :test},
        {:igniter, "~> 0.6", only: [:dev, :test], runtime: false, optional: true},
        {:ex_doc, "~> 0.31", only: [:dev, :test], runtime: false},
        {:ex_check, "~> 0.12", only: [:dev, :test]},
        {:credo, "~> 1.7", only: [:dev, :test], runtime: false},
        {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
        {:sobelow, ">= 0.0.0", only: [:dev, :test], runtime: false},
        # deps.audit: the Elixir security advisory database, alongside hex.audit.
        {:mix_audit, "~> 2.1", only: [:dev, :test], runtime: false},
        {:simple_sat, "~> 0.1", only: [:dev, :test], runtime: false},
        # SQLite supplies uniqueness and atomic conditional updates for tests.
        # This development dependency is excluded from package requirements.
        {:ash_sqlite, "~> 0.3.1", only: [:dev, :test], runtime: false},
        # Real PostgreSQL consumer tests use ASH_HOOKS_POSTGRES=1.
        # This development dependency is excluded from package requirements.
        {:ash_postgres, "~> 2.0", only: [:dev, :test], runtime: false}
      ]
  end

  defp package do
    [
      maintainers: ["rjpalermo"],
      # Shipped docs point adopters at paths within the documentation tree. Subtrees
      # are named individually (not `documentation`) so untracked files at
      # its root (.DS_Store) can never ride a glob into the tarball.
      files:
        ~w(lib .formatter.exs mix.exs README* LICENSE LICENSES/MIT.txt LICENSES/CC-BY-4.0.txt CHANGELOG* usage-rules* SECURITY* CONTRIBUTING* CODE_OF_CONDUCT.md documentation/tutorials documentation/how-to documentation/topics/delivery documentation/topics/support documentation/reference documentation/livebooks documentation/dsls),
      licenses: ["MIT"],
      links: %{"GitHub" => @source_url}
    ]
  end

  defp docs do
    dsl_extras =
      @spark_extensions
      |> String.split(",")
      |> Enum.sort()
      |> Enum.map(fn name ->
        {"documentation/dsls/DSL-#{name}.md",
         search_data: Spark.Docs.search_data_for(Module.concat([name]))}
      end)

    [
      main: "readme",
      # 3.7.0 was published under the legacy tag before package-scoped tags.
      source_ref: if(@version == "3.7.0", do: "v3.7.0", else: "baselabs_ash_hooks-v#{@version}"),
      source_url: @source_url,
      # No EPUB: ExDoc stamps the build time into it. HexDocs offers HTML and
      # Markdown.
      formatters: ["html", "markdown"],
      extra_section: "Guides",
      extras:
        [
          {"README.md", title: "Home"},
          "documentation/tutorials/get-started.md",
          {"documentation/livebooks/get-started.livemd", filename: "guided-tour"},
          "documentation/tutorials/row-security.md",
          "documentation/tutorials/pinned-egress.md",
          {"documentation/how-to/index.md", filename: "integration-guides"},
          "documentation/how-to/receive-http.md",
          "documentation/how-to/verify-any-sender.md",
          "documentation/how-to/verify-remote-keys.md",
          "documentation/how-to/protect-against-replay.md",
          "documentation/how-to/handle-inbound-events.md",
          "documentation/how-to/configure-inbound-sources.md",
          "documentation/how-to/publish-transactionally.md",
          "documentation/how-to/outbound-contracts.md",
          "documentation/how-to/pause-subscriptions.md",
          "documentation/how-to/sign-with-a-host.md",
          "documentation/how-to/configure-outbound-transport.md",
          "documentation/how-to/observe-deliveries.md",
          "documentation/how-to/outbound-recovery.md",
          "documentation/how-to/key-custody.md",
          "documentation/how-to/bind-databases.md",
          "documentation/how-to/tenancy-adoption-checklist.md",
          "documentation/topics/delivery/delivery-lifecycle.md",
          "documentation/topics/support/compatibility.md",
          "documentation/topics/support/security-guarantees.md",
          {"documentation/topics/support/upgrading.md", filename: "upgrading"},
          "documentation/reference/reference.md"
        ] ++
          dsl_extras ++
          [
            "usage-rules.md",
            "CHANGELOG.md",
            "SECURITY.md",
            "CONTRIBUTING.md",
            "CODE_OF_CONDUCT.md"
          ],
      groups_for_extras: [
        Tutorials: ~r"^documentation/(tutorials|livebooks)/",
        "How-to guides": ~r"^documentation/how-to/",
        Delivery: ~r"^documentation/topics/delivery/",
        Support: ~r"^documentation/topics/support/",
        Reference: ~r"^documentation/(dsls|reference)/|^usage-rules[.]md$",
        "About AshHooks": [
          "CHANGELOG.md",
          "SECURITY.md",
          "CONTRIBUTING.md",
          "CODE_OF_CONDUCT.md"
        ]
      ],
      groups_for_modules: [
        "Webhook declarations": [
          AshHooks,
          AshHooks.Info,
          AshHooks.Inbound,
          AshHooks.Outbound,
          AshHooks.Tenancy,
          AshHooks.PrimaryKey,
          AshHooks.Binding
        ],
        Inbound: [
          AshHooks.Ingress,
          AshHooks.Ingress.BatchResult,
          AshHooks.Plug,
          AshHooks.BodyReader,
          AshHooks.InboundDelivery,
          AshHooks.InboundDelivery.LegacyAdoption,
          AshHooks.InboundDelivery.Payload,
          AshHooks.InboundSource,
          AshHooks.Inbound.BindingEvidence,
          AshHooks.Inbound.EnrollmentRef,
          AshHooks.Inbound.ResolvedSource,
          AshHooks.Inbound.RouteBinding,
          AshHooks.Inbound.VerifiedMember,
          AshHooks.Inbound.VerifiedSubject,
          AshHooks.ConfirmationPolicy,
          AshHooks.ConfirmationPolicy.Reconciliation
        ],
        Verification: [
          AshHooks.Provider,
          AshHooks.Provider.Conformance,
          AshHooks.Provider.DeliveryContext,
          AshHooks.Provider.Event,
          AshHooks.Provider.Hmac,
          AshHooks.Provider.Scheme,
          AshHooks.Provider.Signature,
          AshHooks.Provider.SignedTimestamp,
          AshHooks.RemoteKeyProfile,
          AshHooks.RemoteKeyProfile.Enrollment,
          AshHooks.RemoteKeyProfile.Verified,
          AshHooks.VerificationKeys.Cache
        ],
        Outbound: [
          AshHooks.Event,
          AshHooks.Type.EventType,
          AshHooks.Endpoint,
          AshHooks.Endpoint.SecretRef,
          AshHooks.Endpoint.Url,
          AshHooks.Subscription,
          AshHooks.Subscription.Pin,
          AshHooks.OutboundDelivery,
          AshHooks.OutboundAttempt,
          AshHooks.OutboundEvent,
          AshHooks.OutboundBinding,
          AshHooks.OutboundOutbox,
          AshHooks.Changes.Publish,
          AshHooks.Dispatcher,
          AshHooks.Delivery,
          AshHooks.Worker,
          AshHooks.Catalog,
          AshHooks.OpenApi,
          AshHooks.Outbound.Message,
          AshHooks.EndpointHealth,
          AshHooks.Telemetry
        ],
        "Signing and key custody": [
          AshHooks.Signing,
          AshHooks.Signer,
          AshHooks.Legacy,
          AshHooks.Custody,
          AshHooks.Custody.Key,
          AshHooks.Custody.PublicKey,
          AshHooks.Custody.Conformance,
          AshHooks.KeyRegistry
        ],
        Testing: [
          AshHooks.Provider.Mock,
          AshHooks.Provider.Mock.Event
        ],
        Egress: [
          AshHooks.Egress,
          AshHooks.Egress.Destination,
          AshHooks.Egress.Error,
          AshHooks.Egress.Response,
          AshHooks.Egress.ReqAdapter,
          AshHooks.DestinationPolicy,
          AshHooks.Ssrf,
          AshHooks.Transport,
          AshHooks.Http,
          AshHooks.Http.Bounded,
          AshHooks.Http.CertSan,
          AshHooks.Http.Httpc,
          AshHooks.Http.Request
        ],
        Errors: [AshHooks.Errors, ~r"^AshHooks[.]Errors[.]"]
      ]
    ]
  end

  defp aliases do
    [
      covering_tests: &covering_tests/1,
      credo: "credo --strict",
      sobelow: "sobelow --skip",
      # Regenerates the exported `locals_without_parens` in .formatter.exs and
      # the DSL references in documentation/dsls.
      "spark.generate": [
        "spark.formatter --extensions #{@spark_extensions}",
        "run --no-start scripts/generate-dsl-docs.exs #{@spark_extensions}"
      ],
      # Fails when either generated file drifts from the DSL.
      "spark.check": [
        "spark.formatter --extensions #{@spark_extensions} --check",
        "run --no-start scripts/generate-dsl-docs.exs #{@spark_extensions} --check"
      ]
    ]
  end

  defp covering_tests(args) do
    {base, selection_file} =
      case args do
        [base] -> {base, nil}
        [base, "--selection-file", file] -> {base, file}
        _ -> Mix.raise("usage: mix covering_tests BASE_REF [--selection-file PATH]")
      end

    if Mix.env() != :test, do: Mix.raise("run covering_tests with MIX_ENV=test")

    # .github/covering.toml declares the CI gate job's commands; the helper
    # checks that declaration against the workflow and runs them in order.
    status = Mix.shell().cmd("python3 scripts/covering_parity.py gate")
    if status != 0, do: Mix.raise("edit checks failed with exit status #{status}")

    Mix.Task.run("compile", ["--warnings-as-errors"])
    task = Mix.Task.get!("covering_tests")
    {tests, postgres?} = task.select(base, File.cwd!())

    case selection_file do
      nil -> run_covering_slice(tests, postgres?)
      path -> File.write!(path, [to_string(postgres?), "\n", task.selection_lines(tests)])
    end
  end

  defp run_covering_slice([], _postgres?), do: Mix.shell().info("No covering tests selected")

  defp run_covering_slice(tests, postgres?) do
    paths = if tests == :all, do: [], else: tests

    if postgres? and System.get_env("ASH_HOOKS_REAL_RECEIVER_PORT") in [nil, ""] do
      Mix.raise("PostgreSQL covering needs the platform engine and ASH_HOOKS_REAL_RECEIVER_PORT")
    end

    covering_test!(paths, [{"ASH_HOOKS_POSTGRES", nil}, {"ASH_HOOKS_REAL_RECEIVER_PORT", nil}])
    if postgres?, do: covering_test!(paths, [{"ASH_HOOKS_POSTGRES", "1"}])
  end

  defp covering_test!(paths, env) do
    {_, status} =
      System.cmd("mix", ["test", "--exclude", "livebook" | paths],
        env: env,
        into: IO.stream(:stdio, :line)
      )

    if status != 0, do: Mix.raise("mix test exited with status #{status}")
  end
end