Skip to content

Commit 29355dc

Browse files
committed
Add GHA CI
Adds linting and tests to CI.
1 parent 2790a45 commit 29355dc

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

.github/workflows/ci.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Linting & Tests
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" ]
10+
pull_request:
11+
branches: [ "main" ]
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+
runs-on: ubuntu-latest
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.0.4', '27.2'] # Define the OTP version [required]
29+
elixir: ['1.14.1', '1.18.4'] # Define the elixir version [required]
30+
exclude:
31+
- otp: '27.2'
32+
elixir: '1.14.1'
33+
steps:
34+
# Step: Setup Elixir + Erlang image as the base.
35+
- name: Set up Elixir
36+
uses: erlef/setup-beam@v1
37+
with:
38+
otp-version: ${{matrix.otp}}
39+
elixir-version: ${{matrix.elixir}}
40+
41+
# Step: Check out the code.
42+
- name: Checkout code
43+
uses: actions/checkout@v4
44+
45+
# Step: Define how to cache deps. Restores existing cache if present.
46+
- name: Cache deps
47+
id: cache-deps
48+
uses: actions/cache@v3
49+
env:
50+
cache-name: cache-elixir-deps
51+
with:
52+
path: deps
53+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
54+
restore-keys: |
55+
${{ runner.os }}-mix-${{ env.cache-name }}-
56+
57+
# Step: Define how to cache the `_build` directory. After the first run,
58+
# this speeds up tests runs a lot. This includes not re-compiling our
59+
# project's downloaded deps every run.
60+
- name: Cache compiled build
61+
id: cache-build
62+
uses: actions/cache@v3
63+
env:
64+
cache-name: cache-compiled-build
65+
with:
66+
path: _build
67+
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
68+
restore-keys: |
69+
${{ runner.os }}-mix-${{ env.cache-name }}-
70+
${{ runner.os }}-mix-
71+
72+
# Step: Conditionally bust the cache when job is re-run.
73+
# Sometimes, we may have issues with incremental builds that are fixed by
74+
# doing a full recompile. In order to not waste dev time on such trivial
75+
# issues (while also reaping the time savings of incremental builds for
76+
# *most* day-to-day development), force a full recompile only on builds
77+
# that are retried.
78+
- name: Clean to rule out incremental build as a source of flakiness
79+
if: github.run_attempt != '1'
80+
run: |
81+
mix deps.clean --all
82+
mix clean
83+
shell: sh
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: Check that the checked in code has already been formatted.
96+
# This step fails if something was found unformatted.
97+
# Customize this step as desired.
98+
- name: Check Formatting
99+
run: mix format --check-formatted
100+
101+
# Step: Execute the tests.
102+
- name: Run tests
103+
run: mix test

0 commit comments

Comments
 (0)