Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mix format and dialyzer to CI #304

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,155 changes: 588 additions & 567 deletions .dialyzer_ignore.exs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# see docs/local_setup.md for usage
9bb669ea86949ceba75d95d05578f67e8ace5351
98 changes: 98 additions & 0 deletions .github/workflows/dialyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Lint and style checks

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

# Sets the ENV `MIX_ENV` to `test` for running tests
env:
MIX_ENV: test
ELIXIR_VER: '1.14.3'
OTP_VER: '25.2.3'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
name: Dialyzer

steps:
# Step: Setup Elixir + Erlang image as the base.
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VER }}
elixir-version: ${{ env.ELIXIR_VER }}

# Step: Check out the code.
- name: Checkout code
uses: actions/checkout@v4

# Step: Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-

# Step: Define how to cache the `_build` directory. After the first run,
# this speeds up tests runs a lot. This includes not re-compiling our
# project's downloaded deps every run.
- name: Cache compiled build
id: cache-build
uses: actions/cache@v4
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-

# Step: Download project dependencies. If unchanged, uses
# the cached version.
- name: Install dependencies
run: mix deps.get

- name: Restore PLT cache
uses: actions/cache/restore@v3
id: plt_cache
with:
key: |
${{ runner.os }}-${{ env.ELIXIR_VER }}-${{ env.OTP_VER }}-plt
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VER }}-${{ env.OTP_VER }}-plt
path: |
priv/plts

- name: Create PLTs
run: mix dialyzer --plt

- name: Save PLT cache
uses: actions/cache/save@v3
if: steps.plt_cache.outputs.cache-hit != 'true'
id: plt_cache_save
with:
key: |
${{ runner.os }}-${{ env.ELIXIR_VER }}-${{ env.OTP_VER }}-plt
path: |
priv/plts

- name: Run dialyzer
run: mix dialyzer --format github
79 changes: 79 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Lint and style checks

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

# Sets the ENV `MIX_ENV` to `test` for running tests
env:
MIX_ENV: test
ELIXIR_VER: '1.14.3'
OTP_VER: '25.2.3'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
name: mix format

steps:
# Step: Setup Elixir + Erlang image as the base.
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VER }}
elixir-version: ${{ env.ELIXIR_VER }}

# Step: Check out the code.
- name: Checkout code
uses: actions/checkout@v4

# Step: Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: cache-deps
uses: actions/cache@v4
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-

# Step: Define how to cache the `_build` directory. After the first run,
# this speeds up tests runs a lot. This includes not re-compiling our
# project's downloaded deps every run.
- name: Cache compiled build
id: cache-build
uses: actions/cache@v4
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-

# Step: Download project dependencies. If unchanged, uses
# the cached version.
- name: Install dependencies
run: mix deps.get

# Step: Compile the current project. If unchanged, uses
# the cached version.
- name: Install dependencies
run: mix compile

- name: mix format
run: mix format --check-formatted
4 changes: 2 additions & 2 deletions .github/workflows/elixir.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ on:
# Sets the ENV `MIX_ENV` to `test` for running tests
env:
MIX_ENV: test
ELIXIR_VER: '1.16.2'
OTP_VER: '25.0.4'
ELIXIR_VER: '1.14.3'
OTP_VER: '25.2.3'

permissions:
contents: read
Expand Down
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: no-commit-to-branch
args:
- -b
- master
- -b
- production
- -b
- staging
- repo: local
hooks:
- id: mix-format
name: "elixir: mix format"
entry: mix format --check-formatted
language: system
files: \.exs*$
- id: mix-compile
name: "elixir: mix compile"
entry: mix compile --force #--warnings-as-errors
language: system
pass_filenames: false
files: \.ex$
# - id: mix-credo
# name: "elixir: mix credo"
# entry: mix credo
# language: system
# pass_filenames: false
# files: \.exs*$
- id: mix-dialyzer
name: "elixir: mix dialyzer"
entry: mix dialyzer
language: system
pass_filenames: false
files: \.exs*$

3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ if config_env() == :prod do
config :teiserver, Teiserver.Setup,
key: Teiserver.ConfigHelpers.get_env("TEI_SETUP_ROOT_KEY", nil)

enable_discord_bridge = Teiserver.ConfigHelpers.get_env("TEI_ENABLE_DISCORD_BRIDGE", true, :bool)
enable_discord_bridge =
Teiserver.ConfigHelpers.get_env("TEI_ENABLE_DISCORD_BRIDGE", true, :bool)

