Skip to content

Commit

Permalink
Resolve Dialyzer errors on Elixir 1.16 (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathany-copia authored Jun 19, 2024
1 parent 27cc13e commit 34a5108
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
72 changes: 62 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
strategy:
matrix:
include:
- otp: '25.3.2.12'
elixir: '1.15.8'
- elixir: '1.15.8'
otp: '25.3.2.12'
experimental: false
lint: false
- otp: '26.2.5'
elixir: '1.16.3'
- elixir: '1.16.3'
otp: '26.2.5'
experimental: true
lint: true
- otp: '27.0'
elixir: '1.17.1'
- elixir: '1.17.1'
otp: '27.0'
experimental: true
lint: false
steps:
Expand All @@ -32,11 +32,13 @@ jobs:
version-type: strict
- name: Restore dependencies cache
uses: actions/cache@v4
id: cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
env:
MIX_ENV: test
run: |
Expand All @@ -63,10 +65,11 @@ jobs:
version-type: strict
- name: Restore dependencies cache
uses: actions/cache@v4
id: cache
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('test/lockfiles/gun1.lock') }}
restore-keys: ${{ runner.os }}-mix-
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-gun-${{ hashFiles('test/lockfiles/gun1.lock') }}
restore-keys: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-gun-
- name: Install Dependencies
env:
MIX_ENV: test
Expand All @@ -79,3 +82,52 @@ jobs:
env:
LOCKFILE: gun1
run: mix test test/tesla/adapter/gun_test.exs --trace

dialyzer:
runs-on: ubuntu-latest
name: Dialyzer
steps:
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.16.3'
otp-version: '26.2.5'
version-type: strict
- name: Restore dependencies cache
uses: actions/cache@v4
id: cache
with:
path: |
deps
_build
dialyzer
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-dialyzer-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-dialyzer-
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
env:
MIX_ENV: test
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
# Doesn't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
# Cache key based on Elixir & Erlang version.
- name: Restore PLT cache
uses: actions/cache@v2
id: plt_cache
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
restore-keys: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
path: |
priv/plts
# Create PLTs if no cache was found
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt
- name: Run dialyzer
run: mix dialyzer --format github
8 changes: 7 additions & 1 deletion lib/tesla/multipart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule Tesla.Multipart do
false -> headers
end

data = File.stream!(path, [], 2048)
data = stream_file!(path, 2048)
add_file_content(mp, data, filename, opts ++ [headers: headers])
end

Expand Down Expand Up @@ -194,4 +194,10 @@ defmodule Tesla.Multipart do
defp assert_part_value!(val) do
raise(ArgumentError, "#{inspect(val)} is not a supported multipart value.")
end

if Version.compare(System.version(), "1.16.0") in [:gt, :eq] do
defp stream_file!(path, bytes), do: File.stream!(path, bytes)
else
defp stream_file!(path, bytes), do: File.stream!(path, [], bytes)
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Tesla.Mixfile do
dialyzer: [
plt_core_path: "_build/#{Mix.env()}",
plt_add_apps: [:mix, :inets, :idna, :ssl_verify_fun, :ex_unit],
plt_add_deps: :project
plt_add_deps: :apps_direct
],
docs: docs(),
preferred_cli_env: [coveralls: :test, "coveralls.html": :test]
Expand Down

0 comments on commit 34a5108

Please sign in to comment.