Skip to content

Commit

Permalink
chore: setup ci for testing with docker compose (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwkang1998 authored Jan 15, 2025
1 parent 90f6daa commit 90fab8a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 39 deletions.
88 changes: 49 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,65 @@ on:
- sepolia-db

jobs:
rust-ci:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: Swatinem/rust-cache@v2

- name: Check code formatting
run: cargo fmt -- --check

clippy:
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- uses: Swatinem/rust-cache@v2

- name: Cache Cargo index
uses: actions/cache@v3
with:
path: ~/.cargo/index
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-index-
- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Cache Cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
build:
needs: [fmt, clippy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
override: true
- uses: Swatinem/rust-cache@v2

- name: Install dependencies
run: cargo fetch
- name: Build
run: cargo build

- name: Check code formatting
run: cargo fmt -- --check
tests:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- uses: Swatinem/rust-cache@v2

- name: Build the project
run: cargo build --verbose
- name: Setup test env
uses: hoverkraft-tech/[email protected]
with:
compose-file: "./docker-compose.test.yml"

- name: Install required tools
run: cargo install cargo-llvm-cov

- run: chmod +x scripts/run-coverage.sh

- name: Run tests
run: cargo test --all --verbose
run: scripts/run-coverage.sh

- uses: hrishikesh-kadam/setup-lcov@v1
with:
ref: v2.2

- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v4
with:
coverage-files: lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
update-comment: true
6 changes: 6 additions & 0 deletions scripts/run-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export TEST_DB_CONNECTION_STRING="postgresql://postgres:postgres@localhost:5433/fossil_test"

# Run tests with coverage using cargo-llvm-cov.
# Note that you will have to install the tarpaulin binary via cargo install cargo-llvm-cov.
cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

File renamed without changes.
4 changes: 4 additions & 0 deletions scripts/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export TEST_DB_CONNECTION_STRING="postgresql://postgres:postgres@localhost:5433/fossil_test"

# Run tests
cargo test
File renamed without changes.

0 comments on commit 90fab8a

Please sign in to comment.