Skip to content

Commit 1042be2

Browse files
authored
Merge pull request #2093 from hexlet-codebattle/improve-ci
Improve CI
2 parents 09cac80 + ca90a67 commit 1042be2

File tree

267 files changed

+1868
-2104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+1868
-2104
lines changed

.github/workflows/master.yml

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ on:
44
push:
55
branches:
66
- master
7+
workflow_dispatch:
8+
79
jobs:
810
build:
911
if: github.repository == 'hexlet-codebattle/codebattle'
1012
runs-on: ubuntu-latest
13+
timeout-minutes: 30 # Add timeout to prevent hanging builds
1114

12-
# Use test environment by default
1315
env:
1416
MIX_ENV: test
17+
DOCKER_BUILDKIT: 1 # Enable buildkit for faster docker builds
1518

1619
services:
1720
db:
1821
image: postgres:16-alpine
1922
ports: ["5432:5432"]
2023
env:
2124
POSTGRES_PASSWORD: postgres
25+
POSTGRES_HOST_AUTH_METHOD: trust # Simplify auth for CI
2226
options: >-
2327
--health-cmd pg_isready
2428
--health-interval 10s
@@ -29,29 +33,31 @@ jobs:
2933
3034
steps:
3135
- uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0 # Fetch complete history for better caching
3238

3339
- name: Setup Elixir
3440
uses: erlef/setup-beam@v1
3541
with:
3642
otp-version: "27.2"
3743
elixir-version: "1.18.2"
3844

39-
- name: Restore Dependencies Cache
40-
uses: actions/cache@v4
41-
with:
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
45+
- name: Cache Dependencies
4746
uses: actions/cache@v4
47+
id: deps-cache
4848
with:
49-
path: ./services/app/_build
50-
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
51-
restore-keys: ${{ runner.os }}-build-
49+
path: |
50+
./services/app/deps
51+
./services/app/_build
52+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
53+
restore-keys: |
54+
${{ runner.os }}-mix-
5255
5356
- name: Get deps
54-
run: mix deps.get
57+
run: |
58+
mix local.hex --force
59+
mix local.rebar --force
60+
mix deps.get
5561
working-directory: ./services/app
5662

5763
- name: Mix deps.compile
@@ -68,7 +74,7 @@ jobs:
6874

6975
- name: Get yarn cache
7076
id: yarn-cache
71-
run: echo "::set-output name=dir::$(yarn cache dir)"
77+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
7278

7379
- uses: actions/cache@v4
7480
with:
@@ -78,7 +84,7 @@ jobs:
7884
${{ runner.os }}-yarn-
7985
8086
- name: Install yarn dependencies
81-
run: yarn install --froze-lockfile
87+
run: yarn install --frozen-lockfile --network-timeout 300000
8288
working-directory: ./services/app/apps/codebattle
8389

8490
- name: Eslint
@@ -97,23 +103,30 @@ jobs:
97103
run: make test
98104

99105
- name: Upload coverage to Codecov
100-
uses: codecov/codecov-action@v1
106+
uses: codecov/codecov-action@v3
101107
with:
102108
token: ${{ secrets.CODECOV_TOKEN }}
103109
file: ./services/app/assp/codebattle/cover/excoveralls.json
104110
fail_ci_if_error: false
105111

106112
- name: Login to Docker Hub
107-
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
108-
109-
- name: Build docker image for codebattle
110-
run: make GIT_HASH=${{ github.sha }} docker-build-codebattle
111-
- name: Push docker image for codebattle
112-
run: make docker-push-codebattle
113-
- name: Build docker image for runner
114-
run: make docker-build-runner
115-
- name: Push docker image for runner
116-
run: make docker-push-runner
113+
uses: docker/login-action@v3
114+
with:
115+
username: ${{ secrets.DOCKER_USERNAME }}
116+
password: ${{ secrets.DOCKER_PASSWORD }}
117+
118+
- name: Set up Docker Buildx
119+
uses: docker/setup-buildx-action@v3
120+
121+
- name: Build and push codebattle image
122+
run: |
123+
make GIT_HASH=${{ github.sha }} docker-build-codebattle
124+
make docker-push-codebattle
125+
126+
- name: Build and push runner image
127+
run: |
128+
make docker-build-runner
129+
make docker-push-runner
117130
118131
# stop integratoin tests on CI becaues of https://github.com/hexlet-codebattle/codebattle/runs/580337561?check_suite_focus=true
119132
# - name: Pull dockers

