distillery v2.0.8 Mix.Releases.Plugin behaviour View Source

This module provides a simple way to add additional processing to phases of the release assembly and archival.

Implementing your own plugin

To create a Distillery plugin, create a new module in which you use Mix.Releases.Plugin. Then write implementations for the following callbacks:

The default implementation is to pass the original %Release{}. You will only need to implement the functions your plugin requires.

When you use Mix.Releases.Plugin, the following happens:

  • Your module is marked with @behaviour Mix.Releases.Plugin.
  • The Mix.Releases.Release struct is aliased to %Release{}.
  • The functions debug/1, info/1, warn/1, notice/1, and error/1 are imported from Mix.Releases.Shell. These should be used to present output to the user.

The first four callbacks (before_assembly/2, after_assembly/2, before_package/2, and after_package/2) will each be passed the %Release{} struct and options passed to the plugin. You can return a modified struct, or nil. Any other return value will lead to runtime errors.

after_cleanup/2 is only invoked on mix release.clean. It will be passed the command line arguments. The return value is not used.

Example

defmodule MyApp.PluginDemo do
  use Mix.Releases.Plugin

  def before_assembly(%Release{} = release, _opts) do
    info "This is executed just prior to assembling the release"
    release # or nil
  end

  def after_assembly(%Release{} = release, _opts) do
    info "This is executed just after assembling, and just prior to packaging the release"
    release # or nil
  end

  def before_package(%Release{} = release, _opts) do
    info "This is executed just before packaging the release"
    release # or nil
  end

  def after_package(%Release{} = release, _opts) do
    info "This is executed just after packaging the release"
    release # or nil
  end

  def after_cleanup(_args, _opts) do
    info "This is executed just after running cleanup"
    :ok # It doesn't matter what we return here
  end
end

Link to this section Summary

Functions

Run the after_assembly/2 callback of all plugins of release

Run the after_cleanup/2 callback of all plugins of release

Run the after_package/2 callback of all plugins of release

Run the before_assembly/2 callback of all plugins of release

Run the before_package/2 callback of all plugins of release

Callbacks

Called after assembling the release

Called when the user invokes the mix release.clean task

Called after packaging the release

Called before assembling the release

Called before packaging the release

Link to this section Functions

Link to this function after_assembly(release) View Source
after_assembly(Mix.Releases.Release.t()) ::
  {:ok, Mix.Releases.Release.t()} | {:error, term()}

Run the after_assembly/2 callback of all plugins of release.

Link to this function after_cleanup(release, args) View Source
after_cleanup(Mix.Releases.Release.t(), [String.t()]) :: :ok | {:error, term()}

Run the after_cleanup/2 callback of all plugins of release.

Link to this function after_package(release) View Source
after_package(Mix.Releases.Release.t()) ::
  {:ok, Mix.Releases.Release.t()} | {:error, term()}

Run the after_package/2 callback of all plugins of release.

Link to this function before_assembly(release) View Source
before_assembly(Mix.Releases.Release.t()) ::
  {:ok, Mix.Releases.Release.t()} | {:error, term()}

Run the before_assembly/2 callback of all plugins of release.

Link to this function before_package(release) View Source
before_package(Mix.Releases.Release.t()) ::
  {:ok, Mix.Releases.Release.t()} | {:error, term()}

Run the before_package/2 callback of all plugins of release.

Link to this section Callbacks

Link to this callback after_assembly(arg0, arg1) View Source
after_assembly(Mix.Releases.Release.t(), Keyword.t()) ::
  Mix.Releases.Release.t() | nil

Called after assembling the release.

Should return a modified %Release{} or nil.

Link to this callback after_cleanup(list, arg1) View Source
after_cleanup([String.t()], Keyword.t()) :: any()

Called when the user invokes the mix release.clean task.

The callback will be passed the command line arguments to mix release.clean. It should clean up the files the plugin created. The return value of this callback is ignored.

Called after packaging the release.

Should return a modified %Release{} or nil.

When in dev_mode, the packaging phase is skipped.

Link to this callback before_assembly(arg0, arg1) View Source
before_assembly(Mix.Releases.Release.t(), Keyword.t()) ::
  Mix.Releases.Release.t() | nil

Called before assembling the release.

Should return a modified %Release{} or nil.

Link to this callback before_package(arg0, arg1) View Source
before_package(Mix.Releases.Release.t(), Keyword.t()) ::
  Mix.Releases.Release.t() | nil

Called before packaging the release.

Should return a modified %Release{} or nil.

When in dev_mode, the packaging phase is skipped.