Skip to content

Commit

Permalink
[TASK] Introduce pre commit hooks
Browse files Browse the repository at this point in the history
To remove trailing whitespace and let files end on one empty line.
  • Loading branch information
linawolf committed Aug 18, 2024
1 parent 48ee21d commit 114ab2c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/apply-precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.ref }} # Ensure to checkout the correct branch or ref
ref: ${{ github.ref }}

- name: Set up Python
uses: actions/setup-python@v2
Expand All @@ -27,18 +27,16 @@ jobs:
- name: Run pre-commit hooks to fix issues
id: pre-commit
run: |
if pre-commit run --all-files --hook-stage=manual --show-diff-on-failure; then
echo "Pre-commit hooks passed successfully."
else
echo "Pre-commit hooks failed. Proceeding with the next steps."
fi
pre-commit run --all-files --hook-stage=manual || true
git config user.name "github-actions"
git config user.email "[email protected]"
# Check for changes
git status
git diff --cached
# Add and commit changes if there are any
if ! git diff --cached --quiet; then
git add .
git commit -m "Fix whitespace issues"
Expand All @@ -49,10 +47,12 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Push changes
if: success()
if: success() && github.event_name == 'pull_request'
run: |
# Push changes to the branch from which the pull request was created
git push origin ${{ github.head_ref }} || echo "Failed to push changes"
# Get the current branch name
BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}")
echo "Pushing changes to branch: $BRANCH_NAME"
git push origin "$BRANCH_NAME" || echo "Failed to push changes"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down

0 comments on commit 114ab2c

Please sign in to comment.