.github/workflows/pr.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ on:
44
pull_request:
55
branches:
66
- master
7+
workflow_dispatch:
8+
79
jobs:
810
build:
911
runs-on: ubuntu-latest
1012

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
1117
# Use test environment by default
1218
env:
1319
MIX_ENV: test
20+
POSTGRES_PASSWORD: postgres
1421

1522
services:
1623
db:
1724
image: postgres:16-alpine
1825
ports: ["5432:5432"]
1926
env:
20-
POSTGRES_PASSWORD: postgres
27+
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
2128
options: >-
2229
--health-cmd pg_isready
2330
--health-interval 10s
@@ -28,28 +35,28 @@ jobs:
2835
2936
steps:
3037
- uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
3140

3241
- name: Setup Elixir
3342
uses: erlef/setup-beam@v1
3443
with:
3544
otp-version: "27.2"
3645
elixir-version: "1.18.2"
3746

38-
- name: Restore mix build cache
47+
- name: Cache Dependencies
3948
uses: actions/cache@v4
49+
id: deps-cache
4050
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
47-
with:
48-
path: ./services/app/_build
49-
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
50-
restore-keys: ${{ runner.os }}-build-
51+
path: |
52+
./services/app/deps
53+
./services/app/_build
54+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
55+
restore-keys: |
56+
${{ runner.os }}-mix-
5157
5258
- name: Get deps
59+
if: steps.deps-cache.outputs.cache-hit != 'true'
5360
run: mix deps.get
5461
working-directory: ./services/app
5562

@@ -62,12 +69,12 @@ jobs:
6269
working-directory: ./services/app
6370

6471
- name: Mix credo
65-
run: mix credo
72+
run: mix credo --strict
6673
working-directory: ./services/app
6774

6875
- name: Get yarn cache
6976
id: yarn-cache
70-
run: echo "::set-output name=dir::$(yarn cache dir)"
77+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
7178

7279
- uses: actions/cache@v4
7380
with:
@@ -77,7 +84,7 @@ jobs:
7784
${{ runner.os }}-yarn-
7885
7986
- name: Install yarn dependencies
80-
run: yarn install --froze-lockfile
87+
run: yarn install --frozen-lockfile
8188
working-directory: ./services/app/apps/codebattle
8289

8390
- name: Eslint
@@ -89,14 +96,16 @@ jobs:
8996
working-directory: ./services/app/apps/codebattle
9097

9198
- name: Setup db
92-
run: mix ecto.create && mix ecto.migrate
99+
run: |
100+
mix ecto.create
101+
mix ecto.migrate
93102
working-directory: ./services/app
94103

95104
- name: Mix tests
96105
run: make test
97106

98107
- name: Upload coverage to Codecov
99-
uses: codecov/codecov-action@v1
108+
uses: codecov/codecov-action@v4
100109
with:
101110
token: ${{ secrets.CODECOV_TOKEN }}
102111
file: ./services/app/assp/codebattle/cover/excoveralls.json

services/app/.credo.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#
2424
{Credo.Check.Consistency.ExceptionNames, []},
2525
{Credo.Check.Consistency.LineEndings, []},
26-
{Credo.Check.Consistency.ParameterPatternMatching, []},
26+
{Credo.Check.Consistency.ParameterPatternMatching, false},
2727
{Credo.Check.Consistency.SpaceAroundOperators, []},
2828
{Credo.Check.Consistency.SpaceInParentheses, []},
2929
{Credo.Check.Consistency.TabsOrSpaces, []},
@@ -34,8 +34,7 @@
3434
# You can customize the priority of any check
3535
# Priority values are: `low, normal, high, higher`
3636
#
37-
{Credo.Check.Design.AliasUsage,
38-
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
37+
{Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 4, if_called_more_often_than: 0]},
3938
# You can also customize the exit_status of each check.
4039
# If you don't want TODO comments to cause `mix credo` to fail, just
4140
# set this value to 0 (zero).

services/app/.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Used by "mix format"
22
[
3-
plugins: [Phoenix.LiveView.HTMLFormatter],
3+
plugins: [Styler, Phoenix.LiveView.HTMLFormatter],
44
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
55
subdirectories: ["apps/*"]
66
]

