diff options
-rw-r--r-- | .github/codecov.yml | 13 | ||||
-rw-r--r-- | .github/workflows/check.yaml | 62 | ||||
-rw-r--r-- | .github/workflows/ci.yaml | 187 | ||||
-rw-r--r-- | contrib/bruno/configuration/health-check.bru | 19 | ||||
-rw-r--r-- | contrib/bruno/transaction-monitoring/folder.bru | 2 | ||||
-rw-r--r-- | crates/aggregator/.env.example | 1 | ||||
-rw-r--r-- | crates/aggregator/src/main.rs | 8 | ||||
-rw-r--r-- | crates/configuration/.env.example | 1 | ||||
-rw-r--r-- | crates/configuration/src/main.rs | 8 | ||||
-rw-r--r-- | crates/pseudonyms/.env.example | 1 | ||||
-rw-r--r-- | crates/warden/.env.example | 1 | ||||
-rw-r--r-- | crates/warden/src/main.rs | 8 |
12 files changed, 245 insertions, 66 deletions
diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..a51dfc6 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,13 @@ +# doc: https://docs.codecov.com/docs/codecovyml-reference +coverage: + # range: 85..100 + round: down + precision: 1 + status: + project: + default: + threshold: 1% + +comment: + layout: "files" + require_changes: true diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml deleted file mode 100644 index 7bf14b2..0000000 --- a/.github/workflows/check.yaml +++ /dev/null @@ -1,62 +0,0 @@ -permissions: - contents: read -on: - push: - branches: [master] - pull_request: - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true -name: check -jobs: - dockerfile: - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - crate: - - pseudonyms - - warden - - configuration - - router - - rule-executor - - aggregator - name: dockerfile / ${{ matrix.crate }} - steps: - - uses: actions/checkout@v5 - with: - submodules: true - - name: set up docker buildx - uses: docker/setup-buildx-action@v3 - - name: build # and push - uses: docker/build-push-action@v6 - with: - push: false - context: . - file: crates/${{ matrix.crate }}/Dockerfile - tags: warden/${{ matrix.crate }}:latest - cache-from: type=gha - cache-to: type=gha,mode=max - msrv: - runs-on: ubuntu-latest - strategy: - matrix: - msrv: ["1.89.0"] - name: msrv / ${{ matrix.msrv }} - steps: - - uses: actions/checkout@v5 - with: - submodules: true - - name: Install ${{ matrix.msrv }} - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.msrv }} - - name: install protoc - uses: arduino/setup-protoc@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: cargo install cargo-hack - uses: taiki-e/install-action@cargo-hack - - name: cargo hack +${{ matrix.msrv }} - run: cargo hack --clean-per-run --feature-powerset check diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..5bf2fdb --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,187 @@ +permissions: + contents: read +on: + push: + branches: [master] + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +name: ci + +jobs: + os-check: + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest] + steps: + - uses: actions/checkout@v5 + with: + submodules: true + - name: Install stable + uses: dtolnay/rust-toolchain@stable + - name: Install protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Install cargo-nextest + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest + - uses: Swatinem/rust-cache@v2 + - name: cargo test --workspace + run: cargo nextest run --no-run --workspace --locked --all-features --all-targets + - name: cargo build + run: cargo build --workspace --locked --all-features --all-targets + + dockerfile: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + crate: + - pseudonyms + - warden + - configuration + - router + - rule-executor + - aggregator + name: dockerfile / ${{ matrix.crate }} + steps: + - uses: actions/checkout@v5 + with: + submodules: true + - name: Set up docker buildx + uses: docker/setup-buildx-action@v3 + - name: Build # and push + uses: docker/build-push-action@v6 + with: + push: false + context: . + file: crates/${{ matrix.crate }}/Dockerfile + tags: warden/${{ matrix.crate }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=docker,dest=/tmp/${{ matrix.crate }}.tar + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: warden-${{ matrix.crate }} + path: /tmp/${{ matrix.crate }}.tar + + msrv: + runs-on: ubuntu-latest + strategy: + matrix: + msrv: ["1.89.0"] + name: msrv / ${{ matrix.msrv }} + steps: + - uses: actions/checkout@v5 + with: + submodules: true + - name: Install ${{ matrix.msrv }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.msrv }} + - name: Install protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: cargo install cargo-hack + uses: taiki-e/install-action@cargo-hack + - name: cargo hack +${{ matrix.msrv }} + run: cargo hack --clean-per-run --feature-powerset check + + test: + runs-on: ubuntu-latest + needs: + - dockerfile + - os-check + name: test / workspace + steps: + - uses: actions/checkout@v5 + with: + submodules: true + - name: Start stack + run: docker compose -f contrib/docker-compose/compose.yaml up -d + - name: Setup node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + - name: Download artifacts + uses: actions/download-artifact@v5 + with: + path: warden-images + pattern: warden-* + merge-multiple: true + - name: Load docker images + run: | + dir="warden-images" + for file in "$dir"/*.tar; do + if [ -f "$file" ]; then + echo "Loading tar: $file" + image_name=$(docker load --input "$file" | awk '/Loaded image:/ {print $3}') + echo "Running image: $image_name" + docker run --rm -d --network host "$image_name" + fi + done + echo "images loaded" + docker image ls -a + - name: Install bruno cli + run: npm install -g @usebruno/cli + - name: Run HTTP-api tests + run: | + cd contrib/bruno + bru run configuration/health-check.bru \ + configuration/routing/02-post-routing.bru \ + configuration/rule/01-create.bru \ + configuration/typology/01-create.bru \ + --env warden --reporter-html results.html + - name: Upload test results + uses: actions/upload-artifact@v4 + with: + name: test-results + path: contrib/bruno/results.html + - name: Install stable + uses: dtolnay/rust-toolchain@stable + with: + components: llvm-tools-preview + - uses: taiki-e/install-action@cargo-llvm-cov + - name: Install cargo-nextest + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest + - uses: Swatinem/rust-cache@v2 + - name: Install protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Prepare environment for tests + run: | + for processor in warden pseudonyms aggregator configuration; do + cp crates/$processor/.env.example crates/$processor/.env + done + - name: Collect coverage data + # Generate separate reports for nextest and doctests, and combine them. + run: | + cargo llvm-cov nextest --workspace --locked --all-features --lcov --output-path lcov.info + # switch to nightly + # cargo llvm-cov --no-report nextest + # cargo llvm-cov --no-report --doc + # cargo llvm-cov report --doctests --lcov --output-path lcov.info + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: lcov.info + - name: Stop stack + if: always() + run: | + docker compose -f contrib/docker-compose/compose.yaml down -v + docker stop $(docker ps -aq) || true + docker rm $(docker ps -aq) || true diff --git a/contrib/bruno/configuration/health-check.bru b/contrib/bruno/configuration/health-check.bru new file mode 100644 index 0000000..62f66a9 --- /dev/null +++ b/contrib/bruno/configuration/health-check.bru @@ -0,0 +1,19 @@ +meta { + name: health-check + type: http + seq: 4 +} + +get { + url: {{WARDEN_CFG_HOST}} + body: none + auth: inherit +} + +assert { + res.status: eq 200 +} + +settings { + encodeUrl: true +} diff --git a/contrib/bruno/transaction-monitoring/folder.bru b/contrib/bruno/transaction-monitoring/folder.bru index ca6f740..030714b 100644 --- a/contrib/bruno/transaction-monitoring/folder.bru +++ b/contrib/bruno/transaction-monitoring/folder.bru @@ -1,6 +1,6 @@ meta { name: transaction-monitoring - seq: 2 + seq: 3 } auth { diff --git a/crates/aggregator/.env.example b/crates/aggregator/.env.example new file mode 100644 index 0000000..5178bd5 --- /dev/null +++ b/crates/aggregator/.env.example @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:password@localhost:5432/evaluations diff --git a/crates/aggregator/src/main.rs b/crates/aggregator/src/main.rs index 62af544..7bb5a79 100644 --- a/crates/aggregator/src/main.rs +++ b/crates/aggregator/src/main.rs @@ -4,7 +4,7 @@ mod state; use anyhow::Result; use clap::Parser; -use tracing::error; +use tracing::{error, trace}; use warden_stack::{Configuration, Services, tracing::Tracing}; use crate::state::AppState; @@ -78,6 +78,12 @@ async fn main() -> Result<()> { let state = AppState::create(services, &config).await?; + trace!("running migrations"); + sqlx::migrate!("./migrations") + .run(&state.services.postgres) + .await?; + trace!("migrations updated"); + processor::serve(state, provider).await?; Ok(()) diff --git a/crates/configuration/.env.example b/crates/configuration/.env.example new file mode 100644 index 0000000..9581956 --- /dev/null +++ b/crates/configuration/.env.example @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:password@localhost:5432/configuration diff --git a/crates/configuration/src/main.rs b/crates/configuration/src/main.rs index 7dc8da6..6f90b69 100644 --- a/crates/configuration/src/main.rs +++ b/crates/configuration/src/main.rs @@ -8,7 +8,7 @@ use crate::{server::error::AppError, state::AppState}; use axum::http::header::CONTENT_TYPE; use clap::Parser; use tower::{make::Shared, steer::Steer}; -use tracing::{error, info}; +use tracing::{error, info, trace}; use warden_stack::{Configuration, Services, tracing::Tracing}; /// warden-config @@ -82,6 +82,12 @@ async fn main() -> Result<(), AppError> { ) .await?; + trace!("running migrations"); + sqlx::migrate!("./migrations") + .run(&state.services.postgres) + .await?; + trace!("migrations updated"); + let (app, grpc_server) = server::serve(state)?; let service = Steer::new( diff --git a/crates/pseudonyms/.env.example b/crates/pseudonyms/.env.example new file mode 100644 index 0000000..3728d42 --- /dev/null +++ b/crates/pseudonyms/.env.example @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:password@localhost:5432/pseudonyms diff --git a/crates/warden/.env.example b/crates/warden/.env.example new file mode 100644 index 0000000..6caf00a --- /dev/null +++ b/crates/warden/.env.example @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:password@localhost:5432/transaction_history diff --git a/crates/warden/src/main.rs b/crates/warden/src/main.rs index 9e33700..90fedfd 100644 --- a/crates/warden/src/main.rs +++ b/crates/warden/src/main.rs @@ -7,7 +7,7 @@ mod version; use std::net::{Ipv6Addr, SocketAddr}; use clap::{Parser, command}; -use tracing::{error, info}; +use tracing::{error, info, trace}; use warden_stack::{Configuration, Services, tracing::Tracing}; use crate::state::AppState; @@ -79,6 +79,12 @@ async fn main() -> Result<(), error::AppError> { let state = AppState::create(services, &config).await?; + trace!("running migrations"); + sqlx::migrate!("./migrations") + .run(&state.services.postgres) + .await?; + trace!("migrations updated"); + let addr = SocketAddr::from((Ipv6Addr::UNSPECIFIED, config.application.port)); let listener = tokio::net::TcpListener::bind(addr).await?; |