Skip to content

Commit dd2c856

Browse files
committed
add github ci/cd for elixir
1 parent ce04dc0 commit dd2c856

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

.github/workflows/elixir.yaml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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: [ "master" ]
10+
pull_request:
11+
branches: [ "master" ]
12+
13+
# Sets the ENV `MIX_ENV` to `test` for running tests
14+
env:
15+
MIX_ENV: test
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
test:
22+
# Set up a Postgres DB service. By default, Phoenix applications
23+
# use Postgres. This creates a database for running tests.
24+
# Additional services can be defined here if required.
25+
# services:
26+
# db:
27+
# image: postgres:12
28+
# ports: ['5432:5432']
29+
# env:
30+
# POSTGRES_PASSWORD: postgres
31+
# options: >-
32+
# --health-cmd pg_isready
33+
# --health-interval 10s
34+
# --health-timeout 5s
35+
# --health-retries 5
36+
37+
runs-on: ubuntu-latest
38+
name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
39+
strategy:
40+
# Specify the OTP and Elixir versions to use when building
41+
# and running the workflow steps.
42+
matrix:
43+
otp: ['26.1.1'] # Define the OTP version [required]
44+
elixir: ['1.15.7'] # Define the elixir version [required]
45+
steps:
46+
# Step: Setup Elixir + Erlang image as the base.
47+
- name: Set up Elixir
48+
uses: erlef/setup-beam@v1
49+
with:
50+
otp-version: ${{matrix.otp}}
51+
elixir-version: ${{matrix.elixir}}
52+
53+
# Step: Check out the code.
54+
- name: Checkout code
55+
uses: actions/checkout@v3
56+
57+
# Step: Define how to cache deps. Restores existing cache if present.
58+
- name: Cache deps
59+
id: cache-deps
60+
uses: actions/cache@v3
61+
env:
62+
cache-name: cache-elixir-deps
63+
with:
64+
path: deps
65+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
66+
restore-keys: |
67+
${{ runner.os }}-mix-${{ env.cache-name }}-
68+
69+
# Step: Define how to cache the `_build` directory. After the first run,
70+
# this speeds up tests runs a lot. This includes not re-compiling our
71+
# project's downloaded deps every run.
72+
- name: Cache compiled build
73+
id: cache-build
74+
uses: actions/cache@v3
75+
env:
76+
cache-name: cache-compiled-build
77+
with:
78+
path: _build
79+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
80+
restore-keys: |
81+
${{ runner.os }}-mix-${{ env.cache-name }}-
82+
${{ runner.os }}-mix-
83+
84+
# Step: Conditionally bust the cache when job is re-run.
85+
# Sometimes, we may have issues with incremental builds that are fixed by
86+
# doing a full recompile. In order to not waste dev time on such trivial
87+
# issues (while also reaping the time savings of incremental builds for
88+
# *most* day-to-day development), force a full recompile only on builds
89+
# that are retried.
90+
- name: Clean to rule out incremental build as a source of flakiness
91+
if: github.run_attempt != '1'
92+
run: |
93+
mix deps.clean --all
94+
mix clean
95+
shell: sh
96+
97+
# Step: Download project dependencies. If unchanged, uses
98+
# the cached version.
99+
- name: Install dependencies
100+
run: mix deps.get
101+
102+
# Step: Compile the project treating any warnings as errors.
103+
# Customize this step if a different behavior is desired.
104+
105+
# - name: Compiles without warnings
106+
# run: mix compile --warnings-as-errors
107+
108+
- name: Compiles
109+
run: mix compile
110+
111+
# Step: Check that the checked in code has already been formatted.
112+
# This step fails if something was found unformatted.
113+
# Customize this step as desired.
114+
- name: Check Formatting
115+
run: mix format --check-formatted
116+
117+
# Step: Execute the tests.
118+
- name: Run tests
119+
run: mix test

0 commit comments

Comments
 (0)