[TASK] Introduce pre commit hooks #40
Workflow file for this run
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: Check and Fix Whitespace | |
on: [push, pull_request] | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install pre-commit | |
run: pip install pre-commit | |
- name: Configure Git | |
run: | | |
git config user.name "github-actions" | |
git config user.email "[email protected]" | |
- name: Run pre-commit hooks to fix issues | |
id: pre-commit | |
run: | | |
pre-commit run --all-files --hook-stage=manual || true | |
# Stage all changes | |
git add . | |
# Commit changes if there are any | |
if git diff --cached --quiet; then | |
echo "No changes to commit" | |
else | |
git commit -m "Fix whitespace issues" || echo "No changes to commit" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Determine branch to push | |
id: determine-branch | |
run: | | |
# For pull requests, use the head ref | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV | |
else | |
# For push events, use the branch name from ref | |
BRANCH_NAME=${GITHUB_REF#refs/heads/} | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
fi | |
env: | |
GITHUB_REF: ${{ github.ref }} | |
- name: Push changes | |
if: success() | |
run: | | |
echo "Pushing changes to branch: ${{ env.BRANCH_NAME }}" | |
git push origin "${{ env.BRANCH_NAME }}" || echo "Failed to push changes" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Debug | |
run: | | |
echo "Git status:" | |
git status | |
echo "Git diff:" | |
git diff --cached | |