Skip to content

Commit

Permalink
⏪ Removes formatting feature (#29)
Browse files Browse the repository at this point in the history
* 🔥 Removes formatting feature

After a discussion with @haya14busa we decided to remove the formatting
action again as this should be left inside a seperate repository
(see reviewdog/action-remark-lint#25). This
repository can be found on https://github.com/rickstaa/action-black.

* 💚 Removes formatting related gh-action tests

* 🐛 Fixes syntax errors that were marked by shellcheck

* 🚀 Removes debugging statements

* 📝 Updates README.md badges

* 📝 Updates readme.md

* 📝 Updates documentation

* 🔥 Removes redundant code

* 🐛 Fixes bash syntax bugs

* 💚 Removes unnecessary test commands

* 💥 Changes black_flags to black_args

This commit changes the `black_flags` input argument to `black_args` as
this better describes what it does. Additionally it contains some small
bug fixes.

* 💬 Fixes some spell errors

* 🎨 Improves code structure
  • Loading branch information
rickstaa authored Jan 10, 2021
1 parent dbde0e2 commit 1e5ee4c
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 361 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/depup.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: depup
on:
schedule:
- cron: '14 14 * * *' # Runs at 14:14 UTC every day
- cron: "14 14 * * *" # Runs at 14:14 UTC every day
repository_dispatch:
types: [depup]
workflow_dispatch:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- master
tags:
- 'v*.*.*'
- "v*.*.*"
pull_request:
types:
- labeled
Expand Down Expand Up @@ -56,4 +56,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Post bumpr status comment
uses: haya14busa/action-bumpr@v1
uses: haya14busa/action-bumpr@v1
87 changes: 0 additions & 87 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,6 @@ jobs:
exit 1
fi
test-check-format:
name: runner / black-format (github-check-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: info
format: true
workdir: ./testdata/
- name: Check if formatting was successful
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
else
echo "Changes detected!"
fi
test-pr-check:
if: github.event_name == 'pull_request'
name: runner / black-format (github-pr-check)
Expand All @@ -60,38 +38,6 @@ jobs:
reporter: github-pr-check
level: warning
workdir: ./testdata/
- name: Check if code is left untouched (not formatted)
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
else
echo "Changes detected!"
exit 1
fi
test-pr-check-format:
if: github.event_name == 'pull_request'
name: runner / black-format (github-pr-check-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
level: warning
format: true
workdir: ./testdata/
- name: Check if formatting was successful
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
else
echo "Changes detected!"
fi

test-pr-review:
if: github.event_name == 'pull_request'
Expand All @@ -106,36 +52,3 @@ jobs:
level: error
reviewdog_flags: -filter-mode=file -fail-on-error
workdir: ./testdata/
- name: Check if code is left untouched (not formatted)
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
else
echo "Changes detected!"
exit 1
fi
test-pr-review-format:
if: github.event_name == 'pull_request'
name: runner / black-format (github-pr-review-format)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
reviewdog_flags: -filter-mode=file -fail-on-error
format: true
workdir: ./testdata/
- name: Check if formatting was successful
run: |
changed_files=$(git status --porcelain | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
else
echo "Changes detected!"
fi
180 changes: 49 additions & 131 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,19 @@
# Black action

[![Test](https://github.com/rickstaa/action-black/workflows/Test/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/rickstaa/action-black/workflows/reviewdog/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/rickstaa/action-black/workflows/depup/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3Adepup)
[![release](https://github.com/rickstaa/action-black/workflows/release/badge.svg)](https://github.com/rickstaa/action-black/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/rickstaa/action-black?logo=github\&sort=semver)](https://github.com/rickstaa/action-black/releases)
[![Test](https://github.com/reviewdog/action-black/workflows/Test/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/reviewdog/action-black/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/reviewdog/action-black/workflows/depup/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3Adepup)
[![release](https://github.com/reviewdog/action-black/workflows/release/badge.svg)](https://github.com/reviewdog/action-black/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-black?logo=github\&sort=semver)](https://github.com/reviewdog/action-black/releases)
[![action-bumpr supported](https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github\&link=https://github.com/haya14busa/action-bumpr)](https://github.com/haya14busa/action-bumpr)

![github-pr-check demo](https://user-images.githubusercontent.com/17570430/102082175-c6773780-3e11-11eb-9af9-d7ee07ca353a.png)

This action runs the [black formatter](https://github.com/psf/black) with reviewdog on pull requests to improve code review experience. It can be used to format your code and/or annotate possible changes that would be made during this formatting.
This action runs the [black formatter](https://github.com/psf/black) with reviewdog on pull requests to improve code review experience.

## Inputs
## Quick Start

```yaml
inputs:
workdir:
description: "Working directory relative to the root directory. Defaults to '.'."
required: false
default: "."
format:
description: |
If true, black format files and commit are creatable (use other Action).
Defaults to 'false'.
required: false
default: "false"
fail_on_error:
description: |
Exit code when black formatting errors are found [true, false]. Defaults to 'false'.
required: false
default: "false"
black_flags:
description: "Additional black flags."
required: false
default: ""
# Reviewdog related inputs
annotate:
description: "Annotate black changes using reviewdog. Defaults to 'true'."
required: false
default: "true"
github_token:
description: "The automatically created secret github action token."
required: true
default: ${{ github.token }}
tool_name:
description: "Tool name to use for reviewdog reporter. Defaults to 'black-format'."
required: false
default: "black-format"
level:
description: "Report level for reviewdog [info, warning, error]. Defaults to 'error'."
required: false
default: "error"
reporter:
description: |
Reporter of reviewdog command [github-pr-check, github-pr-review, github-check].
Defaults to 'github-pr-check'.
required: false
default: "github-pr-check"
filter_mode:
description: |
Filtering mode for the reviewdog command [added, diff_context, file, nofilter].
Default is added.
required: false
default: "added"
reviewdog_flags:
description: "Additional reviewdog flags."
required: false
default: ""
```
## Outputs
```yml
outputs:
is_formatted:
description: "Whether the files were formatted using the black formatter."
```
## Basic usage
In it's simplest form this action can be used to annotate the changes the black formatter would make if it was run on the code.
In it's simplest form this action can be used to annotate the changes the [black](https://github.com/psf/black) formatter would make if it was run on the code.

```yaml
name: reviewdog
Expand All @@ -96,68 +30,52 @@ jobs:
# Change reviewdog reporter if you need [github-pr-check, github-check].
reporter: github-pr-check
# Change reporter level if you need.
# GitHub Status Check won't become failure with warning.
# GitHub Status Check won't become failure with a warning.
level: warning
```
## Advanced use cases
## Inputs
This action can be combined with [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) or [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) to also apply the annotated changes to the repository.
### `github_token`

### Commit changes
**Required**. The [GITHUB_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow). Must be in form of `github_token: ${{ secrets.github_token }}`. Defaults to `${{ github.token }}`.

```yaml
name: reviewdog
on: [pull_request]
jobs:
name: runner / black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Check files using black formatter
uses: reviewdog/action-black@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: error
fail_on_error: true
format: true
- name: Commit black formatting results
if: failure()
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: ":art: Format Python code with psf/black push"
```
### `workdir`

### Create pull request
**Optional**. The directory to run remark-lint in. Defaults to `.`.

```yaml
name: reviewdog
on: [pull_request]
jobs:
name: runner / black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using black formatter
uses: reviewdog/action-black@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-check
level: error
fail_on_error: true
format: true
- name: Create Pull Request
if: failure()
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Format Python code with psf/black push"
commit-message: ":art: Format Python code with psf/black"
body: |
There appear to be some python formatting errors in ${{ github.sha }}. This pull request
uses the [psf/black](https://github.com/psf/black) formatter to fix these issues.
branch: actions/black
```
#### `black_args`

**Optional**. Additional black input arguments. Defaults to `""`.

| :warning: | Because this action uses the black output to create the annotations, it does not work with the black `--quiet` flag. |
| --------- | -------------------------------------------------------------------------------------------------------------------- |

#### `tool_name`

**Optional**. Tool name to use for reviewdog reporter. Defaults to `remark-lint`.

### `level`

**Optional**. Report level for reviewdog `[info, warning, error]`. It's same as `-level` flag of reviewdog. Defaults to `error`.

### `reporter`

**Optional**. Reporter of reviewdog command `[github-pr-check, github-pr-review, github-check]`.
Default is github-pr-check.

### `filter_mode`

**Optional**. Filtering mode for the reviewdog command `[added, diff_context, file, nofilter]`. Defaults to `added`.

#### `fail_on_error`

**Optional**. Exit code for when reviewdog when errors are found `[true, false]`. Defaults to `false`.

### `reviewdog_flags`

**Optional**. Additional reviewdog flags. Defaults to `""`.

## Format your code

This action is meant to annotate any possible changes that would need to be made to make your code adhere to the [black formatting guidelines](github.com/psf/black). It does not apply these changes to your codebase. If you also want to apply the changes to your repository, you can use the [reviewdog/action-suggester](https://github.com/reviewdog/action-suggester). You can find examples of how this is done can be found in [rickstaa/action-black](https://github.com/rickstaa/action-black/)
Loading

0 comments on commit 1e5ee4c

Please sign in to comment.