1
+ name : Unit 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
+ paths :
10
+ - ' **.ex'
11
+ - ' **.exs'
12
+ - ' !**.md'
13
+ branches :
14
+ - main
15
+ pull_request :
16
+ branches :
17
+ - main
18
+
19
+ # Sets the ENV `MIX_ENV` to `test` for running tests
20
+ env :
21
+ MIX_ENV : test
22
+
23
+ permissions :
24
+ contents : read
25
+
26
+ jobs :
27
+ mix_test :
28
+ name : mix test (OTP ${{matrix.otp}} | Elixir ${{matrix.elixir}})
29
+
30
+ strategy :
31
+ matrix :
32
+ include :
33
+ - elixir : 1.14
34
+ otp : 24.2
35
+
36
+ runs-on : ubuntu-latest
37
+
38
+ steps :
39
+ # Step: Setup Elixir + Erlang image as the base.
40
+ - name : Set up Elixir
41
+ uses : erlef/setup-beam@v1
42
+ with :
43
+ elixir-version : ${{ matrix.elixir }}
44
+ otp-version : ${{ matrix.otp }}
45
+
46
+ # Step: Check out the code.
47
+ - name : Checkout
48
+ uses : actions/checkout@v3
49
+
50
+ # Step: Define how to cache deps. Restores existing cache if present.
51
+ - name : Cache deps
52
+ id : cache-deps
53
+ uses : actions/cache@v3
54
+ env :
55
+ cache-name : cache-elixir-deps
56
+ with :
57
+ path : deps
58
+ key : ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
59
+ restore-keys : |
60
+ ${{ runner.os }}-mix-${{ env.cache-name }}-
61
+
62
+ # Step: Define how to cache the `_build` directory. After the first run,
63
+ # this speeds up tests runs a lot. This includes not re-compiling our
64
+ # project's downloaded deps every run.
65
+ - name : Cache compiled build
66
+ id : cache-build
67
+ uses : actions/cache@v3
68
+ env :
69
+ cache-name : cache-compiled-build
70
+ with :
71
+ path : _build
72
+ key : ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
73
+ restore-keys : |
74
+ ${{ runner.os }}-mix-${{ env.cache-name }}-
75
+ ${{ runner.os }}-mix-
76
+
77
+ # Step: Conditionally bust the cache when job is re-run.
78
+ # Sometimes, we may have issues with incremental builds that are fixed by
79
+ # doing a full recompile. In order to not waste dev time on such trivial
80
+ # issues (while also reaping the time savings of incremental builds for
81
+ # *most* day-to-day development), force a full recompile only on builds
82
+ # that are retried.
83
+ - name : Clean to rule out incremental build as a source of flakiness
84
+ if : github.run_attempt != '1'
85
+ run : |
86
+ mix deps.clean --all
87
+ mix clean
88
+ shell : sh
89
+
90
+ # Step: Download project dependencies. If unchanged, uses
91
+ # the cached version.
92
+ - name : Install dependencies
93
+ run : mix deps.get
94
+
95
+ # Step: Compile the project treating any warnings as errors.
96
+ # Customize this step if a different behavior is desired.
97
+ - name : Compiles without warnings
98
+ run : mix compile --warnings-as-errors
99
+
100
+ # Step: Check that the checked in code has already been formatted.
101
+ # This step fails if something was found unformatted.
102
+ # Customize this step as desired.
103
+ - name : Check Formatting
104
+ run : mix format --check-formatted
105
+
106
+ - if : failure()
107
+ run : echo "### Failed on lint" >> $GITHUB_STEP_SUMMARY
108
+
109
+ # Step: Execute the tests.
110
+ - name : Run tests
111
+ run : mix test
0 commit comments