Skip to content
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
64 changes: 28 additions & 36 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,68 @@ jobs:
if: github.repository == 'hexlet-codebattle/codebattle'
runs-on: ubuntu-latest

# Use test environment by default
env:
MIX_ENV: test

services:
db:
image: postgres:12-alpine
ports: ['5432:5432']
image: postgres:16-alpine
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name=pg_ci
--mount type=tmpfs,destination=/var/lib/postgresql/data

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '26'
elixir-version: '1.16'
- name: Restore mix build cache
uses: actions/cache@v3
otp-version: "27.2"
elixir-version: "1.18.2"

- name: Restore Dependencies Cache
uses: actions/cache@v4
with:
path: |
deps
_build
~/.mix
key: mix:1-${{ hashFiles('**/mix.lock') }}
restore-keys: mix:1-
path: ./services/app/deps
key: ${{ runner.os }}-deps-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-deps-

- name: Restore Build Cache
uses: actions/cache@v4
with:
path: ./services/app/_build
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-build-

- name: Get deps
run: mix deps.get
working-directory: ./services/app

- name: Mix deps.compile
run: mix compile
run: mix compile --warnings-as-errors
working-directory: ./services/app
env:
MIX_ENV: test

- name: Mix format
run: mix format --check-formatted
working-directory: ./services/app
env:
MIX_ENV: test

- name: Mix credo
run: mix credo
working-directory: ./services/app
env:
MIX_ENV: test

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -81,24 +87,14 @@ jobs:

- name: Run jest
run: yarn test
working-directory: ./services/app/apps/codebattle

- name: Compile
run: mix compile
working-directory: ./services/app
env:
MIX_ENV: test
working-directory: ./services/app/apps/codebattle

- name: Setup db
run: mix ecto.create && mix ecto.migrate
working-directory: ./services/app
env:
MIX_ENV: test

- name: Mix tests
run: make test
env:
MIX_ENV: test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand All @@ -123,10 +119,6 @@ jobs:
# - name: Pull dockers
# run: mix dockers.pull
# working-directory: ./services/app
# env:
# MIX_ENV: test

# - name: Run code checkers tests
# run: make test-code-checkers
# env:
# MIX_ENV: test
51 changes: 28 additions & 23 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,68 @@ jobs:
build:
runs-on: ubuntu-latest

# Use test environment by default
env:
MIX_ENV: test

services:
db:
image: postgres:12-alpine
ports: ['5432:5432']
image: postgres:16-alpine
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name=pg_ci
--mount type=tmpfs,destination=/var/lib/postgresql/data

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '26'
elixir-version: '1.16'
otp-version: "27.2"
elixir-version: "1.18.2"

- name: Restore mix build cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ./services/app/deps
key: ${{ runner.os }}-deps-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-deps-

- name: Restore Build Cache
uses: actions/cache@v4
with:
path: |
deps
_build
~/.mix
key: mix:1-${{ hashFiles('**/mix.lock') }}
restore-keys: mix:1-
path: ./services/app/_build
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-build-

- name: Get deps
run: mix deps.get
working-directory: ./services/app

- name: Mix deps.compile
run: mix compile
run: mix compile --warnings-as-errors
working-directory: ./services/app
env:
MIX_ENV: test

- name: Mix format
run: mix format --check-formatted
working-directory: ./services/app
env:
MIX_ENV: test

- name: Mix credo
run: mix credo
working-directory: ./services/app
env:
MIX_ENV: test

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -85,10 +91,9 @@ jobs:
- name: Setup db
run: mix ecto.create && mix ecto.migrate
working-directory: ./services/app
env:
MIX_ENV: test

- run: make test
- name: Mix tests
run: make test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
32 changes: 32 additions & 0 deletions services/app/apps/codebattle/lib/codebattle/customization.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
defmodule Codebattle.Customization do
use Ecto.Schema
import Ecto.Changeset

alias Codebattle.Repo

schema "customizations" do
field(:key, :string)
field(:value, :string)
end

@doc false
def changeset(customization, attrs) do
customization
|> cast(attrs, [:key, :value])
|> validate_required([:key, :value])
end

def upsert(key, value) do
Repo.insert(%__MODULE__{key: key, value: value},
on_conflict: [set: [value: value]],
conflict_target: [:key]
)
end

def get(key) do
case Repo.get_by(__MODULE__, key: key) do
nil -> nil
customization -> customization.value
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,19 @@ defmodule Codebattle.Tournament.Ranking do

