Feature/covid analysis #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run Pre-commit Hooks | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code and fetch all branches | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Ensure the full history is fetched, not just the last commit | |
# Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.11 | |
# Install dependencies and pre-commit hooks | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pre-commit | |
# Fetch the main branch to ensure it's available for comparison | |
- name: Fetch main branch | |
run: git fetch origin main | |
# Run pre-commit hooks | |
- name: Run pre-commit hooks | |
run: | | |
# Show pre-commit version | |
pre-commit --version | |
# Run pre-commit on all files changed between the current branch and main | |
- name: Run pre-commit on all changed files | |
run: | | |
# Get the list of files changed between the current branch and main | |
files=$(git diff --name-only origin/main) | |
if [ -n "$files" ]; then | |
pre-commit run --files $files | |
else | |
echo "No modified files to check." | |
fi |