distillery v0.9.3 Mix.Releases.Plugin behaviour

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 implentations for the following callbacks:

  • c:before_assembly/1
  • c:after_assembly/1
  • c:before_package/1
  • c:after_package/1
  • c:after_cleanup/1

Currently, there are no default implementations. You are required to implement all callbacks yourself.

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.Logger. These should be used to present output to the user.

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

c:after_cleanup/1 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) do
    info "This is executed just prior to assembling the release"
    release # or nil
  end

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

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

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

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

Summary

Functions

Run the c:after_assembly/1 callback of all plugins of release

Run the c:after_cleanup/1 callback of all plugins of release

Run the c:after_package/1 callback of all plugins of release

Run the c:before_assembly/1 callback of all plugins of release

Run the c:before_package/1 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

Functions

after_assembly(release)

Specs

after_assembly(Mix.Releases.Release.t) ::
  {:ok, Mix.Releases.Release.t} |
  {:error, term}

Run the c:after_assembly/1 callback of all plugins of release.

after_cleanup(release, args)

Specs

after_cleanup(Mix.Releases.Release.t, [String.t]) ::
  :ok |
  {:error, term}

Run the c:after_cleanup/1 callback of all plugins of release.

after_package(release)

Specs

after_package(Mix.Releases.Release.t) ::
  {:ok, Mix.Releases.Release.t} |
  {:error, term}

Run the c:after_package/1 callback of all plugins of release.

before_assembly(release)

Specs

before_assembly(Mix.Releases.Release.t) ::
  {:ok, Mix.Releases.Release.t} |
  {:error, term}

Run the c:before_assembly/1 callback of all plugins of release.

before_package(release)

Specs

before_package(Mix.Releases.Release.t) ::
  {:ok, Mix.Releases.Release.t} |
  {:error, term}

Run the c:before_package/1 callback of all plugins of release.

Callbacks

after_assembly(arg0)

Specs

Called after assembling the release.

Should return a modified %Release{} or nil.

after_cleanup(list)

Specs

after_cleanup([String.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.

after_package(arg0)

Specs

Called after packaging the release.

Should return a modified %Release{} or nil.

When in dev_mode, the packaging phase is skipped.

before_assembly(arg0)

Specs

Called before assembling the release.

Should return a modified %Release{} or nil.

before_package(arg0)

Specs

Called before packaging the release.

Should return a modified %Release{} or nil.

When in dev_mode, the packaging phase is skipped.