From 5d1243a6c3268d0cb402c6272ae6e0df1615779a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=9Aled=C5=BA?= Date: Fri, 22 Mar 2024 17:34:53 +0100 Subject: [PATCH] Fix Message.authenticate/2 typespec. Update CI (#13) --- .github/workflows/ci.yml | 107 ++++++++++++++++++++++++++++----------- .gitignore | 3 ++ lib/ex_stun/message.ex | 6 +-- mix.exs | 6 +++ 4 files changed, 88 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6be2c24..df280f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file + - 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 }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index d7596a5..955b860 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ ex_stun-*.tar # Temporary files, for example, from tests. /tmp/ + +# Localy stored dialyzer artifacts +/_dialyzer/ \ No newline at end of file diff --git a/lib/ex_stun/message.ex b/lib/ex_stun/message.ex index ab57cf6..450c5e6 100644 --- a/lib/ex_stun/message.ex +++ b/lib/ex_stun/message.ex @@ -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} -> @@ -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} -> diff --git a/mix.exs b/mix.exs index 6a428c0..e3c30c3 100644 --- a/mix.exs +++ b/mix.exs @@ -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: [