-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,850 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# IDE | ||
.vscode | ||
*.code-workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Changelog | ||
|
||
All notable changes to this project will be documented in this file. Dates are displayed in UTC. | ||
|
||
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM prologic/remark-lint:latest | ||
|
||
ENV REVIEWDOG_VERSION=v0.11.0-nightly20201213+85edbc6 | ||
|
||
RUN apk add --no-cache bash git | ||
|
||
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 | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,148 @@ | ||
# Action remark-lint | ||
# Reviewdog/action-remark-lint GitHub Action | ||
|
||
[](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3ATest) | ||
[](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) | ||
|
||
 | ||
 | ||
|
||
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 | ||
|
||
```yml | ||
name: reviewdog | ||
on: [pull_request] | ||
jobs: | ||
remark-lint: | ||
name: runner / remark-lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: remark-lint | ||
uses: reviewdog/action-remark-lint@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
reporter: github-pr-check # Change reporter. (Only `github-pr-check` is supported at the moment). | ||
``` | ||
See the Inputs section below for details on the defaults and optional configuration settings. | ||
## Inputs | ||
### `github_token` | ||
|
||
**Required**. Must be in form of `github_token: ${{ secrets.github_token }}`'. | ||
|
||
### `workdir` | ||
|
||
**Optional**. The directory to run remark-lint in. Defaults to `.`. | ||
|
||
### `format` | ||
|
||
**Optional**. If true, remark-lint format files and commit are creatable (use other Action). Defaults to `false`. | ||
|
||
#### `fail_on_error` | ||
|
||
**Optional**. Exit code for when remark-lint errors are found \[`true`, `false`]. Defaults to `false`. This is different than the remark-lint `--frail` argument, which specifies whether remark exits with an exit code of `1` if remark warnings are found. | ||
|
||
#### `remark_flags` | ||
|
||
**Optional**. Additional remark-lint flags. Defaults to `""`. | ||
|
||
### `annotate` | ||
|
||
**Optional**. Annotate remark-lint changes using reviewdog. Defaults to `true`. | ||
|
||
#### `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. github-pr-review can use Markdown and add a link to rule page in reviewdog reports. | ||
|
||
### `filter_mode` | ||
|
||
**Optional**. Filtering mode for the reviewdog command \[added, diff_context, file, nofilter]. Defaults to `"added"`. | ||
|
||
### `reviewdog_flags` | ||
|
||
**Optional**. Additional reviewdog flags. Defaults to `""`. | ||
|
||
## Outputs | ||
|
||
### `is_formatted` | ||
|
||
Whether the files were formatted using the remark-lint linter. | ||
|
||
## Advance use cases | ||
|
||
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. | ||
|
||
### Commit changes | ||
|
||
```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" | ||
``` | ||
|
||
### Create pull request | ||
|
||
```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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: "Run remark-lint" | ||
description: "Run remark-lint on your codebase to improve code review experience." | ||
author: "Rick Staa" | ||
inputs: | ||
remark_args: | ||
description: "Remark-lint input arguments." | ||
required: false | ||
default: "" | ||
fail_on_error: | ||
description: | | ||
Exit code when remark-lint linting errors are found [true, false]. Defaults to 'true'. | ||
required: false | ||
default: "true" | ||
outputs: | ||
is_formatted: | ||
description: "Whether the files were formatted using the black linter." | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" | ||
branding: | ||
icon: "zoom-in" | ||
color: "purple" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/bash | ||
set -eu # Increase bash strictness | ||
set -o pipefail | ||
|
||
# If no arguments are given use current working directory | ||
remark_args=(".") | ||
if [[ "$#" -eq 0 && "${INPUT_REMARK_FLAGS}" != "" ]]; then | ||
remark_args+=(${INPUT_REMARK_FLAGS}) | ||
elif [[ "$#" -ne 0 && "${INPUT_REMARK_FLAGS}" != "" ]]; then | ||
remark_args+=($* ${INPUT_REMARK_FLAGS}) | ||
elif [[ "$#" -ne 0 && "${INPUT_REMARK_FLAGS}" == "" ]]; then | ||
remark_args+=($*) | ||
else | ||
# Default (if no args provided). | ||
remark_args+=("--frail" "--quiet") | ||
fi | ||
|
||
# Check if formatting was requested | ||
regex='(\s+-[a-zA-Z]*o[a-zA-Z]*\s?|--output)' | ||
if [[ "${remark_args[*]}" =~ $regex ]]; then | ||
formatting="true" | ||
remark_print_str="Formatting" | ||
else | ||
formatting="false" | ||
remark_print_str="Checking" | ||
fi | ||
|
||
remark_exit_val="0" | ||
echo "[action-remark-lint] Checking ${remark_print_str} code using the remark-lint linter and reviewdog..." | ||
remark_lint_output="$(remark --use=remark-preset-lint-recommended ${remark_args[*]} 2>&1)" || | ||
remark_exit_val="$?" | ||
echo "${remark_lint_output}" | ||
|
||
# Check for remark-lint errors | ||
if [[ "${formatting}" != "true" ]]; then | ||
echo "::set-output name=is_formatted::false" | ||
if [[ "${remark_exit_val}" -eq "0" ]]; then | ||
remark_error="false" | ||
elif [[ "${remark_exit_val}" -eq "1" ]]; then | ||
remark_error="true" | ||
else | ||
echo "[action-remark-lint] ERROR: Something went wrong while trying to run the" \ | ||
"remark-lint linter (error code: ${remark_exit_val})." | ||
exit 1 | ||
fi | ||
else | ||
|
||
# Check if remark-lint linter formatted files | ||
# Note: We use git since parsing wont help if the user supplied the '-s' or '-q' flags | ||
changed_files=$(git status --porcelain | grep .md | wc -l) | ||
if [[ ${changed_files} -eq 0 ]]; then | ||
echo "::set-output name=is_formatted::false" | ||
else | ||
echo "::set-output name=is_formatted::true" | ||
fi | ||
|
||
# Check remark-lint error | ||
if [[ "${remark_exit_val}" -eq "0" ]]; then | ||
remark_error="false" | ||
elif [[ "${remark_exit_val}" -eq "1" ]]; then | ||
remark_error="true" | ||
else | ||
echo "::set-output name=is_formatted::false" | ||
echo "[action-remark-lint] ERROR: Something went wrong while trying to run the" \ | ||
"remark-lint linter (error code: ${remark_exit_val})." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Throw error if an error occurred and fail_on_error is true | ||
if [[ "${INPUT_FAIL_ON_ERROR,,}" = 'true' && "${remark_error}" = 'true' ]]; then | ||
exit 1 | ||
fi |
Oops, something went wrong.