diff --git a/.github/actions/toolchain-cargo-cached/action.yml b/.github/actions/toolchain-cargo-cached/action.yml index ec175954..ea57be66 100644 --- a/.github/actions/toolchain-cargo-cached/action.yml +++ b/.github/actions/toolchain-cargo-cached/action.yml @@ -26,7 +26,7 @@ runs: using: 'composite' steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - id: toolchain-cache-key run: | diff --git a/.github/file-filters.yaml b/.github/file-filters.yaml new file mode 100644 index 00000000..80430239 --- /dev/null +++ b/.github/file-filters.yaml @@ -0,0 +1,72 @@ +# This is used by the action https://github.com/dorny/paths-filter + +# Changes to actions/workflows that can affect any of our project components. +action_changes: &action_changes + - '.github/actions/**/action.yaml' + - '.github/workflows/ci.yaml' + - '.github/file-filters.yaml' + +# Frontend +frontend_dependencies: &frontend_dependencies + - 'frontend/{package,now,vercel}.json' + - 'frontend/package-lock.json' + +eslint_config: &eslint_config + - 'frontend/.eslint*' + +frontend_workflow: &frontend_workflow + - '.github/workflows/frontend.yaml' + +frontend: &frontend + - *action_changes + - *frontend_dependencies + - *frontend_workflow + - *eslint_config + - 'frontend/**/*.[tj]{s,sx}' + - 'frontend/**/tsconfig*.json' + +proto: &proto + - 'proto/*.proto' + +# Agency +agency_dependencies: &agency_dependencies + - 'agency/pyproject.toml' + - 'agency/poetry.lock' + - 'agency/.python-version' + +agency_workflow: &agency_workflow + - '.github/workflows/agency.yaml' + +agency: &agency + - *action_changes + - *agency_dependencies + - *agency_workflow + - *proto + - 'agency/app/**/*.py' + +# Server +server_dependencies: &server_dependencies + - 'Cargo.toml' + - 'Cargo.lock' + - 'rust-toolchain.toml' + +server_workflow: &server_workflow + - '.github/workflows/server.yaml' + +server_migrations: &server_migrations + - 'server/migrations/**.sql' + +sqlx_query_cache: &sqlx_query_cache + - 'server/.sqlx/**.json' + +server_config: &server_config + - 'server/config/**.toml' + +server: &server + - *action_changes + - *server_dependencies + - *server_workflow + - *server_migrations + - *sqlx_query_cache + - *proto + - 'server/src/**/*.rs' \ No newline at end of file diff --git a/.github/workflows/python.yaml b/.github/workflows/agency.yaml similarity index 94% rename from .github/workflows/python.yaml rename to .github/workflows/agency.yaml index 86a8db49..ae29f05f 100644 --- a/.github/workflows/python.yaml +++ b/.github/workflows/agency.yaml @@ -1,7 +1,6 @@ -name: Python CI - +name: Agency CI on: - push: + workflow_call: defaults: run: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..0b600d01 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,43 @@ +name: CI + +on: push + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + RUST_BACKTRACE: short + RUSTFLAGS: "-D warnings" + RUSTUP_MAX_RETRIES: 10 + +jobs: + detect-changes: + name: Detect which files have changed + runs-on: ubuntu-latest + timeout-minutes: 3 + # Map a step output to a job output + outputs: + agency: ${{ steps.changes.outputs.agency }} + frontend: ${{ steps.changes.outputs.frontend }} + llmlingua_service: ${{ steps.changes.outputs.llmlingua_service }} + proto: ${{ steps.changes.outputs.proto }} + server: ${{ steps.changes.outputs.server }} + steps: + - uses: actions/checkout@v4 + + - name: Find changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yaml + + agency: + if: needs.detect-changes.outputs.agency == 'true' + needs: detect-changes + uses: ./.github/workflows/agency.yaml + + server: + if: needs.detect-changes.outputs.server == 'true' + needs: detect-changes + uses: ./.github/workflows/server.yaml \ No newline at end of file diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml deleted file mode 100644 index 79fd6ce2..00000000 --- a/.github/workflows/rust.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: Rust CI - -on: push - -defaults: - run: - working-directory: server - -env: - CARGO_TERM_COLOR: always - CARGO_INCREMENTAL: 0 - CARGO_NET_RETRY: 10 - RUST_BACKTRACE: short - RUSTFLAGS: "-D warnings" - RUSTUP_MAX_RETRIES: 10 - -jobs: - coverage-and-linting: - name: Test coverage & linting - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Protoc - uses: arduino/setup-protoc@v3 - - - name: Setup Rust Toolchain - uses: ./.github/actions/toolchain-cargo-cached - with: - components: llvm-tools-preview, rustfmt, clippy - crates: cargo-llvm-cov - - - name: Tests & coverage - run: cargo llvm-cov test --no-fail-fast --workspace - - - name: Linting rustfmt - run: cargo fmt --all -- --check - - - name: Linting clippy - run: cargo clippy -- \ No newline at end of file diff --git a/.github/workflows/server.yaml b/.github/workflows/server.yaml new file mode 100644 index 00000000..05c3980c --- /dev/null +++ b/.github/workflows/server.yaml @@ -0,0 +1,75 @@ +name: Rust Server CI +on: + workflow_call: + +defaults: + run: + working-directory: server + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + RUST_BACKTRACE: short + RUSTFLAGS: "-D warnings" + RUSTUP_MAX_RETRIES: 10 + +jobs: + detect-changes: + name: Detect which files have changed + runs-on: ubuntu-latest + timeout-minutes: 3 + # Map a step output to a job output + outputs: + agency: ${{ steps.changes.outputs.agency }} + frontend: ${{ steps.changes.outputs.frontend }} + llmlingua_service: ${{ steps.changes.outputs.llmlingua_service }} + proto: ${{ steps.changes.outputs.proto }} + server: ${{ steps.changes.outputs.server }} + steps: + - uses: actions/checkout@v4 + + - name: Find changes + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v2 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + + coverage-and-linting: + name: Test coverage & linting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: dorny/paths-filter@v3 + id: changes + with: + filters: | + src: + - 'src/**' + + # run only if some file in 'src' folder was changed + - if: steps.changes.outputs.src == 'true' + run: ... + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Rust Toolchain + uses: ./.github/actions/toolchain-cargo-cached + with: + components: llvm-tools-preview, rustfmt, clippy + crates: cargo-llvm-cov + + - name: Tests & coverage + run: cargo llvm-cov test --no-fail-fast --workspace + + - name: Linting rustfmt + run: cargo fmt --all -- --check + + - name: Linting clippy + run: cargo clippy -- \ No newline at end of file