$AUTOFORMAT_COMMIT_MESSAGE #129
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: ci-normalize-code | |
on: | |
push: | |
branches: [master] | |
env: | |
AUTOFORMAT_COMMIT_MESSAGE: 'chore: autoformat isort & black' | |
jobs: | |
normalize-code: | |
if: (github.event.head_commit.message != $AUTOFORMAT_COMMIT_MESSAGE) && ${{ (!startsWith(github.event.head_commit.message, 'bump:')) }} | |
name: "Normalize code with internal standards" | |
permissions: write-all | |
strategy: | |
fail-fast: true | |
matrix: | |
python-version: ['3.10'] | |
os: [ubuntu-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Check out | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.BYPASS_PROTECTED_BRANCHES_PAT }} | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Run image | |
uses: abatilo/[email protected] | |
with: | |
poetry-version: 1.4.0 | |
- name: Cache Poetry virtualenv | |
uses: actions/cache@v4 | |
id: cache | |
with: | |
path: ~/.virtualenvs | |
key: venv-${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
restore-keys: | | |
venv-${{ matrix.os }}-${{ matrix.python-version }}- | |
- name: Set Poetry config | |
run: | | |
poetry config virtualenvs.in-project false | |
poetry config virtualenvs.path ~/.virtualenvs | |
- name: Install Dependencies | |
run: poetry install --only dev | |
if: steps.cache.outputs.cache-hit != 'true' | |
- name: Autoformat code if the check fails | |
run: | | |
poetry run isort . | |
poetry run black . | |
- name: Push changes | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: $AUTOFORMAT_COMMIT_MESSAGE | |
push_options: --force |