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 | | Erlang | 28.5 |
| Elixir | 1.19.5-otp-28 | | Elixir | 1.19.5-otp-28 |
| Rust | 1.98.1 | | Rust | 1.98.1 |
| Node.js | 24 (asset build only) |
| Postgres | `postgres:18.0`, pinned directly in the unified compose | | Postgres | `postgres:18.0`, pinned directly in the unified compose |
| Caddy | 2.11.9 | | Caddy | 2.11.9 |
| Docker | 29.9.3 | | Docker | 29.9.3 |
@@ -34,6 +35,7 @@ A new Ubuntu 24.04 VPS needs:
- Docker Engine and the Compose plugin - Docker Engine and the Compose plugin
- Caddy - Caddy
- `curl`, `ca-certificates`, `libstdc++6`, `openssl` - `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 - DNS and TLS for the domain
- A non-root deploy user with SSH access - 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: The release tarball is the contents of the release directory:
```sh ```sh
npm ci --prefix assets --no-audit --no-fund
export MIX_ENV=prod export MIX_ENV=prod
mix deps.get --only prod mix deps.get --only prod
mix assets.deploy mix assets.deploy
@@ -315,6 +319,9 @@ mix release
tar -czf chesstrainer-release.tar.gz -C _build/prod/rel/chesstrainer . 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 `mix assets.deploy` runs `compile` first so the generated LiveView colocated
CSS exists. CSS exists.
+1
View File
@@ -2,3 +2,4 @@
erlang = "28.5" erlang = "28.5"
elixir = "1.19.5-otp-28" elixir = "1.19.5-otp-28"
rust = "1.98.1" rust = "1.98.1"
node = "24"
+31 -10
View File
@@ -7,18 +7,39 @@ defmodule Chesstrainer.EndgamesFixtures do
@doc """ @doc """
Generate a unique endgame FEN. Generate a unique endgame FEN.
Endgames have a unique constraint on :fen, so tests need Endgames have a unique constraint on :fen, so tests need distinct FENs when
distinct FENs when inserting more than one. Each call inserting more than one. The white king moves across 56 board squares and the
shifts the white king's file to avoid FEN collisions. fullmove number is always unique, so repeated calls cannot collide.
""" """
def unique_endgame_fen do def unique_endgame_fen do
# White king on rank 1 in columns b..g, leaving 1-6 empty squares n = System.unique_integer([:positive, :monotonic])
# before and 6-1 after. Both before_king and after_king are valid rank = rem(div(n, 8), 7) + 1
# single digits (1-8), and the rank sums to 8. file = rem(n, 8)
offset = System.unique_integer([:positive]) |> rem(6) # Avoid placing the white king directly next to the black king on e8.
before_king = offset + 1 file = if rank == 7 and file == 4, do: 0, else: file
after_king = 7 - before_king
"4k3/8/8/8/8/8/8/#{before_king}K#{after_king} w - - 0 1" 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 end
@doc """ @doc """