Try fixing CI.

This commit is contained in:
Luca Palmieri 2020-12-05 18:22:18 +00:00
parent 13da6f9b28
commit 30e838f6c5
2 changed files with 8 additions and 2 deletions

View file

@ -32,10 +32,14 @@ jobs:
toolchain: stable
override: true
- name: Migrate database
env:
# Weird networking issue in GitHub actions... It fails with 'connection refused' if we use 'localhost'.
POSTGRES_HOST: postgres
SKIP_DOCKER: true
run: |
sudo apt-get install libpq-dev -y
cargo install --version=0.2.0 sqlx-cli --no-default-features --features postgres
SKIP_DOCKER=true ./scripts/init_db.sh
./scripts/init_db.sh
- uses: actions-rs/cargo@v1
with:
command: test

View file

@ -10,6 +10,8 @@ DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
DB_NAME="${POSTGRES_DB:=newsletter}"
# Check if a custom port has been set, otherwise default to '5432'
DB_PORT="${POSTGRES_PORT:=5432}"
# Check if a custom host has been set, otherwise default to 'localhost'
DB_HOST="${POSTGRES_HOST:=localhost}"
# Allow to skip Docker if a dockerized Postgres database is already running
if [[ -z "${SKIP_DOCKER}" ]]
@ -26,7 +28,7 @@ then
fi
# Keep pinging Postgres until it's ready to accept commands
until PGPASSWORD="${DB_PASSWORD}" psql -h "localhost" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
>&2 echo "Postgres is still unavailable - sleeping"
sleep 1
done