Skip to content
Merged

CI #1

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
24 changes: 21 additions & 3 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,examples,test,test_integration}/**/*.{ex,exs}"]
]

integration_apps =
Enum.map(
Path.wildcard("test_integration/apps/*"),
&"#{&1}/{config,lib,test,mix}/**/*.{ex,exs}"
)

inputs =
[
"{mix,.formatter}.exs",
"config/*.exs",
"lib/**/*.ex",
"examples/**/*.exs",
"test/**/*.{ex,exs}",
"priv/repo/migrations/**/*.exs",
"priv/repo/*/migrations/**/*.exs"
] ++ integration_apps

IO.inspect(inputs)

[inputs: inputs]
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: solnic
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
tests:
name: Run tests (Elixir ${{ matrix.elixir-version }})
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false

matrix:
include:
- elixir-version: "1.18.4"
container: "dev-latest"
- elixir-version: "1.17.3"
container: "dev-1.17"
- elixir-version: "1.16.3"
container: "dev-1.16"
- elixir-version: "1.15.8"
container: "dev-1.15"

steps:
- uses: actions/checkout@v4

- name: Start db service
run: docker compose up -d postgres

- name: Restore deps and _build cache
uses: actions/cache@v3
with:
# we exclude tls_certificate_check because its dir has no x bit and tar fails to access
# it when creating a cache tarbal
path: |
_build
deps/*
!deps/tls_certificate_check
key: ${{ runner.os }}-mix-${{ matrix.container }}-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-mix-${{ matrix.container }}-

- name: Setup
run: docker compose run -e MIX_ENV=test --rm ${{ matrix.container }} bin/setup

- name: Run tests
run: docker compose run -e MIX_ENV=test --rm ${{ matrix.container }} mix test
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ drops_relation-*.tar
priv/*.db*
priv/repo/*sqlite*

test_integration/apps/*/_build
test_integration/apps/*/deps
test_integration/apps/*/priv/repo/*sqlite*
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG ELIXIR_VERSION=1.18.4
ARG OTP_VERSION=28.0.2
ARG DISTRO=ubuntu-noble-20250714

ARG IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-${DISTRO}"

FROM ${IMAGE}

RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
git \
postgresql-client-16 \
libpq-dev \
sqlite3

WORKDIR /workspace/drops-relation

COPY mix.exs mix.lock ./

RUN mix local.hex --force && \
mix local.rebar --force
23 changes: 23 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

cd test_integration/apps/pristine

mix deps.get
mix compile

cd ../../..

cd test_integration/apps/sample

mix deps.get
mix compile

mix ecto.setup
mix drops.relation.refresh_cache

cd ../../..

mix deps.get
mix compile

mix ecto.setup
12 changes: 10 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import Config

# Configure ecto repos
config :drops_relation, ecto_repos: [Test.Repos.Sqlite, Test.Repos.Postgres]
# Configure ecto repos - environment specific
case config_env() do
:test ->
config :drops_relation,
ecto_repos: [Test.Repos.Sqlite, Test.Repos.Postgres, MyApp.Repo]

_ ->
config :drops_relation,
ecto_repos: [MyApp.Repo]
end

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
Expand Down
28 changes: 16 additions & 12 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@ import Config

env = config_env()

if adapter = System.get_env("ADAPTER") do
config :drops_relation, ecto_repos: [Module.concat(["Test", "Repos", adapter])]
end
# if adapter = System.get_env("ADAPTER") do
# config :drops_relation, ecto_repos: [Module.concat(["Test", "Repos", adapter])]
# end

config :logger, :default_handler, config: [file: ~c"log/#{env}.log"]

config :drops_relation, Test.Repos.Sqlite,
adapter: Ecto.Adapters.SQLite3,
database: "priv/repo/#{env}.sqlite",
pool_size: 1,
pool: Ecto.Adapters.SQL.Sandbox,
queue_target: 5000,
queue_interval: 1000,
log: :debug,
priv: "priv/repo/sqlite"
priv: "priv/repo/sqlite",
log: :debug

config :drops_relation, Test.Repos.Postgres,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
hostname: "postgres",
hostname: System.get_env("POSTGRES_HOST", "postgres"),
database: "drops_relation_#{env}",
pool_size: 10,
pool: Ecto.Adapters.SQL.Sandbox,
queue_target: 5000,
queue_interval: 1000,
priv: "priv/repo/postgres",
log: :debug

config :drops_relation, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
hostname: System.get_env("POSTGRES_HOST", "postgres"),
database: "drops_relation_#{env}_my_app",
pool: Ecto.Adapters.SQL.Sandbox,
priv: "priv/repo/postgres",
log: :debug
76 changes: 76 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
services:
base: &base
build:
context: .
dockerfile: Dockerfile
working_dir: /workspace/drops-relation
command: sleep infinity
depends_on: [postgres]
links: [postgres]
volumes:
- ".:/workspace/drops-relation"
- "drops_relation_deps:/workspace/drops-relation/deps"

postgres:
image: postgres:latest
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_DATABASE: postgres
POSTGRES_USERNAME: postgres
ports:
- 5432:5432
command: [ "postgres", "-c", "log_statement=all" ]
volumes:
- "drops_relation_pgdata:/var/lib/postgresql/data"

dev-latest: &dev-latest
<<: *base
build:
context: .
dockerfile: Dockerfile
args:
ELIXIR_VERSION: 1.18.4
OTP_VERSION: 28.0.2

dev-1.17:
<<: *base
build:
context: .
dockerfile: Dockerfile
args:
ELIXIR_VERSION: 1.17.3
OTP_VERSION: 27.3.4.2

dev-1.16:
<<: *base
build:
context: .
dockerfile: Dockerfile
args:
ELIXIR_VERSION: 1.16.3
OTP_VERSION: 26.2.5.14

dev-1.15:
<<: *base
build:
context: .
dockerfile: Dockerfile
args:
ELIXIR_VERSION: 1.15.8
OTP_VERSION: 25.3.2.21

dev-1.14:
<<: *base
build:
context: .
dockerfile: Dockerfile
args:
ELIXIR_VERSION: 1.14.5
OTP_VERSION: 24.3.4.17

test:
<<: *dev-latest

volumes:
drops_relation_deps:
drops_relation_pgdata:
Binary file removed drops_relation_test
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/drops/relation/cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ defmodule Drops.Relation.Cache do
end

defp encode(data) do
JSON.encode!(data)
Drops.Relation.json().encode!(data)
end

defp decode(data) do
JSON.decode!(data)
Drops.Relation.json().decode!(data)
end

defp read_cache_file(cache_file) do
Expand Down
8 changes: 8 additions & 0 deletions lib/drops/relation/relation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ defmodule Drops.Relation do
end
end

if Code.ensure_loaded?(JSON) do
@doc false
def json, do: JSON
else
@doc false
def json, do: Jason
end

@core_plugins [
Drops.Relation.Plugins.Schema,
Drops.Relation.Plugins.Queryable,
Expand Down
14 changes: 0 additions & 14 deletions lib/drops/relation/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ defmodule Drops.Relation.Schema do

use Serializable

# defimpl JSON.Encoder do
# def encode(schema, opts) do
# JSON.Encoder.encode(
# Map.merge(
# %{
# __struct__: "Schema"
# },
# Map.from_struct(schema)
# ),
# opts
# )
# end
# end

@doc """
Creates a new Schema struct with the provided metadata.

Expand Down
15 changes: 6 additions & 9 deletions lib/drops/relation/schema/serializable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ defmodule Drops.Relation.Schema.Serializable do

defmacro __using__(_opts) do
quote location: :keep do
defimpl JSON.Encoder, for: __MODULE__ do
def encode(component, opts) do
defimpl unquote(Drops.Relation.json()).Encoder, for: __MODULE__ do
def encode(component, _opts) do
attributes = Dumper.dump(Map.from_struct(component))

JSON.Encoder.encode(
%{
__struct__: component.__struct__.name(),
attributes: attributes
},
opts
)
Drops.Relation.json().encode!(%{
__struct__: component.__struct__.name(),
attributes: attributes
})
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/dev/test.setup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if Mix.env() == :test do

case adapter() do
nil ->
Test.Repos.start(:all)
Test.Repos.start_all(:auto)

adapter ->
Test.Repos.start(adapter)
Expand Down
Loading