mirror of
https://github.com/BillyOutlast/posthog.git
synced 2026-02-04 03:01:23 +01:00
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
308 lines
12 KiB
YAML
308 lines
12 KiB
YAML
name: Rust CI
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [master, main]
|
|
pull_request:
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
# Job to decide if we should run rust ci
|
|
# See https://github.com/dorny/paths-filter#conditional-execution for more details
|
|
changes:
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 5
|
|
if: github.repository == 'PostHog/posthog'
|
|
name: Determine need to run Rust checks
|
|
# Set job outputs to values from filter step
|
|
outputs:
|
|
rust: ${{ steps.filter.outputs.rust }}
|
|
steps:
|
|
# For pull requests it's not necessary to checkout the code, but we
|
|
# also want this to run on master so we need to checkout
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
clean: false
|
|
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2
|
|
id: filter
|
|
with:
|
|
filters: |
|
|
rust:
|
|
# Avoid running rust tests for irrelevant changes
|
|
- 'rust/**'
|
|
- '.github/workflows/ci-rust.yml'
|
|
- '.github/workflows/rust.yml'
|
|
- '.github/workflows/rust-docker-build.yml'
|
|
- 'posthog/management/commands/setup_test_environment.py'
|
|
- 'posthog/migrations/**'
|
|
- 'ee/migrations/**'
|
|
- 'docker-compose.dev.yml'
|
|
|
|
build:
|
|
name: Build Rust services
|
|
needs: changes
|
|
runs-on: depot-ubuntu-22.04-4
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: rust
|
|
|
|
steps:
|
|
# Checkout project code
|
|
# Use sparse checkout to only select files in rust directory
|
|
# Turning off cone mode ensures that files in the project root are not included during checkout
|
|
- uses: actions/checkout@v4
|
|
if: needs.changes.outputs.rust == 'true'
|
|
with:
|
|
sparse-checkout: 'rust/'
|
|
sparse-checkout-cone-mode: false
|
|
clean: false
|
|
|
|
- name: Install rust
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: dtolnay/rust-toolchain@6691ebadcb18182cc1391d07c9f295f657c593cd # 1.88
|
|
|
|
- name: Install sccache
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
|
|
|
|
- name: Configure sccache
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
|
sccache --start-server
|
|
|
|
- name: Run cargo build
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: cargo build --all --locked --release && find target/release/ -maxdepth 1 -executable -type f | xargs strip
|
|
|
|
test:
|
|
name: Test Rust services
|
|
strategy:
|
|
matrix:
|
|
package:
|
|
- batch-import-worker
|
|
- capture
|
|
- capture-logs
|
|
- common-alloc
|
|
- common-cookieless
|
|
- common-compression
|
|
- common-database
|
|
- common-dns
|
|
- common-geoip
|
|
- common-hypercache
|
|
- common-metrics
|
|
- common-kafka
|
|
- common-profiler
|
|
- common-s3
|
|
- cyclotron-core
|
|
- cyclotron-node
|
|
- cyclotron-janitor
|
|
- cymbal
|
|
- embedding-worker
|
|
- feature-flags
|
|
- health
|
|
- hogvm
|
|
- hook-api
|
|
- hook-common
|
|
- hook-janitor
|
|
- hook-worker
|
|
- kafka-deduplicator
|
|
- limiters
|
|
- posthog-symbol-data
|
|
- property-defs-rs
|
|
- serve-metrics
|
|
needs: changes
|
|
runs-on: depot-ubuntu-24.04-4
|
|
timeout-minutes: 20
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: rust
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
if: needs.changes.outputs.rust == 'true'
|
|
with:
|
|
clean: false
|
|
- name: Clean up data directories with container permissions
|
|
if: needs.changes.outputs.rust == 'true'
|
|
working-directory: .
|
|
run: |
|
|
# Use docker to clean up files created by containers (from repo root, not rust/)
|
|
[ -d "data" ] && docker run --rm -v "$(pwd)/data:/data" alpine sh -c "rm -rf /data/seaweedfs /data/minio" || true
|
|
continue-on-error: true
|
|
|
|
- name: Setup main repo and dependencies
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
docker compose -f ../docker-compose.dev.yml down
|
|
docker compose -f ../docker-compose.dev.yml up -d
|
|
echo "127.0.0.1 kafka clickhouse" | sudo tee -a /etc/hosts
|
|
|
|
- name: Dump Kafka logs on failure
|
|
if: failure()
|
|
run: |
|
|
docker ps -a || true
|
|
docker logs --tail=500 rust-kafka-1 || true
|
|
docker inspect rust-kafka-1 || true
|
|
|
|
# please keep the tag version here in sync with rust-version in rust/*/Cargo.toml
|
|
- name: Install rust
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: dtolnay/rust-toolchain@6691ebadcb18182cc1391d07c9f295f657c593cd # 1.88
|
|
|
|
- name: Install sccache
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
|
|
|
|
- name: Configure sccache
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
|
sccache --start-server
|
|
|
|
- name: Set up Python
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version-file: 'pyproject.toml'
|
|
|
|
- name: Install uv
|
|
id: setup-uv
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: astral-sh/setup-uv@3259c6206f993105e3a61b142c2d97bf4b9ef83d # v7.1.0
|
|
with:
|
|
enable-cache: true
|
|
version: 0.8.19
|
|
|
|
- name: Install SAML (python3-saml) dependencies
|
|
if: needs.changes.outputs.rust == 'true' && steps.setup-uv.outputs.cache-hit != 'true'
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl postgresql-client
|
|
|
|
- name: Install python dependencies
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
UV_PROJECT_ENVIRONMENT=$pythonLocation uv sync --frozen --dev --directory ..
|
|
|
|
- name: Install sqlx-cli
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
cargo install sqlx-cli --version 0.8.0 --features postgres --no-default-features --locked
|
|
|
|
- name: Set up databases
|
|
if: needs.changes.outputs.rust == 'true'
|
|
env:
|
|
DEBUG: 'true'
|
|
TEST: 'true'
|
|
SECRET_KEY: 'abcdef' # unsafe - for testing only
|
|
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog'
|
|
run: cd ../ && python manage.py setup_test_environment
|
|
|
|
- name: Run sqlx migrations
|
|
if: needs.changes.outputs.rust == 'true'
|
|
env:
|
|
DATABASE_URL: 'postgres://posthog:posthog@localhost:5432/posthog_persons'
|
|
run: |
|
|
sqlx migrate run --source persons_migrations/
|
|
|
|
- name: Download MaxMind Database
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
cd ../ && ./bin/download-mmdb
|
|
|
|
- name: Run cargo test
|
|
if: needs.changes.outputs.rust == 'true'
|
|
env:
|
|
RUST_BACKTRACE: 1
|
|
# Set up dual database environment for feature-flags service
|
|
PERSONS_READ_DATABASE_URL: ${{ matrix.package == 'feature-flags' && 'postgres://posthog:posthog@localhost:5432/posthog_persons' || '' }}
|
|
PERSONS_WRITE_DATABASE_URL: ${{ matrix.package == 'feature-flags' && 'postgres://posthog:posthog@localhost:5432/posthog_persons' || '' }}
|
|
run: |
|
|
echo "Starting cargo test"
|
|
cargo test -p ${{matrix.package}}
|
|
echo "Cargo test completed"
|
|
|
|
linting:
|
|
name: Lint Rust services
|
|
needs: changes
|
|
runs-on: depot-ubuntu-22.04-4
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: rust
|
|
|
|
steps:
|
|
# Checkout project code
|
|
# Use sparse checkout to only select files in rust directory
|
|
# Turning off cone mode ensures that files in the project root are not included during checkout
|
|
- uses: actions/checkout@v4
|
|
if: needs.changes.outputs.rust == 'true'
|
|
with:
|
|
sparse-checkout: 'rust/'
|
|
sparse-checkout-cone-mode: false
|
|
clean: false
|
|
|
|
- name: Install rust
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: dtolnay/rust-toolchain@6691ebadcb18182cc1391d07c9f295f657c593cd # 1.88
|
|
with:
|
|
components: clippy,rustfmt
|
|
|
|
- name: Install sccache
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9
|
|
|
|
- name: Configure sccache
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: |
|
|
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
|
|
sccache --start-server
|
|
|
|
- name: Check format
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: cargo fmt -- --check
|
|
|
|
- name: Run clippy
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: cargo clippy --all-targets --all-features -- -D warnings
|
|
|
|
- name: Run cargo check
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: cargo check --all-features
|
|
|
|
shear:
|
|
name: Shear Rust services
|
|
needs: changes
|
|
runs-on: depot-ubuntu-22.04-4
|
|
|
|
defaults:
|
|
run:
|
|
working-directory: rust
|
|
|
|
steps:
|
|
# Checkout project code
|
|
# Use sparse checkout to only select files in rust directory
|
|
# Turning off cone mode ensures that files in the project root are not included during checkout
|
|
- uses: actions/checkout@v4
|
|
if: needs.changes.outputs.rust == 'true'
|
|
with:
|
|
sparse-checkout: 'rust/'
|
|
sparse-checkout-cone-mode: false
|
|
clean: false
|
|
|
|
- name: Install cargo-binstall
|
|
if: needs.changes.outputs.rust == 'true'
|
|
uses: cargo-bins/cargo-binstall@5cbf019d8cb9b9d5b086218c41458ea35d817691 # main
|
|
|
|
- name: Install cargo-shear
|
|
if: needs.changes.outputs.rust == 'true'
|
|
run: cargo binstall --no-confirm cargo-shear@1.1.12
|
|
|
|
- run: cargo shear
|
|
if: needs.changes.outputs.rust == 'true'
|