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
65 changes: 39 additions & 26 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
if: github.repository == 'hexlet-codebattle/codebattle'
runs-on: ubuntu-latest
timeout-minutes: 30 # Add timeout to prevent hanging builds

# Use test environment by default
env:
MIX_ENV: test
DOCKER_BUILDKIT: 1 # Enable buildkit for faster docker builds

services:
db:
image: postgres:16-alpine
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust # Simplify auth for CI
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -29,29 +33,31 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch complete history for better caching

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

- name: Restore Dependencies Cache
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
- name: Cache Dependencies
uses: actions/cache@v4
id: deps-cache
with:
path: ./services/app/_build
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-build-
path: |
./services/app/deps
./services/app/_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-

- name: Get deps
run: mix deps.get
run: |
mix local.hex --force
mix local.rebar --force
mix deps.get
working-directory: ./services/app

- name: Mix deps.compile
Expand All @@ -68,7 +74,7 @@ jobs:

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

- uses: actions/cache@v4
with:
Expand All @@ -78,7 +84,7 @@ jobs:
${{ runner.os }}-yarn-

- name: Install yarn dependencies
run: yarn install --froze-lockfile
run: yarn install --frozen-lockfile --network-timeout 300000
working-directory: ./services/app/apps/codebattle

- name: Eslint
Expand All @@ -97,23 +103,30 @@ jobs:
run: make test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./services/app/assp/codebattle/cover/excoveralls.json
fail_ci_if_error: false

- name: Login to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Build docker image for codebattle
run: make GIT_HASH=${{ github.sha }} docker-build-codebattle
- name: Push docker image for codebattle
run: make docker-push-codebattle
- name: Build docker image for runner
run: make docker-build-runner
- name: Push docker image for runner
run: make docker-push-runner
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push codebattle image
run: |
make GIT_HASH=${{ github.sha }} docker-build-codebattle
make docker-push-codebattle

- name: Build and push runner image
run: |
make docker-build-runner
make docker-push-runner

# stop integratoin tests on CI becaues of https://github.com/hexlet-codebattle/codebattle/runs/580337561?check_suite_focus=true
# - name: Pull dockers
Expand Down
43 changes: 26 additions & 17 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ on:
pull_request:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# Use test environment by default
env:
MIX_ENV: test
POSTGRES_PASSWORD: postgres

services:
db:
image: postgres:16-alpine
ports: ["5432:5432"]
env:
POSTGRES_PASSWORD: postgres
POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
Expand All @@ -28,28 +35,28 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

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

- name: Restore mix build cache
- name: Cache Dependencies
uses: actions/cache@v4
id: deps-cache
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: ./services/app/_build
key: ${{ runner.os }}-build-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-build-
path: |
./services/app/deps
./services/app/_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-

- name: Get deps
if: steps.deps-cache.outputs.cache-hit != 'true'
run: mix deps.get
working-directory: ./services/app

Expand All @@ -62,12 +69,12 @@ jobs:
working-directory: ./services/app

- name: Mix credo
run: mix credo
run: mix credo --strict
working-directory: ./services/app

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

- uses: actions/cache@v4
with:
Expand All @@ -77,7 +84,7 @@ jobs:
${{ runner.os }}-yarn-

- name: Install yarn dependencies
run: yarn install --froze-lockfile
run: yarn install --frozen-lockfile
working-directory: ./services/app/apps/codebattle

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

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

