Skip to content

Commit 620d5f6

Browse files
committed
ci: test without sqlx-cli
1 parent ef6e235 commit 620d5f6

File tree

2 files changed

+83
-85
lines changed

2 files changed

+83
-85
lines changed

.github/workflows/rust.yml

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ on:
1212
env:
1313
CARGO_TERM_COLOR: auto
1414
SQLX_VERSION: 0.8.2
15-
SQLX_FEATURES: "rustls,postgres"
16-
DATABASE_TEST_URL: postgres://postgres:password@localhost:5432/bdk_wallet
15+
PGPASSWORD: password
16+
DATABASE_TEST_URL: postgres://postgres:password@localhost:5432/testdb
1717

1818
jobs:
1919
build-test:
@@ -26,6 +26,13 @@ jobs:
2626
POSTGRES_USER: postgres
2727
POSTGRES_PASSWORD: password
2828
POSTGRES_DB: postgres
29+
# Set health checks to wait until postgres has started
30+
options: >-
31+
--health-cmd pg_isready
32+
--health-interval 10s
33+
--health-timeout 5s
34+
--health-retries 5
35+
# Map ports on service container to the host
2936
ports:
3037
- 5432:5432
3138
steps:
@@ -34,32 +41,23 @@ jobs:
3441
- uses: Swatinem/rust-cache@v2
3542
with:
3643
key: sqlx-${{ env.SQLX_VERSION }}
37-
- name: Install sqlx-cli
38-
run:
39-
cargo install sqlx-cli
40-
--version=${{ env.SQLX_VERSION }}
41-
--no-default-features
42-
--features ${{ env.SQLX_FEATURES }}
43-
--locked
44-
- name: Migrate database
44+
- name: Create database
4545
run: |
4646
sudo apt-get install libpq-dev -y
47-
./ci/init_db.sh
48-
# - name: Check .sqlx is up-to-date
49-
# run: |
50-
# cargo sqlx prepare --workspace --check
47+
psql -h localhost -p 5432 -U postgres -d postgres -c 'create user testuser'
48+
psql -h localhost -p 5432 -U postgres -d postgres -c 'create database testdb with owner = testuser'
5149
- name: Test
5250
run: cargo test
5351

54-
fmt-clippy:
55-
name: Check
56-
runs-on: ubuntu-latest
57-
steps:
58-
- uses: actions/checkout@v4
59-
- uses: dtolnay/rust-toolchain@stable
60-
with:
61-
components: rustfmt, clippy
62-
- name: Check fmt
63-
run: cargo fmt --check
64-
- name: Clippy
65-
run: cargo clippy -- -D warnings
52+
# fmt-clippy:
53+
# name: Check
54+
# runs-on: ubuntu-latest
55+
# steps:
56+
# - uses: actions/checkout@v4
57+
# - uses: dtolnay/rust-toolchain@stable
58+
# with:
59+
# components: rustfmt, clippy
60+
# - name: Check fmt
61+
# run: cargo fmt --check
62+
# - name: Clippy
63+
# run: cargo clippy -- -D warnings

ci/init_db.sh

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
#!/usr/bin/env bash
2-
set -x
3-
set -eo pipefail
4-
5-
if ! [ -x "$(command -v psql)" ]; then
6-
echo >&2 "Error: psql is not installed."
7-
exit 1
8-
fi
9-
10-
if ! [ -x "$(command -v sqlx)" ]; then
11-
echo >&2 "Error: sqlx is not installed."
12-
echo >&2 "Use:"
13-
echo >&2 " cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres"
14-
echo >&2 "to install it."
15-
exit 1
16-
fi
17-
18-
# Check if a custom user has been set, otherwise default to 'postgres'
19-
DB_USER="${POSTGRES_USER:=postgres}"
20-
# Check if a custom password has been set, otherwise default to 'password'
21-
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
22-
# Check if a custom database name has been set, otherwise default to 'bdk_wallet'
23-
DB_NAME="${POSTGRES_DB:=bdk_wallet}"
24-
# Check if a custom port has been set, otherwise default to '5432'
25-
DB_PORT="${POSTGRES_PORT:=5432}"
26-
# Check if a custom host has been set, otherwise default to 'localhost'
27-
DB_HOST="${POSTGRES_HOST:=localhost}"
28-
29-
# Allow to skip Docker if a dockerized Postgres database is already running
30-
# if [[ -z "${SKIP_DOCKER}" ]]
31-
# then
32-
# # if a postgres container is running, print instructions to kill it and exit
33-
# RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
34-
# if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
35-
# echo >&2 "there is a postgres container already running, kill it with"
36-
# echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
37-
# exit 1
38-
# fi
39-
# # Launch postgres using Docker
40-
# docker run \
41-
# -e POSTGRES_USER=${DB_USER} \
42-
# -e POSTGRES_PASSWORD=${DB_PASSWORD} \
43-
# -e POSTGRES_DB=${DB_NAME} \
44-
# -p "${DB_PORT}":5432 \
45-
# -d \
46-
# --name "postgres_$(date '+%s')" \
47-
# postgres -N 1000
48-
# # ^ Increased maximum number of connections for testing purposes
49-
# fi
50-
51-
# Keep pinging Postgres until it's ready to accept commands
52-
until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
53-
>&2 echo "Postgres is still unavailable - sleeping"
54-
sleep 1
55-
done
2+
# set -x
3+
# set -eo pipefail
564

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

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

63-
>&2 echo "Completed migration."
18+
# # Check if a custom user has been set, otherwise default to 'postgres'
19+
# DB_USER="${POSTGRES_USER:=postgres}"
20+
# # Check if a custom password has been set, otherwise default to 'password'
21+
# DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
22+
# # Check if a custom database name has been set, otherwise default to 'bdk_wallet'
23+
# DB_NAME="${POSTGRES_DB:=bdk_wallet}"
24+
# # Check if a custom port has been set, otherwise default to '5432'
25+
# DB_PORT="${POSTGRES_PORT:=5432}"
26+
# # Check if a custom host has been set, otherwise default to 'localhost'
27+
# DB_HOST="${POSTGRES_HOST:=localhost}"
28+
29+
# # Allow to skip Docker if a dockerized Postgres database is already running
30+
# # if [[ -z "${SKIP_DOCKER}" ]]
31+
# # then
32+
# # # if a postgres container is running, print instructions to kill it and exit
33+
# # RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
34+
# # if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
35+
# # echo >&2 "there is a postgres container already running, kill it with"
36+
# # echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
37+
# # exit 1
38+
# # fi
39+
# # # Launch postgres using Docker
40+
# # docker run \
41+
# # -e POSTGRES_USER=${DB_USER} \
42+
# # -e POSTGRES_PASSWORD=${DB_PASSWORD} \
43+
# # -e POSTGRES_DB=${DB_NAME} \
44+
# # -p "${DB_PORT}":5432 \
45+
# # -d \
46+
# # --name "postgres_$(date '+%s')" \
47+
# # postgres -N 1000
48+
# # # ^ Increased maximum number of connections for testing purposes
49+
# # fi
50+
51+
# # Keep pinging Postgres until it's ready to accept commands
52+
# until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do
53+
# >&2 echo "Postgres is still unavailable - sleeping"
54+
# sleep 1
55+
# done
56+
57+
# >&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations."
58+
59+
# export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
60+
# sqlx database create
61+
# sqlx migrate run --source ./db/migrations
62+
63+
# >&2 echo "Completed migration."

0 commit comments

Comments
 (0)