services/app/.iex.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import Ecto.Changeset
2+
import Ecto.Query
3+
14
alias Codebattle.Bot
25
alias Codebattle.Bot.Playbook
36
alias Codebattle.Chat
47
alias Codebattle.Game
5-
alias Codebattle.UserGameReport
68
alias Codebattle.Repo
79
alias Codebattle.TaskPack
810
alias Codebattle.Tournament
911
alias Codebattle.User
1012
alias Codebattle.UserGame
11-
12-
import Ecto.Query
13-
import Ecto.Changeset
13+
alias Codebattle.UserGameReport

services/app/apps/codebattle/.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
[
33
import_deps: [:ecto, :ecto_sql, :phoenix],
44
subdirectories: ["priv/*/migrations"],
5-
plugins: [Phoenix.LiveView.HTMLFormatter],
5+
plugins: [Styler, Phoenix.LiveView.HTMLFormatter],
66
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
77
]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ defmodule Codebattle.Application do
88
def start(_type, _args) do
99
if Application.get_env(:codebattle, :load_dot_env_file) do
1010
root_dir = @app_dir |> Path.join("../../../../") |> Path.expand()
11-
config_path = Mix.Project.config() |> Keyword.get(:config_path)
11+
config_path = Keyword.get(Mix.Project.config(), :config_path)
1212
env_path = Path.join(root_dir, ".env")
1313

1414
Envy.load([env_path])
15-
Config.Reader.read!(config_path) |> Application.put_all_env()
15+
config_path |> Config.Reader.read!() |> Application.put_all_env()
1616
end
1717

1818
github_tasks =
@@ -61,7 +61,7 @@ defmodule Codebattle.Application do
6161
{Codebattle.InvitesKillerServer, []},
6262
%{
6363
id: Codebattle.Chat.Lobby,
64-
start: {Codebattle.Chat, :start_link, [:lobby, %{message_ttl: :timer.hours(8)}]}
64+
start: {Codebattle.Chat, :start_link, [:lobby, %{message_ttl: to_timeout(hour: 8)}]}
6565
}
6666
] ++ github_tasks ++ bot_games ++ user_rank
6767

services/app/apps/codebattle/lib/codebattle/asserts/executor/remote.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
defmodule Codebattle.AssertsService.Executor.Remote do
22
@moduledoc false
33

4-
require Logger
5-
6-
alias Runner.AtomizedMap
74
alias Codebattle.AssertsService.Executor.Token
5+
alias Runner.AtomizedMap
6+
7+
require Logger
88

99
@spec call(Token.t()) :: Token.t()
1010
def call(token) do

services/app/apps/codebattle/lib/codebattle/asserts/output_parser.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
defmodule Codebattle.AssertsService.OutputParser do
22
@moduledoc "Parse container output for representing check status of solution"
33

4-
require Logger
5-
64
alias Codebattle.AssertsService.AssertResult
75
alias Codebattle.AssertsService.Result
86
alias Runner.AtomizedMap
97

8+
require Logger
9+
1010
def call(checker_token) do
1111
%{container_output: container_output, exit_code: exit_code} = checker_token
1212

@@ -21,7 +21,7 @@ defmodule Codebattle.AssertsService.OutputParser do
2121
|> Map.get(:execution_result)
2222
end
2323

24-
defp parse_output(token = %{exit_code: 0}) do
24+
defp parse_output(%{exit_code: 0} = token) do
2525
%{token | execution_result: Jason.decode!(token.container_output)}
2626
rescue
2727
_e ->
@@ -87,7 +87,7 @@ defmodule Codebattle.AssertsService.OutputParser do
8787
}
8888
end
8989

90-
defp parse_assert_result(item = %{"type" => "result"}) do
90+
defp parse_assert_result(%{"type" => "result"} = item) do
9191
status =
9292
if AtomizedMap.atomize(item["actual"]) == AtomizedMap.atomize(item["expected"]) do
9393
"success"

services/app/apps/codebattle/lib/codebattle/asserts/result.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
defmodule Codebattle.AssertsService.Result do
2-
use TypedStruct
3-
4-
alias Codebattle.AssertsService.AssertResult
5-
62
@moduledoc """
73
statuses:
84
initial -> no generation runs
@@ -12,6 +8,10 @@ defmodule Codebattle.AssertsService.Result do
128
error -> compile error, or out of memory
139
"""
1410

11+
use TypedStruct
12+
13+
alias Codebattle.AssertsService.AssertResult
14+
1515
@derive Jason.Encoder
1616

1717
typedstruct do

0 commit comments

Comments
 (0)