Skip to content

Commit

Permalink
Merge pull request #361 from akaihola/ci-no-duplicate-linters
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola authored Aug 28, 2022
2 parents c99b2d0 + 74eb9ae commit 9ed756c
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Security check - Bandit
on: push # yamllint disable-line rule:truthy

jobs:
build:
bandit:
runs-on: ubuntu-latest

steps:
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: codespell

on: push # yamllint disable-line rule:truthy

jobs:
codespell:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: codespell-project/actions-codespell@master
17 changes: 17 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Flake8

on: push # yamllint disable-line rule:truthy

jobs:
flake8:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: TrueBrain/actions-flake8@v2
with:
plugins: >
flake8-2020>=1.6.1
flake8-bugbear>=22.1.11
flake8-comprehensions>=3.7.0
18 changes: 18 additions & 0 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: isort

on: push # yamllint disable-line rule:truthy

jobs:
isort:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install 'isort>=5.0.1'
- uses: wearerequired/lint-action@v2.0.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
isort: true
continue_on_error: false
19 changes: 19 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: mypy

on: push # yamllint disable-line rule:truthy

jobs:
mypy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install -U isort mypy pytest types-toml
- uses: wearerequired/lint-action@v2.0.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
mypy: true
mypy_args: "src"
continue_on_error: false
18 changes: 18 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: pylint

on: push # yamllint disable-line rule:truthy

jobs:
pylint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install pylint
- uses: wearerequired/lint-action@v2.0.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pylint: true
continue_on_error: false
121 changes: 59 additions & 62 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: build
name: Build and test

on: # yamllint disable-line rule:truthy
push:
Expand All @@ -12,6 +12,34 @@ on: # yamllint disable-line rule:truthy

jobs:

build-wheel:
runs-on: ubuntu-latest
outputs:
wheel-path: ${{ steps.get-darker-version.outputs.wheel-path }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Install wheel
run: python -m pip install wheel
- name: Build wheel distribution
run: python setup.py bdist_wheel
- name: Upload wheel for other jobs
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
if-no-files-found: error
- name: Find out Darker version and output it for test jobs
id: get-darker-version
shell: python
run: |
from runpy import run_path
version = run_path("src/darker/version.py")["__version__"]
print(
"::set-output name=wheel-path::"
f"dist/darker-{version}-py3-none-any.whl"
)
test-nixos:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -23,13 +51,15 @@ jobs:
- os: macos-latest
python-version: python39
# see https://github.com/cachix/install-nix-action/issues/135
needs:
- build-wheel
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: cachix/install-nix-action@v17
with:
nix_path: nixpkgs=channel:nixos-21.11
- name: Download wheel uploaded by the build-wheel job
uses: actions/download-artifact@v3
- name: Run tests in nix-shell
run: |
nix-shell \
Expand All @@ -38,13 +68,12 @@ jobs:
--run '
python -m venv venv
source venv/bin/activate
pip install -e '.[isort,test]'
pip install "${{needs.build-wheel.outputs.wheel-path}}[test]"
pytest
' \
./default.nix
build:

test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -59,7 +88,6 @@ jobs:
- '3.9'
- '3.10'
constraints: ['']
lint: ['--darker --flake8 --isort']
include:
- os: ubuntu-latest
python-version: '3.7'
Expand All @@ -68,71 +96,40 @@ jobs:
python-version: '3.10'
constraints: '--constraint constraints-future.txt'
upgrade: '--upgrade --upgrade-strategy=eager'
env:
RUN_MYPY_AND_PYLINT: >-
${{ matrix.python-version == '3.9' || matrix.python-version == '3.10' }}
needs:
- build-wheel
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# need full history since Pytest runs Darker itself below
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip, install wheel and twine
run: |
# strict dependency resolution added in pip 20.3
python -m pip install --upgrade 'pip>=20.3' wheel twine
- name: Build source distribution
run: python setup.py sdist
- name: Build wheel distribution
run: python setup.py bdist_wheel
- name: Validate distributions
run: twine check dist/*
- name: Get Darker version
shell: python
run: |
from os import environ
from pathlib import Path
from runpy import run_path
version = run_path("src/darker/version.py")["__version__"]
Path(environ["GITHUB_ENV"]).write_text(f"VERSION={version}\n")
- name: Install Darker and its dependencies
- name: Download wheel uploaded by the build-wheel job
uses: actions/download-artifact@v3
- name: Install Darker and its dependencies from the wheel build earlier
env:
pip_options: ${{ matrix.upgrade }} ${{ matrix.constraints }}
run: pip install ${pip_options}
"dist/darker-${{ env.VERSION }}-py3-none-any.whl[isort,test]"
- name: Run Pytest without Mypy and Pylint if Python < 3.9
if: env.RUN_MYPY_AND_PYLINT == 'false'
"${{needs.build-wheel.outputs.wheel-path}}[test]"
- name: Run Pytest
run: |
pytest ${{ matrix.lint }}
- name: Run Pytest with Mypy and Pylint if Python >= 3.9
if: env.RUN_MYPY_AND_PYLINT == 'true'
shell: python
run: |
import sys
from pathlib import Path
from subprocess import run
import toml
pytest --darker
data = toml.load("pyproject.toml")
data["tool"]["darker"]["lint"] = ["pylint", "mypy"]
Path("pyproject.toml").write_text(toml.dumps(data))
pytest_cmd = ["pytest"] + "${{ matrix.lint }}".split()
retval = run(pytest_cmd).returncode
run(["git", "restore", "pyproject.toml"])
sys.exit(retval)
- name: Check English spelling in the code base using codespell
run: codespell
- name: Ensure modern Python style using pyupgrade
# This script is written in a Linux / macos / windows portable way
run: |
python -c "
from pyupgrade._main import main
from glob import glob
files = glob('**/*.py', recursive=True)
main(files + ['--py37-plus'])
"
- name: Check dependencies for known security vulterabilities using Safety
run: safety check
build-sdist-validate-dists:
runs-on: ubuntu-latest
needs:
- build-wheel
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Install twine
run: python -m pip install twine
- name: Download wheel uploaded by the build-wheel job
uses: actions/download-artifact@v3
- name: Build source distribution
run: python setup.py sdist
- name: Validate distributions
run: twine check dist/*
23 changes: 23 additions & 0 deletions .github/workflows/pyupgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: pyupgrade

on: push # yamllint disable-line rule:truthy

jobs:
pyupgrade:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install pyupgrade
- name: Ensure modern Python style using pyupgrade
# This script is written in a Linux / macos / windows portable way
run: |
python -c "
import sys
from pyupgrade._main import main
from glob import glob
files = glob('**/*.py', recursive=True)
sys.exit(main(files + ['--py37-plus']))
" || ( git diff ; false )
15 changes: 15 additions & 0 deletions .github/workflows/safety.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: safety

on: push # yamllint disable-line rule:truthy

jobs:
safety:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install -U safety
- name: Check dependencies for known security vulnerabilities using Safety
run: safety check
4 changes: 2 additions & 2 deletions .github/workflows/test-future.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on: # yamllint disable-line rule:truthy
- cron: "05 20 * * 6"

jobs:
build:
test-future:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -27,7 +27,7 @@ jobs:
--constraint=constraints-future.txt \
--upgrade \
--upgrade-strategy=eager \
-e '.[isort,test]'
-e '.[test]'
- name: Test with pytest
run: |
pytest
2 changes: 0 additions & 2 deletions .github/workflows/yaml-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Added
-----
- Add a CI workflow which verifies that the ``darker --help`` output in ``README.rst``
is up to date.
- Only run linters, security checks and package builds once in the CI build.

Fixed
-----
Expand Down
8 changes: 0 additions & 8 deletions constraints-oldest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@
# interpreter and Python ependencies. Keep this up-to-date with minimum
# versions in `setup.cfg`.
airium==0.2.3
bandit==1.7.1
black==21.8b0
codespell==2.1.0
defusedxml==0.7.1
flake8-2020==1.6.1
flake8-bugbear==22.1.11
flake8-comprehensions==3.7.0
mypy==0.940
Pygments==2.4.0
pylint==2.13.0
pytest==6.2.0
pytest-flake8==1.0.6
pytest-isort==1.1.0
pytest-kwparametrize==0.0.3
pyupgrade==2.31.0
regex==2021.4.4
requests_cache==0.7
ruamel.yaml==0.17.21
safety==1.10.3
toml==0.10.0
twine==2.0.0
types-toml==0.10.4
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ src = [
"src",
]
revision = "origin/master..."
# The empty linter list is here so `.github/workflows/python-package.yml` can
# add Pylint in certain run configurations:
lint = []
Loading

0 comments on commit 9ed756c

Please sign in to comment.