config :teiserver, Teiserver,
game_name: "Beyond All Reason",
Expand Down
14 changes: 13 additions & 1 deletion documents/guides/local_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,17 @@ The main dependencies of the project are:
- [Ranch](https://github.com/ninenines/ranch), a tcp server
- [Oban](https://github.com/sorentwo/oban), a backend job processing framework.

### Ignore large `mix format` passes in `git blame`
In ![PR #304](https://github.com/beyond-all-reason/teiserver/pull/304) we've started requiring compliance with `mix format` - this meant we had to use that on the entire codebase.

This obviously breaks `git blame`, but you can sidestep that by using
```bash
git config blame.ignoreRevsFile .git-blame-ignore-revs
```

The attached `.git-blame-ignore-revs` file contains a list of commit hashes which modify a large number of lines with trivial changes.

See [this blog post by Stefan Judis](https://www.stefanjudis.com/today-i-learned/how-to-exclude-commits-from-git-blame/) for reference.

### Next Steps
If you want to develop features that interact with the lobby, then you will need to [set up SPADS](/documents/guides/spads_install.md).
If you want to develop features that interact with the lobby, then you will need to [set up SPADS](/documents/guides/spads_install.md).
3 changes: 2 additions & 1 deletion lib/teiserver/account/libs/role_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ defmodule Teiserver.Account.RoleLib do
end

def allowed_role_management("Admin") do
staff_roles() ++ community_roles() ++ privileged_roles() ++ allowed_role_management("Moderator")
staff_roles() ++
community_roles() ++ privileged_roles() ++ allowed_role_management("Moderator")
end

def allowed_role_management("Moderator") do
Expand Down
6 changes: 4 additions & 2 deletions lib/teiserver/account/libs/user_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,12 @@ defmodule Teiserver.Account.UserLib do
defp can_login(user) do
cond do
Teiserver.CacheUser.is_restricted?(user.id, ["Login"]) ->
{:error, "Your account is currently suspended. Check the suspension's status at https://discord.gg/beyond-all-reason -> #moderation-bot"}
{:error,
"Your account is currently suspended. Check the suspension's status at https://discord.gg/beyond-all-reason -> #moderation-bot"}

user.smurf_of_id != nil ->
{:error, "Alt account detected. Please log in using your original account instead. If you're not sure what that account is or have trouble accessing it, please contact the moderation team at https://discord.gg/beyond-all-reason -> #open-ticket"}
{:error,
"Alt account detected. Please log in using your original account instead. If you're not sure what that account is or have trouble accessing it, please contact the moderation team at https://discord.gg/beyond-all-reason -> #open-ticket"}

true ->
:ok
Expand Down
10 changes: 5 additions & 5 deletions lib/teiserver/battle/balance/balance_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ defmodule Teiserver.Battle.Balance.BalanceTypes do
}

@type group() :: %{
members: [T.userid()],
ratings: [rating_value()],
group_rating: rating_value(),
count: non_neg_integer()
}
members: [T.userid()],
ratings: [rating_value()],
group_rating: rating_value(),
count: non_neg_integer()
}
@type expanded_group_or_pair() :: expanded_group() | {expanded_group(), expanded_group()}

@type algorithm_result :: map()
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/battle/balance/cheeky_switcher_smart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Teiserver.Battle.Balance.CheekySwitcherSmart do

@spec perform([BT.expanded_group_or_pair()], non_neg_integer(), list()) :: BT.algorithm_result()
def perform(raw_groups, team_count, opts) do
groups_with_names = Enum.map(raw_groups, fn x-> Map.drop(x,[:ranks]) end)
groups_with_names = Enum.map(raw_groups, fn x -> Map.drop(x, [:ranks]) end)

{teams, logs} = do_cheeky_switcher(groups_with_names, team_count, opts, [])

Expand Down
6 changes: 3 additions & 3 deletions lib/teiserver/battle/balance/split_one_chevs_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Teiserver.Battle.Balance.SplitOneChevsTypes do
member_id: any()
}
@type team :: %{
members: [member],
team_id: integer()
}
members: [member],
team_id: integer()
}
end
6 changes: 3 additions & 3 deletions lib/teiserver/battle/libs/balance_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ defmodule Teiserver.Battle.BalanceLib do

# Only take keys we need
defp clean_groups(groups) do
groups |> Enum.map(fn x->
groups
|> Enum.map(fn x ->
Map.take(x, ~w(members count group_rating ratings)a)
end)
end
Expand All @@ -179,7 +180,7 @@ defmodule Teiserver.Battle.BalanceLib do
true ->
balance_result.teams
|> Map.new(fn {team_id, groups} ->
{team_id, Enum.reverse(clean_groups((groups)))}
{team_id, Enum.reverse(clean_groups(groups))}
end)
end

Expand Down Expand Up @@ -541,7 +542,6 @@ defmodule Teiserver.Battle.BalanceLib do
get_user_rating_value(userid, rating_type_id)
end


# Used to get the rating value of the user for internal balance purposes which might be
# different from public/reporting
@spec get_user_balance_rating_value(T.userid(), String.t() | non_neg_integer()) ::
Expand Down
Loading
Loading