Skip to content

Commit 25c0611

Browse files
committed
Set up Elixir, Erlang/OTP CI matrix
1 parent 259ab23 commit 25c0611

2 files changed

Lines changed: 111 additions & 63 deletions

File tree

.github/workflows/elixir.yml

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,116 @@
11
name: Elixir CI
22

3-
on: push
3+
# Define workflow that runs when changes are pushed to the
4+
# `main` branch or pushed to a PR branch that targets the `main`
5+
# branch. Change the branch name if your project uses a
6+
# different name for the main branch like "master" or "production".
7+
on:
8+
push:
9+
branches: ["main"] # adapt branch for project
10+
pull_request:
11+
branches: ["main"] # adapt branch for project
412

5-
jobs:
6-
compile:
7-
runs-on: ubuntu-latest
8-
container:
9-
image: elixir:1.9.4-slim
10-
env:
11-
MIX_ENV: prod
12-
steps:
13-
- uses: actions/checkout@v1
14-
- name: install dependencies
15-
run: |
16-
mix local.rebar --force
17-
mix local.hex --force
18-
mix deps.get --only prod
19-
- name: compile
20-
run: mix compile --force
13+
# Sets the ENV `MIX_ENV` to `test` for running tests
14+
env:
15+
MIX_ENV: test
2116

17+
permissions:
18+
contents: read
19+
20+
jobs:
2221
test:
23-
runs-on: ubuntu-latest
24-
container:
25-
image: elixir:1.9.4-slim
26-
env:
27-
MIX_ENV: test
22+
runs-on: ubuntu-20.04
23+
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
24+
strategy:
25+
# Specify the OTP and Elixir versions to use when building
26+
# and running the workflow steps.
27+
matrix:
28+
otp: ["25.3.2.2", "26.0.1"] # Define the OTP version [required]
29+
elixir: ["1.14.5", "1.15.0"] # Define the elixir version [required]
2830
steps:
29-
- uses: actions/checkout@v1
30-
- name: install dependencies
31-
run: |
32-
mix local.rebar --force
33-
mix local.hex --force
34-
mix deps.get --only test
35-
- name: test
36-
run: mix test --cover --trace
37-
- name: archive code coverage
38-
uses: actions/upload-artifact@v1
31+
# Step: Setup Elixir + Erlang image as the base.
32+
- name: Set up Elixir
33+
uses: erlef/setup-beam@v1
3934
with:
40-
name: cover
41-
path: cover
35+
otp-version: ${{matrix.otp}}
36+
elixir-version: ${{matrix.elixir}}
4237

43-
static_code_analysis:
44-
runs-on: ubuntu-latest
45-
container:
46-
image: elixir:1.9.4-slim
47-
env:
48-
MIX_ENV: dev
49-
steps:
50-
- uses: actions/checkout@v1
51-
- name: install dependencies
52-
run: |
53-
mix local.rebar --force
54-
mix local.hex --force
55-
mix deps.get --only dev
56-
- name: plt cache
57-
uses: actions/cache@v1.1.0
38+
# Step: Check out the code.
39+
- name: Checkout code
40+
uses: actions/checkout@v3
41+
42+
# Step: Define how to cache deps. Restores existing cache if present.
43+
- name: Cache deps
44+
id: cache-deps
45+
uses: actions/cache@v3
46+
env:
47+
cache-name: cache-elixir-deps
48+
with:
49+
path: deps
50+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
51+
restore-keys: |
52+
${{ runner.os }}-mix-${{ env.cache-name }}-
53+
54+
# Step: Define how to cache the `_build` directory. After the first run,
55+
# this speeds up tests runs a lot. This includes not re-compiling our
56+
# project's downloaded deps every run.
57+
- name: Cache compiled build
58+
id: cache-build
59+
uses: actions/cache@v3
60+
env:
61+
cache-name: cache-compiled-build
5862
with:
5963
path: _build
60-
key: ${{ runner.os }}-plt-${{ env.GITHUB_REF }}
64+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
6165
restore-keys: |
62-
${{ runner.os }}-plt-
63-
- name: formatted?
64-
run: mix format --check-formatted --dry-run
65-
- name: credo
66-
run: mix credo --verbose
67-
- name: gradient
66+
${{ runner.os }}-mix-${{ env.cache-name }}-
67+
${{ runner.os }}-mix-
68+
69+
# Step: Conditionally bust the cache when job is re-run.
70+
# Sometimes, we may have issues with incremental builds that are fixed by
71+
# doing a full recompile. In order to not waste dev time on such trivial
72+
# issues (while also reaping the time savings of incremental builds for
73+
# *most* day-to-day development), force a full recompile only on builds
74+
# that are retried.
75+
- name: Clean to rule out incremental build as a source of flakiness
76+
if: github.run_attempt != '1'
77+
run: |
78+
mix deps.clean --all
79+
mix clean
80+
shell: sh
81+
82+
# Step: Download project dependencies. If unchanged, uses
83+
# the cached version.
84+
- name: Install dependencies
85+
run: mix deps.get
86+
87+
# Step: Compile the project treating any warnings as errors.
88+
# Customize this step if a different behavior is desired.
89+
- name: Compiles without warnings
90+
run: mix compile --warnings-as-errors
91+
92+
# Step: Check that the checked in code has already been formatted.
93+
# This step fails if something was found unformatted.
94+
# Customize this step as desired.
95+
- name: Check Formatting
96+
run: mix format --check-formatted
97+
98+
# Step: Execute the tests.
99+
- name: Run tests
100+
if: success() || failure()
101+
run: mix test
102+
103+
# Step: Run credo.
104+
- name: Run credo
105+
if: success() || failure()
106+
run: mix credo
107+
108+
# Step: Run dialyzer.
109+
- name: Run dialyzer
110+
if: success() || failure()
111+
run: mix dialyzer
112+
113+
# Step: Run gradient.
114+
- name: Run gradient
115+
if: success() || failure()
68116
run: mix gradient
69-
- name: dialyzer
70-
run: mix dialyzer --halt-exit-status

mix.exs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ defmodule ExRets.MixProject do
77
[
88
app: :ex_rets,
99
version: @version,
10-
elixir: "~> 1.9",
10+
elixir: "~> 1.14",
1111
name: "ExRets",
1212
description: "RETS client for Elixir.",
1313
start_permanent: Mix.env() == :prod,
1414
deps: deps(),
1515
docs: docs(),
16-
package: package()
16+
package: package(),
17+
dialyzer: [plt_add_apps: [:ex_unit]],
18+
preferred_cli_env: [credo: :test, dialyzer: :test, gradient: :test]
1719
]
1820
end
1921

@@ -25,10 +27,10 @@ defmodule ExRets.MixProject do
2527

2628
defp deps do
2729
[
28-
{:credo, "~> 1.1", only: :dev, runtime: false},
29-
{:dialyxir, "~> 1.3", only: :dev, runtime: false},
30+
{:credo, "~> 1.1", only: [:dev, :test], runtime: false},
31+
{:dialyxir, "~> 1.3", only: [:dev, :test], runtime: false},
3032
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
31-
{:gradient, github: "esl/gradient", only: :dev, runtime: false}
33+
{:gradient, github: "esl/gradient", only: [:dev, :test], runtime: false}
3234
]
3335
end
3436

0 commit comments

Comments
 (0)