Configure Dialyxir with GitHub Actions
masterTo optimize Dialyxir runs in GitHub Actions, use a caching strategy for Preloaded Type Lists (PLTs). This prevents re-creating PLTs on every run, which is a time-consuming process.
Key implementation details:
- Cache Key: Use a key that incorporates the runner OS, Erlang/OTP version, Elixir version, and the hash of
mix.lock. This ensures the cache is invalidated when dependencies or the runtime change. - Cache Path: Store PLTs in
priv/plts. - Separate Save Step: Use
actions/cache/saveas a distinct step fromactions/cache/restore. This ensures that ifmix dialyzerfails (which is common when new warnings are introduced), the successfully created PLT cache is still saved for future runs. - Output Formats: When running
mix dialyzer, use both--format githuband--format dialyxir.--format github: Enables GitHub to display warnings directly in the Pull Request /files annotation view.--format dialyxir: Ensures the raw logs contain the full warning details for easier debugging.
steps:
- name: Check out source
uses: actions/checkout@v2
- name: Set up Elixir
id: beam
uses: erlef/setup-beam@v1
with:
otp-version: "24.1"
elixir-version: "1.12.3"
- name: Restore PLT cache
id: plt_cache
uses: actions/cache/restore@v3
with:
key: |
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }-}
path: |
priv/plts
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt
- name: Save PLT cache
id: plt_cache_save
uses: actions/cache/save@v3
if: steps.plt_cache.outputs.cache-hit != 'true'
with:
key: |
plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }}
path: |
priv/plts
- name: Run dialyzer
run: mix dialyzer --format github --format dialyxir