summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre de Lacroix <pierre@pdelacroix.com>2020-12-26 13:59:27 +0000
committerPierre de Lacroix <pierre@pdelacroix.com>2020-12-26 13:59:27 +0000
commit006b2c12cf658ea71ea2e0c4ca105041c2834569 (patch)
treed3c24da6782f80c4043ba5f59241107f73850b1e
parentallow runtime configuration of homserver token (diff)
parentImprove CI (diff)
Merge branch '8-improve-ci' into 'master'
Improve CI Closes #8. - change image to `bitwalker/alpine-elixir:1.10.4` - 5 stages, 2 sequences in parallel: 1 cache for dev, 1 for test - 2 artifacts for reports - 1 artifact for dialyzer PLT (cache as artifact so that it still caches on fail) See merge request kazarma/matrix_app_service.ex!9
-rw-r--r--.dialyzer_ignore.exs1
-rw-r--r--.gitlab-ci.yml111
-rw-r--r--lib/matrix_app_service/application.ex6
-rw-r--r--lib/matrix_app_service/bridge.ex4
-rw-r--r--lib/matrix_app_service/bridge/room.ex4
-rw-r--r--lib/matrix_app_service/bridge/user.ex4
-rw-r--r--lib/matrix_app_service/migrations.ex6
-rw-r--r--lib/matrix_app_service_web/auth_plug.ex6
-rw-r--r--lib/matrix_app_service_web/set_config_plug.ex1
-rw-r--r--mix.exs12
-rw-r--r--mix.lock4
-rw-r--r--test/matrix_app_service/client.ex2
-rw-r--r--test/support/test_room_adapter.ex1
-rw-r--r--test/support/test_transaction_adapter.ex3
-rw-r--r--test/support/test_user_adapter.ex1
15 files changed, 141 insertions, 25 deletions
diff --git a/.dialyzer_ignore.exs b/.dialyzer_ignore.exs
new file mode 100644
index 0000000..fe51488
--- /dev/null
+++ b/.dialyzer_ignore.exs
@@ -0,0 +1 @@
+[]
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9d6c6d8..6233c52 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,16 +1,38 @@
stages:
- - static_analysis
- - deploy
+ - setup
+ - test
+ - format
+ - credo
+ - dialyzer
+ - docs
-image: elixir:latest
+image: bitwalker/alpine-elixir:1.10.4
-before_script:
- - mix local.rebar --force
- - mix local.hex --force
- - mix deps.get
+cache: &global_cache
+ key: cache-test
+ when: always
+ policy: pull
+ paths:
+ - _build
+ - deps
+
+variables:
+ MIX_ENV: test
+
+
+prepare_test:
+ stage: setup
+ script:
+ - mix deps.get
+ - mix compile
+ cache:
+ <<: *global_cache
+ policy: pull-push
test:
- stage: static_analysis
+ stage: test
+ needs:
+ - prepare_test
services:
- postgres:latest
variables:
@@ -19,10 +41,11 @@ test:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST: postgres
POSTGRES_HOST_AUTH_METHOD: trust
+ MIX_ENV: test
+ before_script:
+ - mix ecto.create
+ - mix ecto.migrate
script:
- - MIX_ENV=test mix compile
- - MIX_ENV=test mix ecto.create
- - MIX_ENV=test mix ecto.migrate
- mix test --cover
artifacts:
when: always
@@ -33,16 +56,70 @@ test:
cobertura: coverage.xml
format:
- stage: static_analysis
+ stage: format
+ needs:
+ - prepare_test
script:
- mix format --check-formatted
-pages:
- stage: deploy
+credo:
+ stage: credo
+ needs:
+ - prepare_test
script:
- - mix docs -o public
+ - mix credo suggest --only readability | tee credo.log
artifacts:
+ when: always
paths:
- - public
+ - "credo.log"
+
+## this should be uncommented when
+## https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27172
+## is fixed
+# dialyzer:
+# stage: dialyzer
+# needs:
+# - prepare_test
+# script:
+# - mix dialyzer
+# cache:
+# <<: *global_cache
+# policy: pull-push
+# paths:
+# - _build
+# - deps
+# - priv/plts
+
+
+# Doc generation
+
+prepare_dev:
+ stage: setup
only:
- - master
+ - master
+ variables:
+ MIX_ENV: test
+ script:
+ - mix deps.get
+ - mix compile
+ cache:
+ <<: *global_cache
+ policy: pull-push
+ key: cache-dev
+
+pages:
+ stage: docs
+ only:
+ - master
+ needs:
+ - prepare_dev
+ variables:
+ MIX_ENV: dev
+ script:
+ - mix docs -o public
+ cache:
+ <<: *global_cache
+ key: cache-dev
+ artifacts:
+ paths:
+ - public
diff --git a/lib/matrix_app_service/application.ex b/lib/matrix_app_service/application.ex
index 408d5ab..df9acab 100644
--- a/lib/matrix_app_service/application.ex
+++ b/lib/matrix_app_service/application.ex
@@ -49,15 +49,15 @@ defmodule MatrixAppService.Application do
:ok
end
- def start_endpoint?() do
+ def start_endpoint? do
Application.get_env(:matrix_app_service, :internal_supervisor, false)
end
- def start_repo?() do
+ def start_repo? do
Application.get_env(:matrix_app_service, :internal_repo, false)
end
- def endpoint_config() do
+ def endpoint_config do
[
transaction_adapter: Application.fetch_env!(:matrix_app_service, :transaction_adapter),
room_adapter: Application.fetch_env!(:matrix_app_service, :room_adapter),
diff --git a/lib/matrix_app_service/bridge.ex b/lib/matrix_app_service/bridge.ex
index e0e0fee..42f3450 100644
--- a/lib/matrix_app_service/bridge.ex
+++ b/lib/matrix_app_service/bridge.ex
@@ -1,3 +1,7 @@
defmodule MatrixAppService.Bridge do
+ @moduledoc """
+ This module is used when the library uses its own repo.
+ """
+
use MatrixAppService.BridgeConfig, repo: MatrixAppService.Repo
end
diff --git a/lib/matrix_app_service/bridge/room.ex b/lib/matrix_app_service/bridge/room.ex
index 73ef1ea..e8613a1 100644
--- a/lib/matrix_app_service/bridge/room.ex
+++ b/lib/matrix_app_service/bridge/room.ex
@@ -1,4 +1,8 @@
defmodule MatrixAppService.Bridge.Room do
+ @moduledoc """
+ Schema and helpers for keeping track of room correspondence.
+ """
+
use Ecto.Schema
import Ecto.Changeset
diff --git a/lib/matrix_app_service/bridge/user.ex b/lib/matrix_app_service/bridge/user.ex
index 7bf604a..93cafbf 100644
--- a/lib/matrix_app_service/bridge/user.ex
+++ b/lib/matrix_app_service/bridge/user.ex
@@ -1,4 +1,8 @@
defmodule MatrixAppService.Bridge.User do
+ @moduledoc """
+ Schema and helpers for keeping track of user correspondence.
+ """
+
use Ecto.Schema
import Ecto.Changeset
diff --git a/lib/matrix_app_service/migrations.ex b/lib/matrix_app_service/migrations.ex
index 6ae5344..8b3c9f1 100644
--- a/lib/matrix_app_service/migrations.ex
+++ b/lib/matrix_app_service/migrations.ex
@@ -1,4 +1,10 @@
defmodule MatrixAppService.Migrations do
+ @moduledoc """
+ Module containing migrations for tables used in bridge mode. Should be used like this:
+
+ TODO: example
+ """
+
use Ecto.Migration
def change do
diff --git a/lib/matrix_app_service_web/auth_plug.ex b/lib/matrix_app_service_web/auth_plug.ex
index be38fb0..ee431aa 100644
--- a/lib/matrix_app_service_web/auth_plug.ex
+++ b/lib/matrix_app_service_web/auth_plug.ex
@@ -17,11 +17,13 @@ defmodule MatrixAppServiceWeb.AuthPlug do
@doc false
@impl Plug
- def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token) when is_binary(homeserver_token) do
+ def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token)
+ when is_binary(homeserver_token) do
verify_access_token(conn, homeserver_token)
end
- def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token) when is_function(homeserver_token, 0) do
+ def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token)
+ when is_function(homeserver_token, 0) do
verify_access_token(conn, homeserver_token.())
end
diff --git a/lib/matrix_app_service_web/set_config_plug.ex b/lib/matrix_app_service_web/set_config_plug.ex
index 10296e2..a7fdf89 100644
--- a/lib/matrix_app_service_web/set_config_plug.ex
+++ b/lib/matrix_app_service_web/set_config_plug.ex
@@ -1,5 +1,6 @@
defmodule MatrixAppServiceWeb.SetConfigPlug do
@moduledoc """
+ This plug allows to set compile time configuration as private conn parameters.
"""
@behaviour Plug
diff --git a/mix.exs b/mix.exs
index e0cffe4..defc400 100644
--- a/mix.exs
+++ b/mix.exs
@@ -17,7 +17,13 @@ defmodule MatrixAppService.MixProject do
aliases: aliases(),
deps: deps(),
docs: [main: "MatrixAppService"],
- test_coverage: test_coverage(System.get_env("CI"))
+ test_coverage: test_coverage(System.get_env("CI")),
+
+ # elixirc_options: [warnings_as_errors: true],
+ dialyzer: [
+ plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
+ ignore_warnings: ".dialyzer_ignore.exs"
+ ]
]
end
@@ -65,7 +71,9 @@ defmodule MatrixAppService.MixProject do
{:ex_doc, "~> 0.22", only: :dev, runtime: false},
{:junit_formatter, "~> 3.1", only: :test},
{:cobertura_cover, "~> 0.9.0", only: :test},
- {:postgrex, ">= 0.0.0", only: :test}
+ {:postgrex, ">= 0.0.0", only: :test},
+ {:credo, "~> 1.4.1", only: [:dev, :test], runtime: false},
+ {:dialyxir, "~> 1.0.0", only: [:dev, :test], runtime: false}
]
end
diff --git a/mix.lock b/mix.lock
index 9782076..fd83871 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,15 +1,19 @@
%{
+ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"},
"cobertura_cover": {:hex, :cobertura_cover, "0.9.0", "01b9c5d2688d68240c1394c931383f8b29105b894ae499ef48aefd082a8a42b3", [:mix], [], "hexpm", "870bc4658cacc5c80d13f1206b688925234d2dc4e00278e8a3e72fbbd6bea0b1"},
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
+ "credo": {:hex, :credo, "1.4.1", "16392f1edd2cdb1de9fe4004f5ab0ae612c92e230433968eab00aafd976282fc", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "155f8a2989ad77504de5d8291fa0d41320fdcaa6a1030472e9967f285f8c7692"},
"db_connection": {:hex, :db_connection, "2.3.1", "4c9f3ed1ef37471cbdd2762d6655be11e38193904d9c5c1c9389f1b891a3088e", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "abaab61780dde30301d840417890bd9f74131041afd02174cf4e10635b3a63f5"},
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
+ "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
"ecto": {:hex, :ecto, "3.5.5", "48219a991bb86daba6e38a1e64f8cea540cded58950ff38fbc8163e062281a07", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98dd0e5e1de7f45beca6130d13116eae675db59adfa055fb79612406acf6f6f1"},
"ecto_sql": {:hex, :ecto_sql, "3.5.3", "1964df0305538364b97cc4661a2bd2b6c89d803e66e5655e4e55ff1571943efd", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d2f53592432ce17d3978feb8f43e8dc0705e288b0890caf06d449785f018061c"},
+ "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"},
"hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"},
"idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"},
diff --git a/test/matrix_app_service/client.ex b/test/matrix_app_service/client.ex
index 37d2225..546305a 100644
--- a/test/matrix_app_service/client.ex
+++ b/test/matrix_app_service/client.ex
@@ -1,4 +1,6 @@
defmodule MatrixAppService.ClientTest do
+ @moduledoc false
+
use ExUnit.Case
use Plug.Test
end
diff --git a/test/support/test_room_adapter.ex b/test/support/test_room_adapter.ex
index d57d420..6542838 100644
--- a/test/support/test_room_adapter.ex
+++ b/test/support/test_room_adapter.ex
@@ -1,4 +1,5 @@
defmodule MatrixAppService.TestRoomAdapter do
+ @moduledoc false
@behaviour MatrixAppService.Adapter.Room
@impl MatrixAppService.Adapter.Room
diff --git a/test/support/test_transaction_adapter.ex b/test/support/test_transaction_adapter.ex
index c39371b..26c552a 100644
--- a/test/support/test_transaction_adapter.ex
+++ b/test/support/test_transaction_adapter.ex
@@ -1,6 +1,7 @@
defmodule MatrixAppService.TestTransactionAdapter do
- require Logger
+ @moduledoc false
@behaviour MatrixAppService.Adapter.Transaction
+ require Logger
@impl MatrixAppService.Adapter.Transaction
def new_event(%MatrixAppService.Event{}) do
diff --git a/test/support/test_user_adapter.ex b/test/support/test_user_adapter.ex
index c402e0b..3738313 100644
--- a/test/support/test_user_adapter.ex
+++ b/test/support/test_user_adapter.ex
@@ -1,4 +1,5 @@
defmodule MatrixAppService.TestUserAdapter do
+ @moduledoc false
@behaviour MatrixAppService.Adapter.User
@impl MatrixAppService.Adapter.User