Issue: [CI/CD] Add Pre-commit Validation as First Step of Testing Pipeline
Summary
Implement GitHub Actions workflow to run pre-commit validation as the first gate in the CI/CD pipeline, preventing style/lint issues from entering the codebase and ensuring consistency across contributions.
Related: Pre-commit configuration already exists in repository (.pre-commit-config.yaml)
Reference Implementation: FluctuationAnalysisTools repository CI/CD pipeline
Motivation
- Catch code style, formatting, and linting issues before running expensive tests
- Ensure all contributions follow project standards (
black, isort, YAML/JSON validation, etc.)
- Reduce PR review time by automating mechanical checks
- Align with sister project
FluctuationAnalysisTools CI/CD patterns for maintainability
🔧 Technical Requirements
1. Create Reusable Pre-commit Validation Workflow
Create .github/workflows/reusable_pre-commit-validation.yml based on the reference implementation:
# .github/workflows/reusable_pre-commit-validation.yml
name: Reusable - Pre-commit Validation
on:
workflow_call:
outputs:
cache-key:
description: 'The cache key used for pip dependencies'
value: ${{ jobs.pre-commit-validation.outputs.cache-key }}
permissions:
contents: read
jobs:
pre-commit-validation:
runs-on: ubuntu-latest
outputs:
cache-key: ${{ steps.cache-pip.outputs.key || 'pip-precommit-' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11" # Match pyproject.toml requirement
- name: Cache pip dependencies
id: cache-pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-precommit-${{ hashFiles('**/pyproject.toml', '**/.pre-commit-config.yaml') }}
restore-keys: |
pip-precommit-
- name: Install pre-commit
shell: bash
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit validation
shell: bash
run: |
pre-commit run --all-files
2. Update/Create Main CI Workflow
Create or update .github/workflows/test-and-release.yml to use the reusable workflow:
# .github/workflows/test-and-release.yml (skeleton)
name: Test and Release
on:
push:
branches: [master, main]
tags:
- 'release/*'
pull_request:
branches: [master, main]
workflow_dispatch: # Allow manual triggering
permissions:
contents: read
jobs:
# FIRST STEP: Pre-commit validation
pre-commit-validation:
uses: ./.github/workflows/reusable_pre-commit-validation.yml
# Subsequent jobs depend on pre-commit passing
test:
needs: pre-commit-validation
# ... existing test configuration ...
build:
needs: pre-commit-validation
# ... existing build configuration ...
3. Verify Pre-commit Configuration Compatibility
Current .pre-commit-config.yaml uses [[10]]:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0 # Consider updating to v6.0.0 (as in FluctuationAnalysisTools)
- repo: https://github.com/pycqa/isort
rev: 6.0.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.1.0
Recommended updates:
✅ Acceptance Criteria
Implementation Steps
-
Create reusable workflow file:
mkdir -p .github/workflows
touch .github/workflows/reusable_pre-commit-validation.yml
-
Copy/adapt workflow content from FluctuationAnalysisTools reference [[1]]
-
Update main CI workflow to call reusable workflow with needs: dependency
-
Test locally:
# Install pre-commit hooks for local development
pre-commit install
# Run validation manually
pre-commit run --all-files
-
Validate in PR: Create draft PR to trigger GitHub Actions and verify workflow behavior
Testing Strategy
Local Testing
# Install pre-commit
pip install pre-commit
# Install git hooks
pre-commit install
# Test all files
pre-commit run --all-files
# Test specific hook
pre-commit run black --all-files
CI Validation Checklist
References
ℹ️ Note for Contributors:
- This workflow should be non-breaking for existing PRs — consider adding
continue-on-error: true temporarily during rollout if needed.
- Ensure all existing code passes pre-commit hooks before merging this CI change (run
pre-commit run --all-files locally first).
- Coordinate with maintainers before updating hook versions in
.pre-commit-config.yaml to avoid disrupting active development.
- Follow existing repository conventions:
ruff, black, isort configuration in pyproject.toml.
Issue: [CI/CD] Add Pre-commit Validation as First Step of Testing Pipeline
Summary
Implement GitHub Actions workflow to run
pre-commitvalidation as the first gate in the CI/CD pipeline, preventing style/lint issues from entering the codebase and ensuring consistency across contributions.Motivation
black,isort, YAML/JSON validation, etc.)FluctuationAnalysisToolsCI/CD patterns for maintainability🔧 Technical Requirements
1. Create Reusable Pre-commit Validation Workflow
Create
.github/workflows/reusable_pre-commit-validation.ymlbased on the reference implementation:2. Update/Create Main CI Workflow
Create or update
.github/workflows/test-and-release.ymlto use the reusable workflow:3. Verify Pre-commit Configuration Compatibility
Current
.pre-commit-config.yamluses [[10]]:Recommended updates:
pre-commit-hookstov6.0.0for latest security patches [[1]]blacklanguage_versionmatches project Python requirement (currentlypython3.10in bayes_model vspython3in reference)✅ Acceptance Criteria
pull_requestevents (all branches)pushtomaster/mainworkflow_dispatchpyproject.tomlCONTRIBUTION.mdto mention CI pre-commit requirementpre-commit run --all-filesImplementation Steps
Create reusable workflow file:
Copy/adapt workflow content from
FluctuationAnalysisToolsreference [[1]]Update main CI workflow to call reusable workflow with
needs:dependencyTest locally:
Validate in PR: Create draft PR to trigger GitHub Actions and verify workflow behavior
Testing Strategy
Local Testing
CI Validation Checklist
References
FluctuationAnalysisTools/.github/workflows/test-and-release.ymlFluctuationAnalysisTools/.github/workflows/reusable_pre-commit-validation.yml