Skip to content

Commit 5b349a8

Browse files
committed
add github ci workflow
1 parent 0585960 commit 5b349a8

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

.github/workflows/elixir.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: Elixir CI
2+
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
12+
13+
# Sets the environment variables for running tests
14+
env:
15+
MIX_ENV: test
16+
TEST_DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/postgres"
17+
18+
permissions:
19+
contents: read
20+
21+
jobs:
22+
test:
23+
# Set up a Postgres DB service. By default, Phoenix applications
24+
# use Postgres. This creates a database for running tests.
25+
# Additional services can be defined here if required.
26+
services:
27+
db:
28+
image: postgres:12
29+
ports: ["5432:5432"]
30+
env:
31+
POSTGRES_PASSWORD: postgres
32+
options: >-
33+
--health-cmd pg_isready
34+
--health-interval 10s
35+
--health-timeout 5s
36+
--health-retries 5
37+
38+
runs-on: ubuntu-latest
39+
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
40+
strategy:
41+
# Specify the OTP and Elixir versions to use when building
42+
# and running the workflow steps.
43+
matrix:
44+
otp: ["27.2"] # Define the OTP version [required]
45+
elixir: ["1.18.1"] # Define the elixir version [required]
46+
steps:
47+
# Step: Setup Elixir + Erlang image as the base.
48+
- name: Set up Elixir
49+
uses: erlef/setup-beam@v1
50+
with:
51+
otp-version: ${{matrix.otp}}
52+
elixir-version: ${{matrix.elixir}}
53+
54+
# Step: Check out the code.
55+
- name: Checkout code
56+
uses: actions/checkout@v3
57+
58+
# Step: Define how to cache deps. Restores existing cache if present.
59+
- name: Cache deps
60+
id: cache-deps
61+
uses: actions/cache@v3
62+
env:
63+
cache-name: cache-elixir-deps
64+
with:
65+
path: deps
66+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
67+
restore-keys: |
68+
${{ runner.os }}-mix-${{ env.cache-name }}-
69+
70+
# Step: Define how to cache the `_build` directory. After the first run,
71+
# this speeds up tests runs a lot. This includes not re-compiling our
72+
# project's downloaded deps every run.
73+
- name: Cache compiled build
74+
id: cache-build
75+
uses: actions/cache@v3
76+
env:
77+
cache-name: cache-compiled-build
78+
with:
79+
path: _build
80+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
81+
restore-keys: |
82+
${{ runner.os }}-mix-${{ env.cache-name }}-
83+
${{ runner.os }}-mix-
84+
85+
# Step: Download project dependencies. If unchanged, uses
86+
# the cached version.
87+
- name: Install dependencies
88+
run: mix deps.get
89+
90+
# Step: Compile the project treating any warnings as errors.
91+
# Customize this step if a different behavior is desired.
92+
- name: Compiles without warnings
93+
run: mix compile --warnings-as-errors
94+
95+
# Step: Restore PLT cache. Cache key based on Erlang/Elixir version and the mix.lock hash
96+
- name: Restore PLT cache
97+
id: plt_cache
98+
uses: actions/cache/restore@v3
99+
with:
100+
key: |
101+
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
102+
restore-keys: |
103+
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-
104+
path: |
105+
priv/plts
106+
107+
# Step: Create PLTs if no cache was found
108+
- name: Create PLTs
109+
if: steps.plt_cache.outputs.cache-hit != 'true'
110+
run: mix dialyzer --plt
111+
112+
# Step: Save PLT cache. By default, the GitHub Cache action will only save the cache if all steps in the job succeed, so we separate the cache restore and save steps in case running dialyzer fails.
113+
- name: Save PLT cache
114+
id: plt_cache_save
115+
uses: actions/cache/save@v3
116+
if: steps.plt_cache.outputs.cache-hit != 'true'
117+
with:
118+
key: |
119+
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
120+
path: |
121+
priv/plts
122+
123+
# Step: Run dialyzer
124+
- name: Run dialyzer
125+
# Two formats are included for ease of debugging and it is lightly recommended to use both, see https://github.com/jeremyjh/dialyxir/issues/530 for reasoning
126+
# --format github is helpful to print the warnings in a way that GitHub understands and can place on the /files page of a PR
127+
# --format dialyxir allows the raw GitHub actions logs to be useful because they have the full warning printed
128+
run: mix dialyzer --format github --format dialyxir
129+
130+
# Step: Check that the checked in code has already been formatted.
131+
# This step fails if something was found unformatted.
132+
# Customize this step as desired.
133+
- name: Check Formatting
134+
run: mix format --check-formatted
135+
136+
# Step: Execute the tests.
137+
- name: Run tests
138+
run: mix test

0 commit comments

Comments
 (0)