Skip to content

Commit

Permalink
Add paths filter for conditional CI on detected changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarflakstad committed Jun 25, 2024
1 parent 4e02f4c commit ae3fb95
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/actions/toolchain-cargo-cached/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- id: toolchain-cache-key
run: |
Expand Down
72 changes: 72 additions & 0 deletions .github/file-filters.yaml
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Python CI

name: Agency CI
on:
push:
workflow_call:

defaults:
run:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 0 additions & 41 deletions .github/workflows/rust.yaml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/server.yaml
Original file line number Diff line number Diff line change
@@ -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 --

0 comments on commit ae3fb95

Please sign in to comment.