Skip to content

Commit 09cac80

Browse files
authored
Merge pull request #2090 from hexlet-codebattle/minor-improvement
Improve CI with minor fixes
2 parents 75c217d + 8bec282 commit 09cac80

File tree

25 files changed

+194
-129
lines changed

25 files changed

+194
-129
lines changed

.github/workflows/master.yml

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,68 @@ jobs:
99
if: github.repository == 'hexlet-codebattle/codebattle'
1010
runs-on: ubuntu-latest
1111

12+
# Use test environment by default
13+
env:
14+
MIX_ENV: test
15+
1216
services:
1317
db:
14-
image: postgres:12-alpine
15-
ports: ['5432:5432']
18+
image: postgres:16-alpine
19+
ports: ["5432:5432"]
1620
env:
1721
POSTGRES_PASSWORD: postgres
1822
options: >-
1923
--health-cmd pg_isready
2024
--health-interval 10s
2125
--health-timeout 5s
2226
--health-retries 5
27+
--name=pg_ci
28+
--mount type=tmpfs,destination=/var/lib/postgresql/data
2329
2430
steps:
25-
- uses: actions/checkout@v3
31+
- uses: actions/checkout@v4
32+
2633
- name: Setup Elixir
2734
uses: erlef/setup-beam@v1
2835
with:
29-
otp-version: '26'
30-
elixir-version: '1.16'
31-
- name: Restore mix build cache
32-
uses: actions/cache@v3
36+
otp-version: "27.2"
37+
elixir-version: "1.18.2"
38+
39+
- name: Restore Dependencies Cache
40+
uses: actions/cache@v4
3341
with:
34-
path: |
35-
deps
36-
_build
37-
~/.mix
38-
key: mix:1-${{ hashFiles('**/mix.lock') }}
39-
restore-keys: mix:1-
42+
path: ./services/app/deps
43+
key: ${{ runner.os }}-deps-${{ hashFiles('**/mix.lock') }}
44+
restore-keys: ${{ runner.os }}-deps-
45+
46+
- name: Restore Build Cache
47+
uses: actions/cache@v4
48+
with:
49+
path: ./services/app/_build
50+
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
51+
restore-keys: ${{ runner.os }}-build-
4052

4153
- name: Get deps
4254
run: mix deps.get
4355
working-directory: ./services/app
4456

4557
- name: Mix deps.compile
46-
run: mix compile
58+
run: mix compile --warnings-as-errors
4759
working-directory: ./services/app
48-
env:
49-
MIX_ENV: test
5060

5161
- name: Mix format
5262
run: mix format --check-formatted
5363
working-directory: ./services/app
54-
env:
55-
MIX_ENV: test
5664

5765
- name: Mix credo
5866
run: mix credo
5967
working-directory: ./services/app
60-
env:
61-
MIX_ENV: test
6268

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

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

8288
- name: Run jest
8389
run: yarn test
84-
working-directory: ./services/app/apps/codebattle
85-
86-
- name: Compile
87-
run: mix compile
88-
working-directory: ./services/app
89-
env:
90-
MIX_ENV: test
90+
working-directory: ./services/app/apps/codebattle
9191

9292
- name: Setup db
9393
run: mix ecto.create && mix ecto.migrate
9494
working-directory: ./services/app
95-
env:
96-
MIX_ENV: test
9795

9896
- name: Mix tests
9997
run: make test
100-
env:
101-
MIX_ENV: test
10298

10399
- name: Upload coverage to Codecov
104100
uses: codecov/codecov-action@v1
@@ -123,10 +119,6 @@ jobs:
123119
# - name: Pull dockers
124120
# run: mix dockers.pull
125121
# working-directory: ./services/app
126-
# env:
127-
# MIX_ENV: test
128122

129123
# - name: Run code checkers tests
130124
# run: make test-code-checkers
131-
# env:
132-
# MIX_ENV: test

.github/workflows/pr.yml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,68 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010

11+
# Use test environment by default
12+
env:
13+
MIX_ENV: test
14+
1115
services:
1216
db:
13-
image: postgres:12-alpine
14-
ports: ['5432:5432']
17+
image: postgres:16-alpine
18+
ports: ["5432:5432"]
1519
env:
1620
POSTGRES_PASSWORD: postgres
1721
options: >-
1822
--health-cmd pg_isready
1923
--health-interval 10s
2024
--health-timeout 5s
2125
--health-retries 5
26+
--name=pg_ci
27+
--mount type=tmpfs,destination=/var/lib/postgresql/data
2228
2329
steps:
24-
- uses: actions/checkout@v3
30+
- uses: actions/checkout@v4
31+
2532
- name: Setup Elixir
2633
uses: erlef/setup-beam@v1
2734
with:
28-
otp-version: '26'
29-
elixir-version: '1.16'
35+
otp-version: "27.2"
36+
elixir-version: "1.18.2"
37+
3038
- name: Restore mix build cache
31-
uses: actions/cache@v3
39+
uses: actions/cache@v4
40+
with:
41+
path: ./services/app/deps
42+
key: ${{ runner.os }}-deps-${{ hashFiles('**/mix.lock') }}
43+
restore-keys: ${{ runner.os }}-deps-
44+
45+
- name: Restore Build Cache
46+
uses: actions/cache@v4
3247
with:
33-
path: |
34-
deps
35-
_build
36-
~/.mix
37-
key: mix:1-${{ hashFiles('**/mix.lock') }}
38-
restore-keys: mix:1-
48+
path: ./services/app/_build
49+
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
50+
restore-keys: ${{ runner.os }}-build-
3951

4052
- name: Get deps
4153
run: mix deps.get
4254
working-directory: ./services/app
4355

4456
- name: Mix deps.compile
45-
run: mix compile
57+
run: mix compile --warnings-as-errors
4658
working-directory: ./services/app
47-
env:
48-
MIX_ENV: test
4959

5060
- name: Mix format
5161
run: mix format --check-formatted
5262
working-directory: ./services/app
53-
env:
54-
MIX_ENV: test
5563

5664
- name: Mix credo
5765
run: mix credo
5866
working-directory: ./services/app
59-
env:
60-
MIX_ENV: test
6167

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

66-
- uses: actions/cache@v3
72+
- uses: actions/cache@v4
6773
with:
6874
path: ${{ steps.yarn-cache.outputs.dir }}
6975
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
@@ -85,10 +91,9 @@ jobs:
8591
- name: Setup db
8692
run: mix ecto.create && mix ecto.migrate
8793
working-directory: ./services/app
88-
env:
89-
MIX_ENV: test
9094

91-
- run: make test
95+
- name: Mix tests
96+
run: make test
9297

9398
- name: Upload coverage to Codecov
9499
uses: codecov/codecov-action@v1
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
defmodule Codebattle.Customization do
2+
use Ecto.Schema
3+
import Ecto.Changeset
4+
5+
alias Codebattle.Repo
6+
7+
schema "customizations" do
8+
field(:key, :string)
9+
field(:value, :string)
10+
end
11+
12+
@doc false
13+
def changeset(customization, attrs) do
14+
customization
15+
|> cast(attrs, [:key, :value])
16+
|> validate_required([:key, :value])
17+
end
18+
19+
def upsert(key, value) do
20+
Repo.insert(%__MODULE__{key: key, value: value},
21+
on_conflict: [set: [value: value]],
22+
conflict_target: [:key]
23+
)
24+
end
25+
26+
def get(key) do
27+
case Repo.get_by(__MODULE__, key: key) do
28+
nil -> nil
29+
customization -> customization.value
30+
end
31+
end
32+
end

services/app/apps/codebattle/lib/codebattle/tournament/ranking.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,19 @@ defmodule Codebattle.Tournament.Ranking do
6767

6868
@spec set_ranking_to_ets(Tournament.t()) :: Tournament.t()
6969
def set_ranking_to_ets(tournament) do
70-
get_module(tournament).set_ranking_to_ets(tournament)
70+
# get_module(tournament).set_ranking_to_ets(tournament)
71+
tournament
7172
end
7273

7374
@spec preload_event_ranking(Tournament.t()) :: Tournament.t()
7475
def preload_event_ranking(tournament = %{use_event_ranking: true, event_id: event_id})
7576
when not is_nil(event_id) do
76-
ranking = get_module(tournament).get_event_ranking(tournament)
77+
# ranking = get_module(tournament).get_event_ranking(tournament)
7778

78-
Ranking.put_ranking(tournament, ranking)
79+
# Ranking.put_ranking(tournament, ranking)
7980

