Skip to content

Commit

Permalink
Add "Darker" github action (#1373)
Browse files Browse the repository at this point in the history
Adds a pyproject.toml for default black/darker configuration
Adds a "Darker" github action which picks up on black linting issues for the sections of a file which have changed
  • Loading branch information
tremble authored Feb 21, 2023
1 parent 95b1f08 commit fab1090
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/darker-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: 'Python formatting linter (Darker / Black)'

on:
workflow_dispatch:
pull_request:
branches:
- main

permissions:
contents: read
pull-requests: read

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
check-darker:
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
steps:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ inputs.python }}

- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Install darker
shell: bash
run: |
pip install darker
- name: Rebase against current base
shell: bash
run: |
git config user.email "[email protected]"
git config user.name "Git Hub Testing Rebase"
git rebase ${{ github.event.pull_request.base.sha }}
git show -s
- name: Run darker
shell: bash
run: |
darker --check --diff --color --rev ${{ github.event.pull_request.base.sha }}..
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.black]
skip-string-normalization = false
line-length = 120
target-version = ['py37', 'py38']
extend-exclude = '''
/(
| plugins/module_utils/_version.py
)/
'''

[tool.darker]
revision = "origin/main.."

src = [
"plugins",
"tests/unit",
"tests/integration",
]

0 comments on commit fab1090

Please sign in to comment.