-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 3 commits
78f1919
e7fd133
d7e5d99
42f4234
a57ccbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,13 @@ | |
[](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3Areviewdog) | ||
[](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3Adepup) | ||
[](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3Arelease) | ||
[](https://github.com/reviewdog/action-remark-lint/releases) | ||
[](https://github.com/haya14busa/action-bumpr) | ||
[](https://github.com/reviewdog/action-remark-lint/releases) | ||
[](https://github.com/haya14busa/action-bumpr) | ||
|
||
 | ||
 | ||
|
||
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 | ||
|
||
|
@@ -43,29 +42,25 @@ See the Inputs section below for details on the defaults and optional configurat | |
|
||
**Optional**. The directory to run remark-lint in. Default is `.`. | ||
|
||
### remark_flags | ||
|
||
**Optional**. Additional flags you want to pass to remark-lint. Default is ` `. | ||
|
||
### `level` | ||
|
||
**Optional**. Report level for reviewdog \[info, warning, error\]. | ||
**Optional**. Report level for reviewdog \[info, warning, error]. | ||
It's same as `-level` flag of reviewdog. | ||
|
||
### `reporter` | ||
|
||
**Optional**. Reporter of reviewdog command \[github-pr-check, github-pr-review, github-check\]. | ||
**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. | ||
|
||
**NB:** Only `github-pr-check` is supported currently. | ||
|
||
#### `filter_mode` | ||
|
||
**Optional**. Filtering mode for the reviewdog command \[added, diff_context, file, nofilter\]. Default = `"added"`. | ||
**Optional**. Filtering mode for the reviewdog command \[added, diff_context, file, nofilter]. Default = `"added"`. | ||
|
||
#### `fail_on_error` | ||
|
||
**Optional**. Exit code for reviewdog when errors are found \[`true`, `false`\]. Default = `false`. | ||
**Optional**. Exit code for reviewdog when errors are found \[`true`, `false`]. Default = `false`. | ||
|
||
#### `reviewdog_flags` | ||
|
||
|
@@ -75,36 +70,75 @@ Default is github-pr-check. github-pr-review can use Markdown and add a link to | |
|
||
**Optional**. Tool name to use for reviewdog reporter. Default = `remark-lint`. | ||
|
||
## Development | ||
|
||
### Release | ||
|
||
#### [haya14busa/action-bumpr](https://github.com/haya14busa/action-bumpr) | ||
## Docker input args | ||
|
||
You can bump version on merging Pull Requests with specific labels (bump:major,bump:minor,bump:patch). | ||
Pushing tag manually by yourself also work. | ||
Besides the aforementioned input arguments you can also supply additional input arguments for the remark-lint linter using the args keyword [run.args](https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions#runsargs). | ||
|
||
#### [haya14busa/action-update-semver](https://github.com/haya14busa/action-update-semver) | ||
|
||
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> | ||
|
||
### Lint - reviewdog integration | ||
|
||
This reviewdog action template itself is integrated with reviewdog to run lints | ||
which is useful for Docker container based actions. | ||
```yaml | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: ". --verbose" | ||
``` | ||
|
||
 | ||
## 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
- [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 | ||
|
||
[](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 | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,62 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
set -e # Exit immediately if a command exits with a non-zero status | ||
|
||
if [ -n "${GITHUB_WORKSPACE}" ] ; then | ||
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit | ||
if [[ -n "${GITHUB_WORKSPACE}" ]]; then | ||
cd "${GITHUB_WORKSPACE}" || exit | ||
fi | ||
|
||
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" | ||
|
||
remark --frail --quiet --use=remark-preset-lint-recommended . ${INPUT_REMARK_FLAGS} 2>&1 | | ||
sed 's/\x1b\[[0-9;]*m//g' | # Removes ansi codes see https://github.com/reviewdog/errorformat/issues/51 | ||
reviewdog -f=remark-lint \ | ||
-name="${INPUT_TOOL_NAME}" \ | ||
-reporter="${INPUT_REPORTER:-github-pr-check}"\ | ||
-filter-mode="${INPUT_FILTER_MODE}" \ | ||
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \ | ||
-level="${INPUT_LEVEL}" \ | ||
-tee \ | ||
${INPUT_REVIEWDOG_FLAGS} | ||
# If no arguments are given use current working directory | ||
if [[ "$#" -eq 0 ]]; then | ||
remark_args="." | ||
else | ||
remark_args="$*" | ||
fi | ||
|
||
# Check if formatting is requested | ||
if [[ "${INPUT_FORMAT}" = 'true' ]]; then | ||
format_str="Format" | ||
format_arg="-o" | ||
else | ||
format_str="Check" | ||
format_arg="" | ||
fi | ||
|
||
# Run black with reviewdog | ||
remark_lint_error="false" | ||
reviewdog_error="false" | ||
if [[ "${INPUT_ANNOTATE}" = 'true' ]]; then | ||
echo "[action-remark-lint] ${format_str} markdown code using the remark-lint linter..." | ||
remark --frail --quiet --use=remark-preset-lint-recommended "${format_arg}" "${INPUT_WORKDIR}/${remark_args}" 2>&1 | | ||
sed 's/\x1b\[[0-9;]*m//g' | # Removes ansi codes see https://github.com/reviewdog/errorformat/issues/51 | ||
reviewdog -f=remark-lint \ | ||
-name="${INPUT_TOOL_NAME}" \ | ||
-reporter="${INPUT_REPORTER}" \ | ||
-filter-mode="${INPUT_FILTER_MODE}" \ | ||
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \ | ||
-level="${INPUT_LEVEL}" \ | ||
-tee \ | ||
${INPUT_REVIEWDOG_FLAGS} || reviewdog_error="true" | ||
remark_exit_val="${PIPESTATUS[0]}" | ||
if [[ "${remark_exit_val}" -ne "0" ]]; then | ||
remark_lint_error="true" | ||
elif [[ "${remark_exit_val}" -eq "0" && "${INPUT_FORMAT}" = 'true' ]]; then | ||
echo "[action-remark-lint] Formatting not needed." | ||
fi | ||
else | ||
echo "[action-remark-lint] ${format_str} markdown code using the remark-lint linter..." | ||
remark --frail --quiet \ | ||
--use=remark-preset-lint-recommended "${format_arg}" "${INPUT_WORKDIR}/${remark_args}" 2>&1 || reviewdog_error="true" | ||
rickstaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
remark_exit_val="${PIPESTATUS[0]}" | ||
if [[ "${remark_exit_val}" -ne "0" ]]; then | ||
remark_lint_error="true" | ||
elif [[ "${remark_exit_val}" -eq "0" && "${INPUT_FORMAT}" = 'true' ]]; then | ||
echo "[action-remark-lint] Formatting not needed." | ||
fi | ||
fi | ||
|
||
# Throw error if an error occurred and fail_on_error is true | ||
if [[ ("${reviewdog_error}" = 'true' || "${remark_lint_error}") && "${INPUT_FAIL_ON_ERROR}" = 'true' ]]; then | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not available for this action users, but just for the developer of this action.
Can you remove it or do you think it's useful for users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haya14busa Thanks a lot for pointing this out I will try to create another way for users to add additional flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haya14busa I removed this option from the readme. The user now can supply additional arguments using the
remarks_flags
argument.