Skip to content

Commit

Permalink
ci: test without sqlx-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ValuedMammal committed Sep 24, 2024
1 parent ef6e235 commit 7bcce21
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 85 deletions.
49 changes: 23 additions & 26 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ on:
env:
CARGO_TERM_COLOR: auto
SQLX_VERSION: 0.8.2
SQLX_FEATURES: "rustls,postgres"
DATABASE_TEST_URL: postgres://postgres:password@localhost:5432/bdk_wallet
DATABASE_TEST_URL: postgres://postgres:password@localhost:5432/testdb

jobs:
build-test:
Expand All @@ -26,6 +25,13 @@ jobs:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# Map ports on service container to the host
ports:
- 5432:5432
steps:
Expand All @@ -34,32 +40,23 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}
- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--no-default-features
--features ${{ env.SQLX_FEATURES }}
--locked
- name: Migrate database
- name: Create database
run: |
sudo apt-get install libpq-dev -y
./ci/init_db.sh
# - name: Check .sqlx is up-to-date
# run: |
# cargo sqlx prepare --workspace --check
psql -h localhost -p 5432 -U postgres -d postgres -c 'create user testuser'
psql -h localhost -p 5432 -U postgres -d postgres -c 'create database testdb with owner = testuser'
- name: Test
run: cargo test

fmt-clippy:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Check fmt
run: cargo fmt --check
- name: Clippy
run: cargo clippy -- -D warnings
# fmt-clippy:
# name: Check
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# components: rustfmt, clippy
# - name: Check fmt
# run: cargo fmt --check
# - name: Clippy
# run: cargo clippy -- -D warnings
118 changes: 59 additions & 59 deletions ci/init_db.sh
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
#!/usr/bin/env bash
set -x
set -eo pipefail

if ! [ -x "$(command -v psql)" ]; then
echo >&2 "Error: psql is not installed."
exit 1
fi

if ! [ -x "$(command -v sqlx)" ]; then
echo >&2 "Error: sqlx is not installed."
echo >&2 "Use:"
echo >&2 " cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres"
echo >&2 "to install it."
exit 1
fi

# Check if a custom user has been set, otherwise default to 'postgres'
DB_USER="${POSTGRES_USER:=postgres}"
# Check if a custom password has been set, otherwise default to 'password'
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
# Check if a custom database name has been set, otherwise default to 'bdk_wallet'
DB_NAME="${POSTGRES_DB:=bdk_wallet}"
# 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}" ]]
# then
# # if a postgres container is running, print instructions to kill it and exit
# RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
# if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
# echo >&2 "there is a postgres container already running, kill it with"
# echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
# exit 1
# fi
# # Launch postgres using Docker
# docker run \
# -e POSTGRES_USER=${DB_USER} \
# -e POSTGRES_PASSWORD=${DB_PASSWORD} \
# -e POSTGRES_DB=${DB_NAME} \
# -p "${DB_PORT}":5432 \
# -d \
# --name "postgres_$(date '+%s')" \
# postgres -N 1000
# # ^ Increased maximum number of connections for testing purposes
# fi

# Keep pinging Postgres until it's ready to accept commands
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
# set -x
# set -eo pipefail

>&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations."
# if ! [ -x "$(command -v psql)" ]; then
# echo >&2 "Error: psql is not installed."
# exit 1
# fi

export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
sqlx database create
sqlx migrate run --source ./db/migrations
# if ! [ -x "$(command -v sqlx)" ]; then
# echo >&2 "Error: sqlx is not installed."
# echo >&2 "Use:"
# echo >&2 " cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres"
# echo >&2 "to install it."
# exit 1
# fi

>&2 echo "Completed migration."
# # Check if a custom user has been set, otherwise default to 'postgres'
# DB_USER="${POSTGRES_USER:=postgres}"
# # Check if a custom password has been set, otherwise default to 'password'
# DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
# # Check if a custom database name has been set, otherwise default to 'bdk_wallet'
# DB_NAME="${POSTGRES_DB:=bdk_wallet}"
# # 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}" ]]
# # then
# # # if a postgres container is running, print instructions to kill it and exit
# # RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
# # if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
# # echo >&2 "there is a postgres container already running, kill it with"
# # echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
# # exit 1
# # fi
# # # Launch postgres using Docker
# # docker run \
# # -e POSTGRES_USER=${DB_USER} \
# # -e POSTGRES_PASSWORD=${DB_PASSWORD} \
# # -e POSTGRES_DB=${DB_NAME} \
# # -p "${DB_PORT}":5432 \
# # -d \
# # --name "postgres_$(date '+%s')" \
# # postgres -N 1000
# # # ^ Increased maximum number of connections for testing purposes
# # fi

# # Keep pinging Postgres until it's ready to accept commands
# 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

# >&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations."

# export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
# sqlx database create
# sqlx migrate run --source ./db/migrations

# >&2 echo "Completed migration."

0 comments on commit 7bcce21

Please sign in to comment.