Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
77 changes: 58 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jobs:
ports:
- 5432:5432

env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
TEST_MODE: "1"

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -87,42 +91,77 @@ jobs:
restore-keys: |
${{ runner.os }}-cargo-

- name: Run migrations
- name: Cache sqlx-data
uses: actions/cache@v3
with:
path: backend/.sqlx
key: ${{ runner.os }}-sqlx-${{ hashFiles('backend/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-sqlx-

- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features postgres,rustls

- name: List migrations folder (debug)
working-directory: backend
run: |
echo "Checking migrations folder:"
ls -lah migrations/ || echo "❌ No migrations folder found"
echo "Migration files:"
ls -lah migrations/*.sql || echo "❌ No .sql files found"

- name: Wait for Postgres
run: |
until pg_isready -h localhost -p 5432 -U postgres; do
echo "Waiting for Postgres..."
sleep 2
done

- name: Reset and run migrations
working-directory: backend
run: |
cd backend
cargo install sqlx-cli --no-default-features --features postgres,native-tls --locked
echo "Reverting all migrations..."
while sqlx migrate revert -y 2>/dev/null; do
echo "Reverted one migration"
done
echo "Running migrations..."
sqlx migrate run
echo "Migrations completed"
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
SQLX_OFFLINE: "false"

- name: Install dependencies
- name: Verify tables exist
run: |
cd backend
cargo build
echo "Listing all tables in database:"
PGPASSWORD=postgres psql -h localhost -U postgres -d guild_genesis_test -c "\dt"
echo "Checking profiles table schema:"
PGPASSWORD=postgres psql -h localhost -U postgres -d guild_genesis_test -c "\d profiles"

- name: Build backend
working-directory: backend
run: cargo build
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
SQLX_OFFLINE: true

- name: Run clippy
run: |
cd backend
cargo clippy --all-targets --all-features -- -D warnings
working-directory: backend
run: cargo clippy --all-targets --all-features -- -D warnings
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
SQLX_OFFLINE: true

- name: Run rustfmt
run: |
cd backend
cargo fmt --all -- --check
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
working-directory: backend
run: cargo fmt --all -- --check

- name: Run tests
run: |
cd backend
cargo test
working-directory: backend
run: cargo test --test integration_github_handle -- --test-threads=1
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
SQLX_OFFLINE: true
TEST_MODE: "1"

smart-contracts:
name: Smart Contracts Tests
Expand Down
101 changes: 101 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Rust CI

on:
push:
branches: [main, dev]
pull_request:

jobs:
backend_tests:
name: Backend Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: guild_genesis_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5

env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
TEST_MODE: "1"

steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Cache sqlx-data
uses: actions/cache@v3
with:
path: backend/.sqlx
key: ${{ runner.os }}-sqlx-${{ hashFiles('backend/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-sqlx-

- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features postgres,rustls

- name: List migrations folder (debug)
working-directory: backend
run: |
echo "Checking migrations folder:"
ls -lah migrations/ || echo "❌ No migrations folder found"
echo "Migration files:"
ls -lah migrations/*.sql || echo "❌ No .sql files found"

- name: Wait for Postgres
run: |
until pg_isready -h localhost -p 5432 -U postgres; do
echo "Waiting for Postgres..."
sleep 2
done

- name: Reset and run migrations
working-directory: backend
run: |
echo "Reverting all migrations..."
while sqlx migrate revert -y 2>/dev/null; do
echo "Reverted one migration"
done
echo "Running migrations..."
sqlx migrate run
echo "Migrations completed"
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
SQLX_OFFLINE: "false"

- name: Verify tables exist
run: |
echo "Listing all tables in database:"
PGPASSWORD=postgres psql -h localhost -U postgres -d guild_genesis_test -c "\dt"
echo "Checking profiles table schema:"
PGPASSWORD=postgres psql -h localhost -U postgres -d guild_genesis_test -c "\d profiles"

- name: Run tests
working-directory: backend
run: cargo test -- --nocapture
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/guild_genesis_test
SQLX_OFFLINE: true
TEST_MODE: "1"
7 changes: 7 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Database URL for local dev or test DB (adjust user/password/db as needed)
DATABASE_URL=postgres://guild_user:guild_password@localhost:5432/guild_genesis

# Optional: allow SQLx offline mode when building
# SQLX_OFFLINE=true

# Other env vars your app uses...

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading