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

init #2

Merged
merged 10 commits into from
Jun 15, 2024
Merged
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
11 changes: 11 additions & 0 deletions .github/workflows/depup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ jobs:
version_name: reviewdog_version
repo: reviewdog/reviewdog
labels: "bump:minor"

typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: reviewdog/action-depup/with-pr@v1
with:
file: script.sh
version_name: TYPOS_VERSION
repo: crate-ci/typos/
labels: "bump:minor"
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ on:
branches:
- main
pull_request:
# TODO: replace `<linter-name>` with yours
jobs:
test-check:
name: runner / <linter-name> (github-check)
name: runner / typos (github-check)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -16,11 +15,10 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: info
locale: "US"

test-pr-check:
if: github.event_name == 'pull_request'
name: runner / <linter-name> (github-pr-check)
name: runner / typos (github-pr-check)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -29,12 +27,11 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
level: warning
locale: "US"
workdir: ./testdata/subdir/

test-pr-review:
if: github.event_name == 'pull_request'
name: runner / <linter-name> (github-pr-review)
name: runner / typos (github-pr-review)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -44,7 +41,6 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
locale: "US"
filter_mode: file
fail_on_error: true
- name: check the exit code
Expand Down
56 changes: 17 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
# action-composite-template

<!-- TODO: replace reviewdog/action-composite-template with your repo name -->
[![Test](https://github.com/reviewdog/action-composite-template/workflows/Test/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/reviewdog/action-composite-template/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/reviewdog/action-composite-template/workflows/depup/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3Adepup)
[![release](https://github.com/reviewdog/action-composite-template/workflows/release/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-composite-template?logo=github&sort=semver)](https://github.com/reviewdog/action-composite-template/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-review demo](https://user-images.githubusercontent.com/3797062/73162963-4b8e2b00-4132-11ea-9a3f-f9c6f624c79f.png)
![github-pr-check demo](https://user-images.githubusercontent.com/3797062/73163032-70829e00-4132-11ea-8481-f213a37db354.png)
# action-typos

<!-- TODO: outline your action here -->
This is a template repository for
[reviewdog](https://github.com/reviewdog/reviewdog) action with release
automation based on [action composition](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action).
Click `Use this template` button to create your reviewdog action :dog:!
[![Test](https://github.com/reviewdog/action-typos/workflows/Test/badge.svg)](https://github.com/reviewdog/action-typos/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/reviewdog/action-typos/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-typos/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/reviewdog/action-typos/workflows/depup/badge.svg)](https://github.com/reviewdog/action-typos/actions?query=workflow%3Adepup)
[![release](https://github.com/reviewdog/action-typos/workflows/release/badge.svg)](https://github.com/reviewdog/action-typos/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-typos?logo=github&sort=semver)](https://github.com/reviewdog/action-typos/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)

If you want to create your own reviewdog action from scratch without using this
template, please check and copy release automation flow.
It's important to manage release workflow and sync reviewdog version for all
reviewdog actions.
![github-pr-review demo](https://github.com/reviewdog/action-typos/assets/3797062/c1870265-079c-477e-96af-92683bc1998c)

This repo contains a sample action to run [misspell](https://github.com/client9/misspell).
This action runs [crate-ci/typos](https://github.com/crate-ci/typos) with reviewdog on pull requests to improve code review experience.
You can include suggested typo fix as shown the above example.

## Input

<!-- TODO: replace `<linter-name>` with yours -->
```yaml
inputs:
github_token:
Expand All @@ -38,13 +25,13 @@ inputs:
### Flags for reviewdog ###
tool_name:
description: 'Tool name to use for reviewdog reporter.'
default: '<linter-name>'
default: 'typos'
level:
description: 'Report level for reviewdog [info,warning,error].'
default: 'error'
reporter:
description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].'
default: 'github-check'
default: 'github-pr-review'
filter_mode:
description: |
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
Expand All @@ -58,33 +45,24 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags.'
default: ''
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
### Flags for typos ###
typos_flags:
description: 'flags for typos'
default: ''
```

## Usage
<!-- TODO: replace reviewdog/action-composite-template with your repo name -->

```yaml
name: reviewdog
on: [pull_request]
jobs:
# TODO: replace `linter_name` and `<linter-name>` with yours
linter_name:
name: runner / <linter-name>
name: runner / typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: reviewdog/action-composite-template@v1
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-check,github-pr-review,github-pr-check].
reporter: github-pr-review
# Change reporter level if you need.
# GitHub Status Check won't become failure with warning.
level: warning
- uses: reviewdog/actions-typos@v1
```

## Development
Expand Down
20 changes: 9 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# TODO: replace `<linter-name>` and `<your-name>` with yours
name: 'Run <linter-name> with reviewdog'
description: '🐶 Run <linter-name> with reviewdog on pull requests to improve code review experience.'
author: '<your-name>'
name: 'Run typos with reviewdog'
description: '🐶 Run typos with reviewdog on pull requests to improve code review experience.'
author: 'haya14busa'
inputs:
github_token:
description: 'GITHUB_TOKEN'
Expand All @@ -12,13 +11,13 @@ inputs:
### Flags for reviewdog ###
tool_name:
description: 'Tool name to use for reviewdog reporter.'
default: '<linter-name>'
default: 'typos'
level:
description: 'Report level for reviewdog [info,warning,error].'
default: 'error'
reporter:
description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].'
default: 'github-check'
default: 'github-pr-review'
filter_mode:
description: |
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
Expand All @@ -32,9 +31,9 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags.'
default: ''
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
### Flags for typos ###
typos_flags:
description: 'flags for typos'
default: ''
runs:
using: 'composite'
Expand All @@ -55,10 +54,9 @@ runs:
INPUT_FILTER_MODE: ${{ inputs.filter_mode }}
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }}
INPUT_LOCALE: ${{ inputs.locale }}
INPUT_TYPOS_FLAGS: ${{ inputs.typos_flags }}

# Ref: https://haya14busa.github.io/github-action-brandings/
# TODO: update branding if you want.
branding:
icon: 'check'
color: 'blue'
16 changes: 11 additions & 5 deletions script.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
#!/bin/sh
set -e

TYPOS_VERSION=v1.22.7

if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
fi

export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

echo '::group::🐶 Installing misspell ... https://github.com/client9/misspell'
echo '::group::🐶 Installing typos ... https://github.com/crate-ci/typos'
TEMP_PATH="$(mktemp -d)"
PATH="${TEMP_PATH}:$PATH"
wget -O - -q https://git.io/misspell | sh -s -- -b "${TEMP_PATH}"
wget -O - -q https://raw.githubusercontent.com/crate-ci/gh-install/057430d007bc58dc624003c9af8ff9cf1f747c66/v1/install.sh |
sh -s -- --tag "${TYPOS_VERSION}" --git crate-ci/typos --target x86_64-unknown-linux-musl --to "${TEMP_PATH}"
echo '::endgroup::'

echo '::group:: Running misspell with reviewdog 🐶 ...'
echo '::group:: Running typos with reviewdog 🐶 ...'
# shellcheck disable=SC2086
misspell -locale="${INPUT_LOCALE}" . |
reviewdog -efm="%f:%l:%c: %m" \
typos ${INPUT_TYPOS_FLAGS} --format json |
jq -f "${GITHUB_ACTION_PATH}/to-rdjsonl.jq" -c |
reviewdog \
-f="rdjsonl" \
-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}
exit_code=$?
echo '::endgroup::'
Expand Down
8 changes: 7 additions & 1 deletion testdata/text.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Determinisitic result is important.
Determinisitic result is important!

Check notice on line 1 in testdata/text.md

View workflow job for this annotation

GitHub Actions / typos

[typos] testdata/text.md#L1

Typo: Determinisitic -> Deterministic
Raw output
{"message":"Typo: Determinisitic -> Deterministic","location":{"path":"./testdata/text.md","range":{"start":{"line":1,"column":1},"end":{"line":1,"column":15}}},"suggestions":[{"text":"Deterministic","range":{"start":{"line":1,"column":1},"end":{"line":1,"column":15}}}]}

Check warning on line 1 in testdata/text.md

View workflow job for this annotation

GitHub Actions / misspell

[misspell] testdata/text.md#L1

"Determinisitic" is a misspelling of "Deterministic"
Raw output
./testdata/text.md:1:0: "Determinisitic" is a misspelling of "Deterministic"
Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: Determinisitic -> Deterministic

Suggested change
Determinisitic result is important!
Deterministic result is important!


colour # <= Check -locale

langauge
Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: langauge -> language

Suggested change
langauge
languagee

Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: langauge -> language

Suggested change
langauge
language


varius

Check notice on line 7 in testdata/text.md

View workflow job for this annotation

GitHub Actions / typos

[typos] testdata/text.md#L7

Typo: varius -> various
Raw output
{"message":"Typo: varius -> various","location":{"path":"./testdata/text.md","range":{"start":{"line":7,"column":1},"end":{"line":7,"column":7}}},"suggestions":[{"text":"various","range":{"start":{"line":7,"column":1},"end":{"line":7,"column":7}}}]}
Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: varius -> various

Suggested change
varius
variouss

Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: varius -> various

Suggested change
varius
various


A abd B

Check notice on line 9 in testdata/text.md

View workflow job for this annotation

GitHub Actions / typos

[typos] testdata/text.md#L9

Typo: abd -> and
Raw output
{"message":"Typo: abd -> and","location":{"path":"./testdata/text.md","range":{"start":{"line":9,"column":3},"end":{"line":9,"column":6}}},"suggestions":[{"text":"and","range":{"start":{"line":9,"column":3},"end":{"line":9,"column":6}}}]}
Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: abd -> and

Suggested change
A abd B
A andd B

Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: abd -> and

Suggested change
A abd B
A and B


It SHOUL be A

Check notice on line 11 in testdata/text.md

View workflow job for this annotation

GitHub Actions / typos

[typos] testdata/text.md#L11

Typo: SHOUL -> SHOULD, SHAWL, SHOAL
Raw output
{"message":"Typo: SHOUL -> SHOULD, SHAWL, SHOAL","location":{"path":"./testdata/text.md","range":{"start":{"line":11,"column":4},"end":{"line":11,"column":9}}},"suggestions":[{"text":"SHOULD","range":{"start":{"line":11,"column":4},"end":{"line":11,"column":9}}},{"text":"SHAWL","range":{"start":{"line":11,"column":4},"end":{"line":11,"column":9}}},{"text":"SHOAL","range":{"start":{"line":11,"column":4},"end":{"line":11,"column":9}}}]}
Copy link
Contributor

Choose a reason for hiding this comment

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

[typos] reported by reviewdog 🐶
Typo: SHOUL -> SHOULD, SHAWL, SHOAL

Suggested change
It SHOUL be A
It SHOULD be A
Suggested change
It SHOUL be A
It SHAWL be A
Suggested change
It SHOUL be A
It SHOAL be A

22 changes: 22 additions & 0 deletions to-rdjsonl.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
. as $item |
if .type == "typo" then
{
"message": ("Typo: " + .typo + " -> " + (.corrections | join(", "))),
"location": {
"path": .path,
"range": {
"start": { "line": .line_num, "column": (.byte_offset + 1) },
"end": { "line": .line_num, "column": (.byte_offset + (.typo | length) + 1) }
}
},
"suggestions": .corrections | map({
"text": .,
"range": {
"start": { "line": $item.line_num, "column": ($item.byte_offset + 1) },
"end": { "line": $item.line_num, "column": ($item.byte_offset + ($item.typo | length) + 1) }
}
})
}
else
empty
end
Loading