80-
event_ranking = Map.new(ranking, fn item = %{id: id} -> {id, item} end)
81-
Map.put(tournament, :event_ranking, event_ranking)
81+
# event_ranking = Map.new(ranking, fn item = %{id: id} -> {id, item} end)
82+
Map.put(tournament, :event_ranking, %{})
8283
end
8384

8485
def preload_event_ranking(t), do: t

services/app/apps/codebattle/lib/codebattle/tournament/strategy/swiss.ex

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,19 @@ defmodule Codebattle.Tournament.Swiss do
113113
end
114114
end
115115

116-
defp build_player_pairs(tournament) do
117-
played_pair_ids = MapSet.new(tournament.played_pair_ids)
116+
# defp build_player_pairs(_tournament) do
117+
# played_pair_ids = MapSet.new(tournament.played_pair_ids)
118118

119-
sorted_players =
120-
tournament
121-
|> get_players()
122-
|> Enum.sort_by(& &1.score, :desc)
119+
# sorted_players =
120+
# tournament
121+
# |> get_players()
122+
# |> Enum.sort_by(& &1.score, :desc)
123123

124-
{player_pairs, played_pair_ids} = build_new_pairs(sorted_players, [], played_pair_ids)
124+
# {player_pairs, played_pair_ids} = build_new_pairs(sorted_players, [], played_pair_ids)
125125

126-
{Enum.reverse(player_pairs), played_pair_ids}
127-
end
126+
# {Enum.reverse(player_pairs), played_pair_ids}
127+
# {[], MapSet.new()}
128+
# end
128129

129130
def build_new_pairs([], player_pairs, played_pair_ids) do
130131
{player_pairs, played_pair_ids}

services/app/apps/codebattle/lib/codebattle/user/scope.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ defmodule Codebattle.User.Scope do
3737
end
3838

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

4242
query
4343
|> where([ug: ug], ug.inserted_at >= type(^starts_at, :naive_datetime))

services/app/apps/codebattle/lib/codebattle_web.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ defmodule CodebattleWeb do
3030
quote do
3131
use Phoenix.Controller, namespace: CodebattleWeb
3232
use PhoenixMetaTags.TagController
33+
use Gettext, backend: CodebattleWeb.Gettext
3334

3435
alias Codebattle.Repo
3536
alias CodebattleWeb.Router.Helpers, as: Routes
3637

3738
import Ecto
3839
import Ecto.Query
39-
import CodebattleWeb.Gettext
4040
import Phoenix.LiveView.Controller, only: [live_render: 3]
4141

4242
defp translate_errors(changeset) do
@@ -61,9 +61,9 @@ defmodule CodebattleWeb do
6161
# Use all HTML functionality (forms, tags, etc)
6262
use Phoenix.HTML
6363
import Phoenix.HTML.Form
64+
use Gettext, backend: CodebattleWeb.Gettext
6465

6566
import CodebattleWeb.ErrorHelpers
66-
import CodebattleWeb.Gettext
6767
import CodebattleWeb.FormHelpers
6868

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

88+
use Gettext, backend: CodebattleWeb.Gettext
89+
8890
import CodebattleWeb.ErrorHelpers
89-
import CodebattleWeb.Gettext
9091

9192
unquote(view_helpers())
9293
end
@@ -131,7 +132,7 @@ defmodule CodebattleWeb do
131132
def channel do
132133
quote do
133134
use Phoenix.Channel
134-
import CodebattleWeb.Gettext
135+
use Gettext, backend: CodebattleWeb.Gettext
135136
end
136137
end
137138

services/app/apps/codebattle/lib/codebattle_web/controllers/auth_bind_controller.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule CodebattleWeb.AuthBindController do
22
use CodebattleWeb, :controller
3-
import CodebattleWeb.Gettext
3+
use Gettext, backend: CodebattleWeb.Gettext
44

55
require Logger
66

services/app/apps/codebattle/lib/codebattle_web/controllers/auth_controller.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule CodebattleWeb.AuthController do
22
use CodebattleWeb, :controller
3-
4-
import CodebattleWeb.Gettext
3+
use Gettext, backend: CodebattleWeb.Gettext
54

65
require Logger
76

0 commit comments

Comments
 (0)