Skip to content

Commit

Permalink
✨ Adds remark-lint action
Browse files Browse the repository at this point in the history
  • Loading branch information
rickstaa committed Jan 7, 2021
1 parent b74c0fa commit e48c0f8
Show file tree
Hide file tree
Showing 10 changed files with 1,850 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# IDE
.vscode
*.code-workspace
5 changes: 5 additions & 0 deletions CHANGELOG.md
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).
14 changes: 14 additions & 0 deletions Dockerfile
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 []
149 changes: 148 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,148 @@
# Action remark-lint
# Reviewdog/action-remark-lint GitHub Action

[![Test](https://github.com/reviewdog/action-remark-lint/workflows/Test/badge.svg)](https://github.com/reviewdog/action-remark-lint/actions?query=workflow%3ATest)
[![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)

![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. 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
```
22 changes: 22 additions & 0 deletions action.yml
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"
73 changes: 73 additions & 0 deletions entrypoint.sh
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
Loading

0 comments on commit e48c0f8

Please sign in to comment.