@spec set_ranking_to_ets(Tournament.t()) :: Tournament.t()
def set_ranking_to_ets(tournament) do
get_module(tournament).set_ranking_to_ets(tournament)
# get_module(tournament).set_ranking_to_ets(tournament)
tournament
end

@spec preload_event_ranking(Tournament.t()) :: Tournament.t()
def preload_event_ranking(tournament = %{use_event_ranking: true, event_id: event_id})
when not is_nil(event_id) do
ranking = get_module(tournament).get_event_ranking(tournament)
# ranking = get_module(tournament).get_event_ranking(tournament)

Ranking.put_ranking(tournament, ranking)
# Ranking.put_ranking(tournament, ranking)

event_ranking = Map.new(ranking, fn item = %{id: id} -> {id, item} end)
Map.put(tournament, :event_ranking, event_ranking)
# event_ranking = Map.new(ranking, fn item = %{id: id} -> {id, item} end)
Map.put(tournament, :event_ranking, %{})
end

def preload_event_ranking(t), do: t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,19 @@ defmodule Codebattle.Tournament.Swiss do
end
end

defp build_player_pairs(tournament) do
played_pair_ids = MapSet.new(tournament.played_pair_ids)
# defp build_player_pairs(_tournament) do
# played_pair_ids = MapSet.new(tournament.played_pair_ids)

sorted_players =
tournament
|> get_players()
|> Enum.sort_by(& &1.score, :desc)
# sorted_players =
# tournament
# |> get_players()
# |> Enum.sort_by(& &1.score, :desc)

{player_pairs, played_pair_ids} = build_new_pairs(sorted_players, [], played_pair_ids)
# {player_pairs, played_pair_ids} = build_new_pairs(sorted_players, [], played_pair_ids)

{Enum.reverse(player_pairs), played_pair_ids}
end
# {Enum.reverse(player_pairs), played_pair_ids}
# {[], MapSet.new()}
# end

def build_new_pairs([], player_pairs, played_pair_ids) do
{player_pairs, played_pair_ids}
Expand Down
2 changes: 1 addition & 1 deletion services/app/apps/codebattle/lib/codebattle/user/scope.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Codebattle.User.Scope do
end

defp filter_by_date(query, %{"date_from" => date_from}) when date_from !== "" do
starts_at = Timex.parse!(date_from, "{YYYY}-{0M}-{D}")
starts_at = Date.from_iso8601!(date_from) |> NaiveDateTime.new!(~T[00:00:00])

query
|> where([ug: ug], ug.inserted_at >= type(^starts_at, :naive_datetime))
Expand Down
9 changes: 5 additions & 4 deletions services/app/apps/codebattle/lib/codebattle_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ defmodule CodebattleWeb do
quote do
use Phoenix.Controller, namespace: CodebattleWeb
use PhoenixMetaTags.TagController
use Gettext, backend: CodebattleWeb.Gettext

alias Codebattle.Repo
alias CodebattleWeb.Router.Helpers, as: Routes

import Ecto
import Ecto.Query
import CodebattleWeb.Gettext
import Phoenix.LiveView.Controller, only: [live_render: 3]

defp translate_errors(changeset) do
Expand All @@ -61,9 +61,9 @@ defmodule CodebattleWeb do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Phoenix.HTML.Form
use Gettext, backend: CodebattleWeb.Gettext

import CodebattleWeb.ErrorHelpers
import CodebattleWeb.Gettext
import CodebattleWeb.FormHelpers

unquote(view_helpers())
Expand All @@ -85,8 +85,9 @@ defmodule CodebattleWeb do
use Phoenix.HTML
import Phoenix.HTML.{Form, Tag, Link, Format}

use Gettext, backend: CodebattleWeb.Gettext

import CodebattleWeb.ErrorHelpers
import CodebattleWeb.Gettext

unquote(view_helpers())
end
Expand Down Expand Up @@ -131,7 +132,7 @@ defmodule CodebattleWeb do
def channel do
quote do
use Phoenix.Channel
import CodebattleWeb.Gettext
use Gettext, backend: CodebattleWeb.Gettext
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule CodebattleWeb.AuthBindController do
use CodebattleWeb, :controller
import CodebattleWeb.Gettext
use Gettext, backend: CodebattleWeb.Gettext

require Logger

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule CodebattleWeb.AuthController do
use CodebattleWeb, :controller

import CodebattleWeb.Gettext
use Gettext, backend: CodebattleWeb.Gettext

require Logger

Expand Down
Loading
Loading