Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formatting feature #25

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: info
workdir: ./testdata/

test-check-format:
name: runner / markdown-lint (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 --untracked-files=no | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
fi

test-pr-check:
if: github.event_name == 'pull_request'
Expand All @@ -27,6 +48,28 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
level: warning
workdir: ./testdata/

test-pr-check-format:
if: github.event_name == 'pull_request'
name: runner / markdown-lint (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 --untracked-files=no | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
fi

test-pr-review:
if: github.event_name == 'pull_request'
Expand All @@ -40,3 +83,26 @@ jobs:
reporter: github-pr-review
level: error
reviewdog_flags: -filter-mode=file -fail-on-error
workdir: ./testdata/

test-pr-review-format:
if: github.event_name == 'pull_request'
name: runner / markdown-lint (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 --untracked-files=no | wc -l)
if [[ ${changed_files} -eq 0 ]]; then
echo "No changes detected!"
exit 1
fi
32 changes: 16 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 13 December 2020

- :wrench: Updates dockerfile reviewdog install to nightly branch [`#5`](https://github.com/rickstaa/action-remark-lint/pull/5)
- Add --frail argument to remark to exit with 1 on warnings [`#3`](https://github.com/rickstaa/action-remark-lint/pull/3)
- Fix reviewdog exit code bug and error format syntax problem [`#4`](https://github.com/rickstaa/action-remark-lint/pull/4)
- Change version and reporter [`#1`](https://github.com/rickstaa/action-remark-lint/pull/1)
- :see_no_evil: Updates gitignore [`2b9ef56`](https://github.com/rickstaa/action-remark-lint/commit/2b9ef565dc342eb7b01170c22d0c8efbf26adda5)
- :sparkles: Adds reviewdog ci actions, testdata and removes github-pr-review warning [`3fe02eb`](https://github.com/rickstaa/action-remark-lint/commit/3fe02eb8f74cba56966ea63532354e99f5b23cb1)
- :sparkles: Adds additional reviewdog arguments and updates documentation [`a4425dc`](https://github.com/rickstaa/action-remark-lint/commit/a4425dccec04b3eb28d9756b49227aef7e630aed)
* :wrench: Updates dockerfile reviewdog install to nightly branch [`#5`](https://github.com/rickstaa/action-remark-lint/pull/5)
* Add --frail argument to remark to exit with 1 on warnings [`#3`](https://github.com/rickstaa/action-remark-lint/pull/3)
* Fix reviewdog exit code bug and error format syntax problem [`#4`](https://github.com/rickstaa/action-remark-lint/pull/4)
* Change version and reporter [`#1`](https://github.com/rickstaa/action-remark-lint/pull/1)
* :see_no_evil: Updates gitignore [`2b9ef56`](https://github.com/rickstaa/action-remark-lint/commit/2b9ef565dc342eb7b01170c22d0c8efbf26adda5)
* :sparkles: Adds reviewdog ci actions, testdata and removes github-pr-review warning [`3fe02eb`](https://github.com/rickstaa/action-remark-lint/commit/3fe02eb8f74cba56966ea63532354e99f5b23cb1)
* :sparkles: Adds additional reviewdog arguments and updates documentation [`a4425dc`](https://github.com/rickstaa/action-remark-lint/commit/a4425dccec04b3eb28d9756b49227aef7e630aed)

#### [v0.0.5](https://github.com/rickstaa/action-remark-lint/compare/v0.0.4...v0.0.5)

> 25 January 2020

- Re-fixed args passed to remark (what a painful piece of software) [`abb616b`](https://github.com/rickstaa/action-remark-lint/commit/abb616bd9d9ec698d38bb680e5caa4c16f6380ff)
- Revert "Added --no-stdout --no-color args to remark call" [`3c2e844`](https://github.com/rickstaa/action-remark-lint/commit/3c2e844aaa86e3bbe96a93bebd3f44b629c37e10)
* Re-fixed args passed to remark (what a painful piece of software) [`abb616b`](https://github.com/rickstaa/action-remark-lint/commit/abb616bd9d9ec698d38bb680e5caa4c16f6380ff)
* Revert "Added --no-stdout --no-color args to remark call" [`3c2e844`](https://github.com/rickstaa/action-remark-lint/commit/3c2e844aaa86e3bbe96a93bebd3f44b629c37e10)

#### [v0.0.4](https://github.com/rickstaa/action-remark-lint/compare/v0.0.3...v0.0.4)

> 25 January 2020

- Added --no-stdout --no-color args to remark call [`4d68733`](https://github.com/rickstaa/action-remark-lint/commit/4d687330c3b96a6261a3426878c584059bb7ff5d)
* Added --no-stdout --no-color args to remark call [`4d68733`](https://github.com/rickstaa/action-remark-lint/commit/4d687330c3b96a6261a3426878c584059bb7ff5d)

#### [v0.0.3](https://github.com/rickstaa/action-remark-lint/compare/v0.0.2...v0.0.3)

> 25 January 2020

- Revert "Added Makefile and release script" [`e078250`](https://github.com/rickstaa/action-remark-lint/commit/e0782504aad6bc4bd4970a6d236e13254d2a1fac)
- Added Makefile and release script [`f4ca24a`](https://github.com/rickstaa/action-remark-lint/commit/f4ca24a8b145313efa4c88e749fecc01e33b49f7)
- Fixed remark CLI usage [`09a9260`](https://github.com/rickstaa/action-remark-lint/commit/09a9260dcbc40e639ad089664070a6ea9be63e04)
* Revert "Added Makefile and release script" [`e078250`](https://github.com/rickstaa/action-remark-lint/commit/e0782504aad6bc4bd4970a6d236e13254d2a1fac)
* Added Makefile and release script [`f4ca24a`](https://github.com/rickstaa/action-remark-lint/commit/f4ca24a8b145313efa4c88e749fecc01e33b49f7)
* Fixed remark CLI usage [`09a9260`](https://github.com/rickstaa/action-remark-lint/commit/09a9260dcbc40e639ad089664070a6ea9be63e04)

#### [v0.0.2](https://github.com/rickstaa/action-remark-lint/compare/v0.0.1...v0.0.2)

Expand All @@ -53,6 +53,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 25 January 2020

- Initial Commit [`9427de7`](https://github.com/rickstaa/action-remark-lint/commit/9427de75ca49d1c667e37c01974f46391dea78f0)
- Revert "Added Makefile and release script" [`e078250`](https://github.com/rickstaa/action-remark-lint/commit/e0782504aad6bc4bd4970a6d236e13254d2a1fac)
- Added Makefile and release script [`f4ca24a`](https://github.com/rickstaa/action-remark-lint/commit/f4ca24a8b145313efa4c88e749fecc01e33b49f7)
* Initial Commit [`9427de7`](https://github.com/rickstaa/action-remark-lint/commit/9427de75ca49d1c667e37c01974f46391dea78f0)
* Revert "Added Makefile and release script" [`e078250`](https://github.com/rickstaa/action-remark-lint/commit/e0782504aad6bc4bd4970a6d236e13254d2a1fac)
* Added Makefile and release script [`f4ca24a`](https://github.com/rickstaa/action-remark-lint/commit/f4ca24a8b145313efa4c88e749fecc01e33b49f7)
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ FROM prologic/remark-lint:latest

ENV REVIEWDOG_VERSION=v0.11.0-nightly20201213+85edbc6

RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/nightly/master/install.sh| sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION}
RUN apk add --no-cache bash

RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/nightly/master/install.sh | sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION}

RUN apk --no-cache -U add git

Expand Down
128 changes: 83 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
[![reviewdog](https://github.com/reviewdog/action-remark-lint/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/reviewdog/action-remark-lint/workflows/depup/badge.svg)](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3Adepup)
[![release](https://github.com/reviewdog/action-remark-lint/workflows/release/badge.svg)](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-remark-lint?logo=github&sort=semver)](https://github.com/reviewdog/action-remark-lint/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 release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-remark-lint?logo=github\&sort=semver)](https://github.com/reviewdog/action-remark-lint/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)

![action screenshot](https://user-images.githubusercontent.com/17570430/102060312-4ee5e000-3df2-11eb-8c82-767afeccd8db.png)
![action screenshot](https://user-images.githubusercontent.com/17570430/102059912-d3842e80-3df1-11eb-9b0a-2e04eab5e294.png)

This action runs [remark-lint](https://github.com/remarkjs/remark-lint) with [reviewdog](https://github.com/reviewdog/reviewdog) on pull requests to improve
code review experience.
This action runs [remark-lint](https://github.com/remarkjs/remark-lint) with [reviewdog](https://github.com/reviewdog/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.

## Quickstart

Expand Down Expand Up @@ -39,72 +38,111 @@ See the Inputs section below for details on the defaults and optional configurat

**Required**. Must be in form of `github_token: ${{ secrets.github_token }}`'.

### workdir
### `workdir`

**Optional**. The directory to run remark-lint in. Default is `.`.
**Optional**. The directory to run remark-lint in. Defaults to `.`.

### remark_flags
### `format`

**Optional**. Additional flags you want to pass to remark-lint. Default is ` `.
**Optional**. If true, remark-lint format files and commit are creatable (use other Action). Defaults to `false`.

### `level`

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

### `reporter`
#### `fail_on_error`

**Optional**. Reporter of reviewdog command \[github-pr-check, github-pr-review, github-check\].
Default is github-pr-check. github-pr-review can use Markdown and add a link to rule page in reviewdog reports.
**Optional**. Exit code for when remark-lint errors are found \[`true`, `false`]. Defaults to `false`.

**NB:** Only `github-pr-check` is supported currently.
#### `remark_flags`

#### `filter_mode`
**Optional**. Additional remark-lint flags. Defaults to `""`.

**Optional**. Filtering mode for the reviewdog command \[added, diff_context, file, nofilter\]. Default = `"added"`.
### `annotate`

#### `fail_on_error`
**Optional**. Annotate remark-lint changes using reviewdog. Defaults to `true`.

**Optional**. Exit code for reviewdog when errors are found \[`true`, `false`\]. Default = `false`.
#### `tool_name`

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

**Optional**. Additional reviewdog flags. Default = `""`.
### `level`

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

**Optional**. Tool name to use for reviewdog reporter. Default = `remark-lint`.
### `reporter`

## Development
**Optional**. Reporter of reviewdog command \[github-pr-check, github-pr-review, github-check].
Default is github-pr-check. github-pr-review can use Markdown and add a link to rule page in reviewdog reports.

### Release
### `filter_mode`

#### [haya14busa/action-bumpr](https://github.com/haya14busa/action-bumpr)
**Optional**. Filtering mode for the reviewdog command \[added, diff_context, file, nofilter]. Defaults to `"added"`.

You can bump version on merging Pull Requests with specific labels (bump:major,bump:minor,bump:patch).
Pushing tag manually by yourself also work.
### `reviewdog_flags`

#### [haya14busa/action-update-semver](https://github.com/haya14busa/action-update-semver)
**Optional**. Additional reviewdog flags. Defaults to `""`.

This action updates major/minor release tags on a tag push. e.g. Update v1 and v1.2 tag when released v1.2.3.
ref: <https://help.github.com/en/articles/about-actions#versioning-your-action>
## Outputs

### Lint - reviewdog integration
### `is_formatted`

This reviewdog action template itself is integrated with reviewdog to run lints
which is useful for Docker container based actions.
Whether the files were formatted using the remark-lint linter.

![reviewdog integration](https://user-images.githubusercontent.com/3797062/72735107-7fbb9600-3bde-11ea-8087-12af76e7ee6f.png)
## Advance use cases

Supported linters:
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this feature or use reviewdog -f=diff instead to support code suggestion instead of committing whole changes w/o reviewdog?

If it just runs the formatter and don't need reviewdog, you should create a different action which doesn't require reviewdog and users should use the action instead.

You can refer to https://github.com/reviewdog/action-suggester

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haya14busa I now changed the action such that the formatting action is seperate from the annotation action. As a result, the formatting is only done when the user explicitly asks for the files to be formatted. Consequently, review dog only receives the unformatted output. What do you think about this implementation?

Copy link
Member Author

@rickstaa rickstaa Jan 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haya14busa I agree that committing back the changes to the pull request or repository is bad practice. I use this feature to format + annotate the code while also creating a pull-request containing the formatted code. We can also remove the stefanzweifel/git-auto-commit-action action from the README and keep the peter-evans/create-pull-request action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, it's fine to create an action that format the file and use commit / pull-request actions, but in this case, you don't need to use reviewdog, so it should be better to create a separate repo.
Users can just install or run simple formatted action and then use commit / pull-request actions instead of using this reviewdog action.

My second point is that reviewdog supports code-suggestion based on diff (see action-suggester for example as written above), so if you want to support this feature, I'm very much welcome to have such feature in reviewdog actions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haya14busa Ah I see! I will revert the formatting related changes (both in this repository and in the action-black repository) and only add the new remark_flags argument. I will try out if I can use the https://github.com/reviewdog/action-suggester with my actions and add a small note to this repository pointing to that action if people want to also autoformat their code.


- [reviewdog/action-shellcheck](https://github.com/reviewdog/action-shellcheck)
- [reviewdog/action-hadolint](https://github.com/reviewdog/action-hadolint)
- [reviewdog/action-misspell](https://github.com/reviewdog/action-misspell)
### Commit changes

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

This repository uses [reviewdog/action-depup](https://github.com/reviewdog/action-depup) to update
reviewdog version.
### Create pull request

[![reviewdog depup demo](https://user-images.githubusercontent.com/3797062/73154254-170e7500-411a-11ea-8211-912e9de7c936.png)](https://github.com/reviewdog/action-template/pull/6)
```yaml
name: reviewdog
on: [pull_request]
jobs:
name: runner / remark-lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check files using remark-lint linter
uses: reviewdog/action-remark-lint@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 markdown code with remark-lint linter"
commit-message: ":art: Format markdown code with remark-lint linter"
body: |
There appear to be some python formatting errors in ${{ github.sha }}. This pull request
uses the [remark-lint](https://github.com/remarkjs/remark-lint) linter to fix these issues.
branch: actions/remark-lint
```
Loading