diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4336739..c15d0c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/compose-action@v2.0.2 + 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 diff --git a/scripts/run-coverage.sh b/scripts/run-coverage.sh new file mode 100755 index 0000000..c6e8d82 --- /dev/null +++ b/scripts/run-coverage.sh @@ -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 + diff --git a/run-migrations.sh b/scripts/run-migrations.sh similarity index 100% rename from run-migrations.sh rename to scripts/run-migrations.sh diff --git a/scripts/run-test.sh b/scripts/run-test.sh new file mode 100644 index 0000000..2aa84bd --- /dev/null +++ b/scripts/run-test.sh @@ -0,0 +1,4 @@ +export TEST_DB_CONNECTION_STRING="postgresql://postgres:postgres@localhost:5433/fossil_test" + +# Run tests +cargo test \ No newline at end of file diff --git a/run.sh b/scripts/run.sh similarity index 100% rename from run.sh rename to scripts/run.sh