Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create GitHub action #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions .github/workflows/mix-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Elixir CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

name: Build and test
runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432


steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: actions/setup-elixir@v1
with:
elixir-version: '1.10.3' # Define the elixir version [required]
otp-version: '22.3' # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Create DB
run: mix ecto.create
env:
MIX_ENV: test
- name: Run tests
run: mix test
9 changes: 6 additions & 3 deletions test/support/repo_case.ex
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
defmodule EctoResource.RepoCase do
use ExUnit.CaseTemplate

alias Ecto.Integration.TestRepo

using do
quote do
alias EctoResource.TestRepo, as: Repo
alias Ecto.Integration.TestRepo, as: Repo
# alias EctoResource.TestRepo, as: Repo
import Ecto
import Ecto.Query
import EctoResource.RepoCase
end
end

setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(EctoResource.TestRepo)
:ok = Ecto.Adapters.SQL.Sandbox.checkout(TestRepo)

unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(EctoResource.TestRepo, {:shared, self()})
Ecto.Adapters.SQL.Sandbox.mode(TestRepo, {:shared, self()})
end

:ok
Expand Down
31 changes: 30 additions & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(EctoResource.TestRepo, :manual)
# Ecto.Adapters.SQL.Sandbox.mode(EctoResource.TestRepo, :manual)

alias Ecto.Integration.TestRepo

Application.put_env(
:ecto,
TestRepo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL", "ecto://localhost/ecto_network_test"),
pool: Ecto.Adapters.SQL.Sandbox
)

defmodule Ecto.Integration.TestRepo do
use Ecto.Repo,
otp_app: :ecto,
adapter: Ecto.Adapters.Postgres
end

{:ok, _} = Ecto.Adapters.Postgres.ensure_all_started(TestRepo, :temporary)

_ = Ecto.Adapters.Postgres.storage_down(TestRepo.config())
:ok = Ecto.Adapters.Postgres.storage_up(TestRepo.config())

{:ok, _pid} = TestRepo.start_link()

Code.require_file("ecto_migration.exs", __DIR__)

:ok = Ecto.Migrator.up(TestRepo, 0, Ecto.Integration.Migration, log: false)
Ecto.Adapters.SQL.Sandbox.mode(TestRepo, :manual)
Process.flag(:trap_exit, true)