Skip to content

Add path filters to workflows to prevent unnecessary CI runs #30

@RAprogramm

Description

@RAprogramm

Add path filters to all workflows to run them only when relevant files change.

Problem

Currently all workflows run on EVERY push/PR, even when only documentation or workflow files change. This wastes CI resources and time.

Example: Changing .github/workflows/miri.yml triggers:

  • Full CI (format, clippy, tests, coverage, benchmarks)
  • Benchmark workflow
  • All other workflows

This is illogical and inefficient.

Solution

Add path filters to workflows:

ci.yml - Run only when code changes

on:
  push:
    branches: [main]
    paths:
      - 'src/**'
      - 'tests/**'
      - 'benches/**'
      - 'examples/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.rustfmt.toml'
      - '.github/workflows/ci.yml'
  pull_request:
    branches: [main]
    paths:
      - 'src/**'
      - 'tests/**'
      - 'benches/**'
      - 'examples/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.rustfmt.toml'
      - '.github/workflows/ci.yml'

benchmark.yml - Run only when code or benchmarks change

on:
  push:
    branches: [main]
    paths:
      - 'src/**'
      - 'benches/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.github/workflows/benchmark.yml'
  workflow_dispatch:

miri.yml - Run only when code changes

on:
  push:
    branches: [main]
    paths:
      - 'src/**'
      - 'tests/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.github/workflows/miri.yml'
  pull_request:
    branches: [main]
    paths:
      - 'src/**'
      - 'tests/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.github/workflows/miri.yml'
  schedule:
    - cron: '0 3 * * 1'

codeql.yml - Run only when code changes

on:
  push:
    branches: [main]
    paths:
      - 'src/**'
      - 'tests/**'
      - 'Cargo.toml'
      - '.github/workflows/codeql.yml'
  pull_request:
    branches: [main]
    paths:
      - 'src/**'
      - 'tests/**'
      - 'Cargo.toml'
      - '.github/workflows/codeql.yml'
  schedule:
    - cron: '0 0 * * 1'

release.yml - No changes needed

Already runs only on tags (v*..)

Benefits

  • Saves CI minutes (no unnecessary runs)
  • Faster workflow execution (no queuing)
  • Logical workflow triggers
  • Better resource utilization
  • Professional CI/CD setup

Edge Cases

  • workflow_dispatch still allows manual runs
  • schedule triggers remain unchanged
  • Each workflow includes its own .yml file in paths to run when workflow itself changes

Success Criteria

  • All workflows have appropriate path filters
  • README/docs changes do not trigger CI
  • Workflow changes trigger only that specific workflow
  • Code changes trigger all relevant workflows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions