Compare commits

..
5 Commits
4 changed files with 135 additions and 10 deletions
+96
View File
@@ -0,0 +1,96 @@
name: CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
test:
name: Test
runs-on: ubuntu-24.04
env:
MIX_ENV: test
services:
postgres:
image: postgres:18.0
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 5s
--health-timeout 5s
--health-retries 10
steps:
- uses: actions/checkout@v7
- uses: jdx/mise-action@v2
- uses: actions/cache@v4
with:
path: |
deps
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-mix-test-${{ hashFiles('mix.lock', 'mise.toml') }}
restore-keys: |
${{ runner.os }}-mix-test-
- run: mix local.hex --force
- run: mix local.rebar --force
- run: mix deps.get
- run: mix format --check-formatted
- run: mix precommit
build-release:
name: Build release
needs: test
runs-on: ubuntu-24.04
env:
MIX_ENV: prod
SECRET_KEY_BASE: build-only-secret-key-base-build-only-secret-key-base-build-only-secret-key-base
DATABASE_URL: ecto://postgres:postgres@127.0.0.1:5432/chesstrainer_build
SES_REGION: eu-north-1
SES_ACCESS_KEY_ID: build
SES_SECRET_ACCESS_KEY: build
steps:
- uses: actions/checkout@v7
- uses: jdx/mise-action@v2
- uses: actions/cache@v4
with:
path: |
deps
~/.cargo/registry
~/.cargo/git
assets/node_modules
key: ${{ runner.os }}-mix-prod-${{ hashFiles('mix.lock', 'mise.toml', 'assets/package-lock.json') }}
restore-keys: |
${{ runner.os }}-mix-prod-
- run: mix local.hex --force
- run: mix local.rebar --force
- run: npm ci --prefix assets --no-audit --no-fund
- run: mix deps.get --only prod
- run: mix assets.setup
- run: mix assets.deploy
- run: mix release
- run: tar -czf chesstrainer-release.tar.gz -C _build/prod/rel/chesstrainer .
- uses: actions/upload-artifact@v4
with:
name: chesstrainer-release
path: chesstrainer-release.tar.gz
retention-days: 7
+7
View File
@@ -18,6 +18,7 @@ Internet
| Erlang | 28.5 |
| Elixir | 1.19.5-otp-28 |
| Rust | 1.98.1 |
| Node.js | 24 (asset build only) |
| Postgres | `postgres:18.0`, pinned directly in the unified compose |
| Caddy | 2.11.9 |
| Docker | 29.9.3 |
@@ -34,6 +35,7 @@ A new Ubuntu 24.04 VPS needs:
- Docker Engine and the Compose plugin
- Caddy
- `curl`, `ca-certificates`, `libstdc++6`, `openssl`
- Node.js 24 + npm if you build the release on this host instead of CI
- DNS and TLS for the domain
- A non-root deploy user with SSH access
@@ -307,6 +309,8 @@ Build on a machine matching Ubuntu 24.04 / glibc 2.39, or let CI do it.
The release tarball is the contents of the release directory:
```sh
npm ci --prefix assets --no-audit --no-fund
export MIX_ENV=prod
mix deps.get --only prod
mix assets.deploy
@@ -315,6 +319,9 @@ mix release
tar -czf chesstrainer-release.tar.gz -C _build/prod/rel/chesstrainer .
```
`npm ci` is required before `mix assets.deploy`: Tailwind imports the
Chessground CSS and esbuild bundles the package from `assets/node_modules`.
`mix assets.deploy` runs `compile` first so the generated LiveView colocated
CSS exists.
+1
View File
@@ -2,3 +2,4 @@
erlang = "28.5"
elixir = "1.19.5-otp-28"
rust = "1.98.1"
node = "24"
+31 -10
View File
@@ -7,18 +7,39 @@ defmodule Chesstrainer.EndgamesFixtures do
@doc """
Generate a unique endgame FEN.
Endgames have a unique constraint on :fen, so tests need
distinct FENs when inserting more than one. Each call
shifts the white king's file to avoid FEN collisions.
Endgames have a unique constraint on :fen, so tests need distinct FENs when
inserting more than one. The white king moves across 56 board squares and the
fullmove number is always unique, so repeated calls cannot collide.
"""
def unique_endgame_fen do
# White king on rank 1 in columns b..g, leaving 1-6 empty squares
# before and 6-1 after. Both before_king and after_king are valid
# single digits (1-8), and the rank sums to 8.
offset = System.unique_integer([:positive]) |> rem(6)
before_king = offset + 1
after_king = 7 - before_king
"4k3/8/8/8/8/8/8/#{before_king}K#{after_king} w - - 0 1"
n = System.unique_integer([:positive, :monotonic])
rank = rem(div(n, 8), 7) + 1
file = rem(n, 8)
# Avoid placing the white king directly next to the black king on e8.
file = if rank == 7 and file == 4, do: 0, else: file
white_king_row = row_with_king(file)
board =
8..1//-1
|> Enum.map(fn
8 -> "4k3"
^rank -> white_king_row
_ -> "8"
end)
|> Enum.join("/")
"#{board} w - - 0 #{n}"
end
defp row_with_king(file) do
before_count = file
after_count = 7 - file
before_part = if before_count > 0, do: Integer.to_string(before_count), else: ""
after_part = if after_count > 0, do: Integer.to_string(after_count), else: ""
before_part <> "K" <> after_part
end
@doc """