Pre-commit fix #1
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: Run pre-commit and commit changes on Github Actions UI | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
run-pre-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref_name }} | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install pre-commit | |
run: | | |
python -m venv venv | |
. venv/bin/activate | |
pip install --upgrade pip | |
pip install pre-commit | |
- name: Run pre-commit | |
run: | | |
. venv/bin/activate | |
pre-commit run --all-files | |
continue-on-error: true | |
- name: Check for changes | |
id: check_changes | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Changes detected by pre-commit." | |
echo "::set-output name=changes_detected::true" | |
else | |
echo "No changes made by pre-commit." | |
echo "::set-output name=changes_detected::false" | |
fi | |
- name: Commit and push changes | |
if: steps.check_changes.outputs.changes_detected == 'true' | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "Apply pre-commit fixes" | |
git push origin HEAD:${{ github.ref_name }} |