Skip to content

Commit

Permalink
Fix Message.authenticate/2 typespec. Update CI (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 authored Mar 22, 2024
1 parent 4df3729 commit 5d1243a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 34 deletions.
107 changes: 77 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,87 @@
name: CI

on: push

jobs:
lint:
runs-on: ubuntu-latest
name: lint OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: ['26']
elixir: ['1.16']
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- run: mix deps.get
- run: mix credo
- run: mix dialyzer
- run: mix format --check-formatted
- run: mix docs 2>&1 | (! grep -q "warning:")
env:
MIX_ENV: test

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
name: test OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
name: CI on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: ['26']
elixir: ['1.16']
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- run: mix deps.get
- run: mix coveralls.json
- uses: codecov/codecov-action@v3
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Checkout the code
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-deps-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-deps-
- name: Cache compiled build
uses: actions/cache@v4
with:
path: _build
key: ${{ runner.os }}-mix-build-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-build-
${{ runner.os }}-mix-
- name: Cache dialyzer artifacts
uses: actions/cache@v4
with:
path: _dialyzer
key: ${{ runner.os }}-dialyzer-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-dialyzer-
- name: Install dependencies
run: mix deps.get

- name: Compile without warnings
id: compile
run: mix compile --warnings-as-errors

- name: Check formatting
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
run: mix format --check-formatted

- name: Check with credo
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
run: mix credo

- name: Check with dialyzer
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
run: mix dialyzer

- name: Check docs
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
run: mix docs 2>&1 | (! grep -q "warning:")

- name: Run tests and check test coverage
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
id: test
run: mix coveralls.json

- name: Upload test coverage results to Codecov
if: ${{ !cancelled() && steps.test.outcome == 'success' }}
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true,
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ ex_stun-*.tar

# Temporary files, for example, from tests.
/tmp/

# Localy stored dialyzer artifacts
/_dialyzer/
6 changes: 2 additions & 4 deletions lib/ex_stun/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ defmodule ExSTUN.Message do
Depending on the authentication method and its context (client/server side),
user has to perform those checks on their own.
"""
@spec authenticate(t(), binary()) ::
:ok | {:error, :no_message_integrity, :no_matching_message_integrity | atom()}
@spec authenticate(t(), binary()) :: :ok | {:error, atom()}
def authenticate(msg, key) do
case get_message_integrity(msg) do
{:ok, %MessageIntegrity{} = msg_int} ->
Expand All @@ -264,8 +263,7 @@ defmodule ExSTUN.Message do
end
end

@spec check_fingerprint(t()) ::
:ok | {:error, :no_fingerprint | :no_matching_fingerprint | atom()}
@spec check_fingerprint(t()) :: :ok | {:error, atom()}
def check_fingerprint(%__MODULE__{} = msg) do
case get_attribute(msg, Fingerprint) do
{:ok, %Fingerprint{} = fingerprint} ->
Expand Down
6 changes: 6 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ defmodule ExSTUN.MixProject do
docs: docs(),
source_url: @source_url,

# dialyzer
dialyzer: [
plt_local_path: "_dialyzer",
plt_core_path: "_dialyzer"
],

# code coverage
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
Expand Down

0 comments on commit 5d1243a

Please sign in to comment.