Skip to content

Commit 41561fb

Browse files
committed
Update GitHub workflow
1 parent 4ac0d48 commit 41561fb

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

.github/workflows/development.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@ on:
77
branches: ["develop"]
88

99
env:
10-
MIX_ENV: dev
10+
MIX_ENV: test
1111

1212
permissions:
1313
contents: read
1414

1515
jobs:
1616
build:
1717
name: OS ${{matrix.os}} / Elixir ${{matrix.elixir}} / OTP ${{matrix.otp}}
18+
services:
19+
db:
20+
image: postgres:16
21+
ports: ["5432:5432"]
22+
env:
23+
POSTGRES_USER: ${{ vars.POSTGRES_USERNAME }}
24+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
25+
options: >-
26+
--health-cmd pg_isready
27+
--health-interval 10s
28+
--health-timeout 5s
29+
--health-retries 5
1830
strategy:
1931
matrix:
2032
elixir: ['1.14', '1.15', '1.16', '1.17']
@@ -48,16 +60,15 @@ jobs:
4860
path: deps
4961
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
5062
restore-keys: ${{ runner.os }}-mix-
51-
- name: Set up Postgres
52-
run: |
53-
sudo apt-get update
54-
sudo apt-get install -y postgresql
55-
sudo service postgresql start
56-
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'postgres';"
5763
- name: Install dependencies
5864
run: mix deps.get
59-
- name: Create database
60-
run: mix do ecto.create, ecto.migrate
65+
- name: Reset database and run migrations
66+
env:
67+
POSTGRES_USERNAME: ${{ vars.POSTGRES_USERNAME }}
68+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
69+
POSTGRES_HOSTNAME: ${{ vars.POSTGRES_HOSTNAME }}
70+
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
71+
run: mix ecto.drop && mix ecto.create
6172
- name: Compile code
6273
run: mix compile --warnings-as-errors
6374
- name: Check Formatting
@@ -67,4 +78,9 @@ jobs:
6778
- name: Credo
6879
run: mix credo
6980
- name: Run tests
70-
run: MIX_ENV=test mix test
81+
env:
82+
POSTGRES_USERNAME: ${{ vars.POSTGRES_USERNAME }}
83+
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
84+
POSTGRES_HOSTNAME: ${{ vars.POSTGRES_HOSTNAME }}
85+
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
86+
run: mix test

config/config.exs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ if config_env() == :test do
6060
ecto_repos: [Kanta.Test.Repo]
6161

6262
config :kanta, Kanta.Test.Repo,
63+
username: System.get_env("POSTGRES_USERNAME", "postgres"),
64+
password: System.get_env("POSTGRES_PASSWORD", "postgres"),
65+
hostname: System.get_env("POSTGRES_HOSTNAME", "localhost"),
6366
database: "kanta_test",
64-
hostname: "localhost",
67+
port: 5432,
6568
pool: Ecto.Adapters.SQL.Sandbox,
6669
pool_size: 10
6770
end

0 commit comments

Comments
 (0)