Elixir and Erlang
This guide will help build Elixir and Erlang projects on Semaphore.
Overview
The Elixir and Erlang toolchains are pre-installed in Linux machines. You can switch the active compiler using sem-version.
How to change Elixir versions
Elixir is available on Linux Ubuntu machines and Docker Environments.
On Linux machines use sem-version
. For example to switch to v1.16:
sem-version elixir 1.16
Using Docker containers
Semaphore distributes the pre-built semaphoreci:elixir
image on the Semaphore Container Registry. Find Dockerfiles to build your custom images in the semaphoreci/docker-images repository.
How to cache Elixir dependencies
The cache tool automatically detects the presence Mix dependencies and compiled code
The first job in the pipeline must cache the dependencies:
checkout
mix local.hex --force
mix local.rebar --force
cache restore
mix do deps.get, compile
cache store
The rest of the jobs can use the cache directly to retrieve dependencies and compiled code:
checkout
cache restore
How to set up test reports
This section explains how to set up test reports (and flaky tests) for Elixir and mix.
-
Add junit-formatter to your
mix.exs
dependenciesdefp deps do
[
# ...
{:junit_formatter, "~> 3.1", only: [:test]}
]
end -
Install dependencies
mix deps.get
-
Extend your
config/test.exs
config :junit_formatter,
report_dir: "/tmp",
report_file: "junit.xml", # Save output to "/tmp/junit.xml"
print_report_file: true, # Adds information about file location when suite finishes
include_filename?: true, # Include filename and file number for more insights
include_file_line?: true -
Extend your
tests/test_helper.exs
ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter])
ExUnit.start() -
Create an after_pipeline job with the following command:
test-results publish /tmp/junit.xml
Example pipeline definition
- name: Tests
task:
prologue:
commands:
- checkout
- mix deps.get
jobs:
- name: Elixir Tests
commands:
- mix test
epilogue:
always:
commands:
- test-results publish /tmp/junit.xml
How to change Erlang versions
Elixir is available on Linux Ubuntu machines and Docker Environments.
On Linux machines use sem-version
. For example to switch to v25
sem-version erlang 25
How to run Erlang projects
Use earlc
to compile an Erlang source code to binary.
For instance, with a source file called hello.erl
:
%% Programmer: Mihalis Tsoukalos
%% Date: Friday 21 December 2018
-module(hello).
-export([helloWorld/0]).
helloWorld() -> io:fwrite("hello, world\n").
We can compile and run with:
checkout
sem-version erlang 25
erlc hello.erl
erl -noshell -s hello helloWorld -s init stop