@@ -4,6 +4,9 @@ name: Checks
4
4
# Sets the ENV `MIX_ENV` to `test` for running tests
5
5
env :
6
6
MIX_ENV : test
7
+ # Artificially refresh the cache
8
+ DEPENDENCIES_CACHE_VERSION : 1
9
+ PLT_CACHE_VERSION : 1
7
10
8
11
permissions :
9
12
contents : read
56
59
cache-name : cache-elixir-deps
57
60
with :
58
61
path : deps
59
- key : ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
62
+ key : ${{ runner.os }}-mix-${{ env.cache-name }-${{ env.DEPENDENCIES_CACHE_VERSION }} }-${{ hashFiles('**/mix.lock') }}
60
63
restore-keys : |
61
- ${{ runner.os }}-mix-${{ env.cache-name }}-
64
+ ${{ runner.os }}-mix-${{ env.cache-name }}-${{ env.DEPENDENCIES_CACHE_VERSION }}-
65
+
66
+ # Step: Define how to cache the `_build` directory. After the first run,
67
+ # this speeds up tests runs a lot. This includes not re-compiling our
68
+ # project's downloaded deps every run.
69
+ - name : Cache compiled build
70
+ id : cache-build
71
+ uses : actions/cache@v3
72
+ env :
73
+ cache-name : cache-compiled-build
74
+ with :
75
+ path : _build
76
+ key : ${{ runner.os }}-mix-${{ env.cache-name }}-${{ env.DEPENDENCIES_CACHE_VERSION }}-${{ hashFiles('**/mix.lock') }}
77
+ restore-keys : |
78
+ ${{ runner.os }}-mix-${{ env.cache-name }}-${{ env.DEPENDENCIES_CACHE_VERSION }}-
79
+ ${{ runner.os }}-mix-
80
+
81
+ # Step: Conditionally bust the cache when job is re-run. Sometimes, we
82
+ # may have issues with incremental builds that are fixed by doing a full
83
+ # recompile. In order to not waste dev time on such trivial issues (while
84
+ # also reaping the time savings of incremental builds for *most*
85
+ # day-to-day development), force a full recompile only on builds that are
86
+ # retried.
87
+ - name : Clean to rule out incremental build as a source of flakiness
88
+ if : github.run_attempt != '1'
89
+ run : |
90
+ mix deps.clean --all
91
+ mix clean
92
+ shell : sh
93
+
94
+ # Step: Download project dependencies. If unchanged, uses the cached
95
+ # version.
96
+ - name : Install dependencies
97
+ run : mix deps.get
98
+
99
+ # Step: Compile the project treating any warnings as errors.
100
+ - name : Compiles without warnings
101
+ run : mix compile --warnings-as-errors
102
+
103
+ # Step: Setup the database for the tests.
104
+ - name : Setup db
105
+ run : mix ecto.setup
106
+
107
+ # Step: Execute the tests.
108
+ - name : Run tests
109
+ run : mix test
110
+
111
+ ensure_code_consistency :
112
+ runs-on : ubuntu-latest
113
+ name : Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
114
+ steps :
115
+ # Step: Setup Elixir + Erlang image as the base.
116
+ - name : Set up Elixir
117
+ uses : erlef/setup-beam@v1
118
+ with :
119
+ otp-version : ${{matrix.otp}}
120
+ elixir-version : ${{matrix.elixir}}
121
+
122
+ # Step: Check out the code.
123
+ - name : Checkout code
124
+ uses : actions/checkout@v3
125
+
126
+ # Step: Define how to cache deps. Restores existing cache if present.
127
+ - name : Cache deps
128
+ id : cache-deps
129
+ uses : actions/cache@v3
130
+ env :
131
+ cache-name : cache-elixir-deps
132
+ with :
133
+ path : deps
134
+ key : ${{ runner.os }}-mix-${{ env.cache-name }}-${{ env.DEPENDENCIES_CACHE_VERSION }}-${{ hashFiles('**/mix.lock') }}
135
+ restore-keys : |
136
+ ${{ runner.os }}-mix-${{ env.cache-name }}-${{ env.DEPENDENCIES_CACHE_VERSION }}-
62
137
63
138
# Step: Define how to cache the `_build` directory. After the first run,
64
139
# this speeds up tests runs a lot. This includes not re-compiling our
86
161
run : |
87
162
mix deps.clean --all
88
163
mix clean
89
- shell : sh
164
+ shell : s
90
165
91
166
# Step: Download project dependencies. If unchanged, uses the cached
92
167
# version.
@@ -97,18 +172,47 @@ jobs:
97
172
- name : Compiles without warnings
98
173
run : mix compile --warnings-as-errors
99
174
100
- # Step: Check that the checked in code has already been formatted.
175
+ # Step: Check that the code has already been formatted.
101
176
- name : Check Formatting
102
177
run : mix format --check-formatted
103
178
104
- # Step: Check that the checked in code complies with the credo rules.
179
+ # Step: Check that the code complies with the credo rules.
105
180
- name : Check Credo
106
181
run : mix credo -A
107
182
108
- # Step: Setup the database for the tests .
109
- - name : Setup db
110
- run : mix ecto.setup
183
+ # Step: Check that the documentation and specs complies with the doctor rules .
184
+ - name : Check Doctor
185
+ run : mix doctor
111
186
112
- # Step: Execute the tests.
113
- - name : Run tests
114
- run : mix test
187
+ # Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
188
+ # Cache key based on Elixir & Erlang version (also useful when running in matrix)
189
+ - name : Restore PLT cache
190
+ uses : actions/cache/restore@v4
191
+ id : plt_cache
192
+ with :
193
+ key : |
194
+ plt-${{ runner.os }}-${{ env.PLT_CACHE_VERSION }}
195
+ restore-keys : |
196
+ plt-${{ runner.os }}-${{ env.PLT_CACHE_VERSION }}
197
+ path : |
198
+ priv/plts
199
+
200
+ # Create PLTs if no cache was found
201
+ - name : Create PLTs
202
+ if : steps.plt_cache.outputs.cache-hit != 'true'
203
+ run : mix dialyzer --plt
204
+
205
+ # By default, the GitHub Cache action will only save the cache if all steps in the job succeed,
206
+ # so we separate the cache restore and save steps in case running dialyzer fails.
207
+ - name : Save PLT cache
208
+ uses : actions/cache/save@v4
209
+ if : steps.plt_cache.outputs.cache-hit != 'true'
210
+ id : plt_cache_save
211
+ with :
212
+ key : |
213
+ plt-${{ runner.os }}-${{ env.PLT_CACHE_VERSION }}
214
+ path : |
215
+ priv/plts
216
+
217
+ - name : Run dialyzer
218
+ run : mix dialyzer --format raw
0 commit comments