Use pre-commit for testing style #5
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: Suggest style upgrades | |
#on: | |
# schedule: | |
# - cron: "0 0 * * *" | |
on: | |
push: | |
branches: | |
- main | |
- 'version-**' | |
pull_request: | |
jobs: | |
update-style: | |
timeout-minutes: 15 | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.11'] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: "pip" | |
cache-dependency-path: | | |
setup.py | |
pyproject.toml | |
- name: Install pre-commit | |
run: pip install pre-commit | |
- name: Check for updates | |
run: pre-commit autoupdate | |
- name: Run style check | |
run: pre-commit run --all-files --show-diff-on-failure | |
continue-on-error: true | |
- name: Check for changes | |
id: check_for_changes | |
run: | | |
if git diff --quiet; then | |
echo "changes=false" >> "$GITHUB_ENV" | |
else | |
echo "changes=true" >> "$GITHUB_ENV" | |
fi | |
- name: Add changed files | |
if: ${{ env.changes == 'true' }} | |
run: | | |
git config user.name "$USER_NAME" | |
git config user.email "$USER_EMAIL" | |
git checkout -b update_dependencies | |
git commit -a -m "Update style dependencies" | |
- name: Create pull request | |
if: ${{ env.changes == 'true' }} | |
run: gh pr create -B main -H update_dependencies --title 'Update style dependencies' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |