fix: Messages save user ID & chat tweaks (#742) #1119
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: [opened, synchronize, reopened] | |
branches: | |
- main | |
env: | |
CARGO_TERM_COLOR: always | |
SQLX_VERSION: 0.8.0 | |
SQLX_FEATURES: "rustls,postgres" | |
APP_USER: app | |
APP_USER_PWD: secret | |
APP_DB_NAME: newsletter | |
jobs: | |
backend: | |
name: Backend | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: backend | |
env: | |
AIDER_API_KEY: ${{ secrets.AIDER_API_KEY }} | |
DATABASE_URL: "postgres://postgres:password@localhost:5432/openagents_test" | |
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} | |
GITHUB_CLIENT_ID: ${{ secrets.OAUTH_GITHUB_CLIENT_ID }} | |
GITHUB_CLIENT_SECRET: ${{ secrets.OAUTH_GITHUB_CLIENT_SECRET }} | |
GITHUB_TOKEN: ${{ github.token }} | |
OIDC_CLIENT_ID: ${{ secrets.OIDC_CLIENT_ID }} | |
OIDC_CLIENT_SECRET: ${{ secrets.OIDC_CLIENT_SECRET }} | |
OIDC_AUTH_URL: ${{ secrets.OIDC_AUTH_URL }} | |
OIDC_TOKEN_URL: ${{ secrets.OIDC_TOKEN_URL }} | |
OIDC_REDIRECT_URI: ${{ secrets.OIDC_REDIRECT_URI }} | |
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} | |
services: | |
postgres: | |
image: postgres:14 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: password | |
POSTGRES_DB: postgres | |
ports: | |
- 5432:5432 | |
redis: | |
image: redis:7 | |
ports: | |
- 6379:6379 | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install the Rust toolchain | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
- name: Install sqlx-cli | |
run: cargo install sqlx-cli | |
--version=${{ env.SQLX_VERSION }} | |
--features ${{ env.SQLX_FEATURES }} | |
--no-default-features | |
--locked | |
- name: Create app user in Postgres | |
run: | | |
sudo apt-get install postgresql-client | |
# Create the application user | |
CREATE_QUERY="CREATE USER ${APP_USER} WITH PASSWORD '${APP_USER_PWD}';" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "${CREATE_QUERY}" | |
# Grant create db privileges to the app user | |
GRANT_QUERY="ALTER USER ${APP_USER} CREATEDB;" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "${GRANT_QUERY}" | |
- name: Create test database | |
run: | | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "CREATE DATABASE openagents_test;" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "GRANT ALL PRIVILEGES ON DATABASE openagents_test TO ${APP_USER};" | |
- name: Setup configuration | |
run: | | |
mkdir -p configuration | |
echo "application: | |
port: 8080 | |
host: 0.0.0.0 | |
admin_token: admin-token | |
environment: production" > configuration/base.yaml | |
echo "application: | |
host: 0.0.0.0 | |
admin_token: admin-token | |
database: | |
require_ssl: false | |
environment: production" > configuration/production.yaml | |
echo "application: | |
host: 0.0.0.0 | |
admin_token: admin-token | |
database: | |
require_ssl: false | |
environment: production" > configuration/local.yaml | |
- name: Run SQLx migrations | |
run: | | |
cargo sqlx database create | |
cargo sqlx migrate run | |
- name: Run tests | |
env: | |
APP_ENVIRONMENT: "production" | |
RUST_TEST_THREADS: "1" | |
run: | | |
# Set environment variable in a way that persists for child processes | |
echo "APP_ENVIRONMENT=production" >> $GITHUB_ENV | |
# Verify environment setting | |
echo "APP_ENVIRONMENT=$APP_ENVIRONMENT" | |
# Run tests with environment tracing | |
RUST_LOG=debug cargo test --features local-tests -- --nocapture | |
- name: Check that queries are fresh | |
env: | |
APP_ENVIRONMENT: "production" | |
run: | | |
echo "Current directory contents:" | |
ls -la | |
echo "Checking for .sqlx directory:" | |
ls -la .sqlx || true | |
cargo sqlx prepare --workspace --check | |
frontend: | |
name: Frontend | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: frontend | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Install pnpm | |
run: npm install -g pnpm | |
- name: Install dependencies | |
run: pnpm install --no-frozen-lockfile | |
- name: Type check | |
run: pnpm run typecheck | |
- name: Build | |
run: pnpm run build | |
fmt: | |
name: Rustfmt | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: backend | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install the Rust toolchain | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
components: rustfmt | |
- name: Enforce formatting | |
run: cargo fmt --check | |
clippy: | |
name: Clippy | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: backend | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install the Rust toolchain | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
components: clippy | |
- name: Linting | |
run: cargo clippy -- -D warnings | |
coverage: | |
name: Code coverage | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: backend | |
env: | |
APP_ENVIRONMENT: "production" | |
AIDER_API_KEY: ${{ secrets.AIDER_API_KEY }} | |
DATABASE_URL: "postgres://postgres:password@localhost:5432/openagents_test" | |
DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} | |
GITHUB_CLIENT_ID: ${{ secrets.OAUTH_GITHUB_CLIENT_ID }} | |
GITHUB_CLIENT_SECRET: ${{ secrets.OAUTH_GITHUB_CLIENT_SECRET }} | |
GITHUB_TOKEN: ${{ github.token }} | |
OIDC_CLIENT_ID: ${{ secrets.OIDC_CLIENT_ID }} | |
OIDC_CLIENT_SECRET: ${{ secrets.OIDC_CLIENT_SECRET }} | |
OIDC_AUTH_URL: ${{ secrets.OIDC_AUTH_URL }} | |
OIDC_TOKEN_URL: ${{ secrets.OIDC_TOKEN_URL }} | |
OIDC_REDIRECT_URI: ${{ secrets.OIDC_REDIRECT_URI }} | |
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} | |
services: | |
postgres: | |
image: postgres:14 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: password | |
POSTGRES_DB: postgres | |
ports: | |
- 5432:5432 | |
redis: | |
image: redis:7 | |
ports: | |
- 6379:6379 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install the Rust toolchain | |
uses: actions-rust-lang/setup-rust-toolchain@v1 | |
with: | |
components: llvm-tools-preview | |
- name: Install sqlx-cli | |
run: cargo install sqlx-cli | |
--version=${{ env.SQLX_VERSION }} | |
--features ${{ env.SQLX_FEATURES }} | |
--no-default-features | |
--locked | |
- name: Create app user in Postgres | |
run: | | |
sudo apt-get install postgresql-client | |
# Create the application user | |
CREATE_QUERY="CREATE USER ${APP_USER} WITH PASSWORD '${APP_USER_PWD}';" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "${CREATE_QUERY}" | |
# Grant create db privileges to the app user | |
GRANT_QUERY="ALTER USER ${APP_USER} CREATEDB;" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "${GRANT_QUERY}" | |
- name: Create test database | |
run: | | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "CREATE DATABASE openagents_test;" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "GRANT ALL PRIVILEGES ON DATABASE openagents_test TO ${APP_USER};" | |
- name: Setup configuration | |
run: | | |
mkdir -p configuration | |
echo "application: | |
port: 8080 | |
host: 0.0.0.0 | |
admin_token: admin-token | |
environment: production" > configuration/base.yaml | |
echo "application: | |
host: 0.0.0.0 | |
admin_token: admin-token | |
database: | |
require_ssl: false | |
environment: production" > configuration/production.yaml | |
echo "application: | |
host: 0.0.0.0 | |
admin_token: admin-token | |
database: | |
require_ssl: false | |
environment: production" > configuration/local.yaml | |
- name: Run SQLx migrations | |
run: | | |
cargo sqlx database create | |
cargo sqlx migrate run | |
- name: Install cargo-llvm-cov | |
uses: taiki-e/install-action@cargo-llvm-cov | |
- name: Generate code coverage | |
env: | |
APP_ENVIRONMENT: "production" | |
RUST_TEST_THREADS: "1" | |
run: | | |
echo "APP_ENVIRONMENT=production" >> $GITHUB_ENV | |
echo "APP_ENVIRONMENT=$APP_ENVIRONMENT" | |
RUST_LOG=debug cargo llvm-cov --features local-tests --all-features --workspace --lcov --output-path lcov.info | |
- name: Generate report | |
run: cargo llvm-cov report --html --output-dir coverage | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: "Coverage report" | |
path: coverage/ |