- name: Mix tests
run: make test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./services/app/assp/codebattle/cover/excoveralls.json
Expand Down
5 changes: 2 additions & 3 deletions services/app/.credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.ParameterPatternMatching, false},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},
Expand All @@ -34,8 +34,7 @@
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
{Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 4, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
Expand Down
2 changes: 1 addition & 1 deletion services/app/.formatter.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Used by "mix format"
[
plugins: [Phoenix.LiveView.HTMLFormatter],
plugins: [Styler, Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["apps/*"]
]
8 changes: 4 additions & 4 deletions services/app/.iex.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Ecto.Changeset
import Ecto.Query

alias Codebattle.Bot
alias Codebattle.Bot.Playbook
alias Codebattle.Chat
alias Codebattle.Game
alias Codebattle.UserGameReport
alias Codebattle.Repo
alias Codebattle.TaskPack
alias Codebattle.Tournament
alias Codebattle.User
alias Codebattle.UserGame

import Ecto.Query
import Ecto.Changeset
alias Codebattle.UserGameReport
2 changes: 1 addition & 1 deletion services/app/apps/codebattle/.formatter.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
[
import_deps: [:ecto, :ecto_sql, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
plugins: [Styler, Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]
6 changes: 3 additions & 3 deletions services/app/apps/codebattle/lib/codebattle/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ defmodule Codebattle.Application do
def start(_type, _args) do
if Application.get_env(:codebattle, :load_dot_env_file) do
root_dir = @app_dir |> Path.join("../../../../") |> Path.expand()
config_path = Mix.Project.config() |> Keyword.get(:config_path)
config_path = Keyword.get(Mix.Project.config(), :config_path)
env_path = Path.join(root_dir, ".env")

Envy.load([env_path])
Config.Reader.read!(config_path) |> Application.put_all_env()
config_path |> Config.Reader.read!() |> Application.put_all_env()
end

github_tasks =
Expand Down Expand Up @@ -61,7 +61,7 @@ defmodule Codebattle.Application do
{Codebattle.InvitesKillerServer, []},
%{
id: Codebattle.Chat.Lobby,
start: {Codebattle.Chat, :start_link, [:lobby, %{message_ttl: :timer.hours(8)}]}
start: {Codebattle.Chat, :start_link, [:lobby, %{message_ttl: to_timeout(hour: 8)}]}
}
] ++ github_tasks ++ bot_games ++ user_rank

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule Codebattle.AssertsService.Executor.Remote do
@moduledoc false

require Logger

alias Runner.AtomizedMap
alias Codebattle.AssertsService.Executor.Token
alias Runner.AtomizedMap

require Logger

@spec call(Token.t()) :: Token.t()
def call(token) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule Codebattle.AssertsService.OutputParser do
@moduledoc "Parse container output for representing check status of solution"

require Logger

alias Codebattle.AssertsService.AssertResult
alias Codebattle.AssertsService.Result
alias Runner.AtomizedMap

require Logger

def call(checker_token) do
%{container_output: container_output, exit_code: exit_code} = checker_token

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

defp parse_output(token = %{exit_code: 0}) do
defp parse_output(%{exit_code: 0} = token) do
%{token | execution_result: Jason.decode!(token.container_output)}
rescue
_e ->
Expand Down Expand Up @@ -87,7 +87,7 @@ defmodule Codebattle.AssertsService.OutputParser do
}
end

defp parse_assert_result(item = %{"type" => "result"}) do
defp parse_assert_result(%{"type" => "result"} = item) do
status =
if AtomizedMap.atomize(item["actual"]) == AtomizedMap.atomize(item["expected"]) do
"success"
Expand Down
8 changes: 4 additions & 4 deletions services/app/apps/codebattle/lib/codebattle/asserts/result.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
defmodule Codebattle.AssertsService.Result do
use TypedStruct

alias Codebattle.AssertsService.AssertResult

@moduledoc """
statuses:
initial -> no generation runs
Expand All @@ -12,6 +8,10 @@ defmodule Codebattle.AssertsService.Result do
error -> compile error, or out of memory
"""

use TypedStruct

alias Codebattle.AssertsService.AssertResult

@derive Jason.Encoder

typedstruct do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule Codebattle.AssertsService.Executor.Token do
@moduledoc false
use TypedStruct

alias Codebattle.AssertsService
Expand Down
Loading
Loading