Skip to content

Commit

Permalink
reviewdog for github action, refs wemake-services#1023 (wemake-servic…
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Nov 26, 2019
1 parent 5efd8b8 commit 0527ab4
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/wps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: wemake-services/wemake-python-styleguide@master
with:
reporter: 'github-pr-review'
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
We follow Semantic Versions since the `0.1.0` release.
We used to have incremental versioning before `0.1.0`.


## 0.13.1 WIP

### Bufixes
Expand All @@ -12,6 +13,10 @@ We used to have incremental versioning before `0.1.0`.
- Fixes invalid docs for `BracketBlankLineViolation` #1020
- Add more complex example to `ParametersIndentationViolation` #1021

### Misc

- Now our GitHub Action can be used to leave PR review comments


## 0.13.0 aka The Lintoberfest

Expand Down
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
# This is Github Action docker-based image.
# It is not intended for local development!
#
# You can find docs about how to setup your own Github Action here:
# https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/github-actions.html
#
# It can still be used as a raw image for your own containers.
# See `action.yml` in case you want to learn more about Github Actions.
# See it live:
# https://github.com/wemake-services/wemake-python-styleguide/actions

#
# This image is also available on Dockerhub:
# https://hub.docker.com/r/wemakeservices/wemake-python-styleguide

Expand All @@ -19,9 +22,13 @@ LABEL vendor="wemake.services"

ENV WPS_VERSION='0.13.0'

RUN apk add --no-cache bash
RUN pip install "wemake-python-styleguide==$WPS_VERSION"
RUN apk add --no-cache bash git wget
RUN pip install "wemake-python-styleguide==$WPS_VERSION" \
# Installing reviewdog to optionally comment on pull requests:
&& wget -O - -q 'https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh' \
| sh -s -- -b /usr/local/bin/ v0.9.13

COPY ./scripts/action-config.cfg /
COPY ./scripts/entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![Github Action](https://github.com/wemake-services/wemake-python-styleguide/workflows/wps/badge.svg)](https://github.com/wemake-services/wemake-python-styleguide/actions)
[![Python Version](https://img.shields.io/pypi/pyversions/wemake-python-styleguide.svg)](https://pypi.org/project/wemake-python-styleguide/)
[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide)

---

Welcome to the strictest and most opinionated python linter ever.
Expand Down Expand Up @@ -52,6 +53,9 @@ And it won't change your existing workflow.
See ["Usage" section](https://wemake-python-stylegui.de/en/latest/pages/usage/setup.html)
in the docs for examples and integrations.

We also support [Github Actions](https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/github-actions.html) as first class-citizens.
[Try it out](https://github.com/marketplace/actions/wemake-python-styleguide)!


## What we are about

Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ inputs:
description: 'Path or space-separated list of paths to lint'
required: false
default: '.'

reporter:
description: 'How would you like the results to be displayed?'
required: false
default: 'terminal'

outputs:
output:
description: 'The output of wemake-python-styleguide run'
Expand All @@ -24,3 +28,4 @@ runs:
image: 'Dockerfile'
args:
- ${{ inputs.path }}
- ${{ inputs.reporter }}
31 changes: 23 additions & 8 deletions docs/pages/usage/integrations/github-actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,31 @@ You can use it from the `Github Marketplace <https://github.com/marketplace/acti
You can also specify any version
starting from ``0.12.5`` instead of the ``latest`` tag.
You can also specify to leave inline PR comments
and PR summary review starting from ``0.13.1`` version.

Inputs
~~~~~~

We also support custom path to be specified:
We support three reporting options:

- ``terminal`` (default one) when we just dump the output into Action's logs.
Is the easiest one to setup, that's why we use it by default
- ``github-pr-review`` (recommended) when we use `inline comments <https://github.com/reviewdog/reviewdog#reporter-github-pullrequest-review-comment--reportergithub-pr-review>`_ inside code reviews
- ``github-pr-check`` when we use `Github Checks <https://github.com/reviewdog/reviewdog#reporter-github-checks--reportergithub-pr-check>`_ for the output

That's how it can be setup:

.. code:: yaml
- name: wemake-python-styleguide
uses: wemake-python-styleguide@latest
with:
reporter: 'github-pr-review'
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
We also support custom ``path`` to be specified:

.. code:: yaml
Expand All @@ -34,15 +54,10 @@ Outputs

We also support ``outputs`` from the spec, so you can later
pass the output of ``wemake-python-styleguide`` to somewhere else.
For example to `reviewdog <https://github.com/reviewdog/reviewdog>`_ app.

.. code:: yaml
- name: wemake-python-styleguide
uses: wemake-python-styleguide@latest
with:
path: './your/custom/path'
- name: Custom reviewdog Action
runs: echo "{{ steps.wemake-python-styleguide.outputs.output }}" | reviewdog -f pep8
Note, that Github Actions are currently in beta.
- name: Custom Action
runs: echo "{{ steps.wemake-python-styleguide.outputs.output }}"
10 changes: 10 additions & 0 deletions scripts/action-config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# We need to overload some default configuration,
# when running inside Github Actions + ReviewDog.
# Because we struggle to get the correct formatting.

[flake8]
# Base flake8 configuration:
# https://flake8.pycqa.org/en/latest/user/configuration.html
format = default
show-source = False
statistics = False
24 changes: 20 additions & 4 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/bin/bash

# Diagnostic output for the passed path:
echo "Linting path: $1"
flake8 --version
echo "Linting path: $INPUT_PATH"
echo '================================='
echo

# Runs flake8:
output=$(flake8 "$1")
status="$?"
# Runs flake8, possibly with reviewdog:
if [ "$INPUT_REPORTER" == 'terminal' ]; then
output=$(flake8 "$INPUT_PATH")
status="$?"
elif [ "$INPUT_REPORTER" == 'github-pr-review' ] ||
[ "$INPUT_REPORTER" == 'github-pr-check' ]; then
# We will need this token for `reviewdog` to work:
export REVIEWDOG_GITHUB_API_TOKEN="$GITHUB_TOKEN"

# Running special version of `flake8` to mathc the `reviewdog` format:
output=$(flake8 "$INPUT_PATH" --append-config='/action-config.cfg')
echo "$output" | reviewdog -f=pep8 -reporter="$INPUT_REPORTER" -level=error
# `reviewdog` does not fail with any status code, so we have to get dirty:
status=$(test "$output" = '')
else
output="Invalid reporter specified: $INPUT_REPORTER"
status=1
fi

# Sets the output variable for Github Action API:
# See: https://help.github.com/en/articles/development-tools-for-github-action
Expand Down

0 comments on commit 0527ab4

Please sign in to comment.