diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index 8f898e2..e7749ed 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -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" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43a038a..c6dfb4d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,10 +4,9 @@ on: branches: - main pull_request: -# TODO: replace `` with yours jobs: test-check: - name: runner / (github-check) + name: runner / typos (github-check) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -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 / (github-pr-check) + name: runner / typos (github-pr-check) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -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 / (github-pr-review) + name: runner / typos (github-pr-review) runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -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 diff --git a/README.md b/README.md index 720a859..9e09a8e 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,19 @@ -# action-composite-template - - -[![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 - -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 - ```yaml inputs: github_token: @@ -38,13 +25,13 @@ inputs: ### Flags for reviewdog ### tool_name: description: 'Tool name to use for reviewdog reporter.' - default: '' + 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]. @@ -58,33 +45,24 @@ inputs: reviewdog_flags: description: 'Additional reviewdog flags.' default: '' - ### Flags for ### - locale: - description: '-locale flag of misspell. (US/UK)' + ### Flags for typos ### + typos_flags: + description: 'flags for typos' default: '' ``` ## Usage - ```yaml name: reviewdog on: [pull_request] jobs: - # TODO: replace `linter_name` and `` with yours linter_name: - name: runner / + 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 diff --git a/action.yml b/action.yml index e5b099e..4b128b0 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,6 @@ -# TODO: replace `` and `` with yours -name: 'Run with reviewdog' -description: '🐶 Run with reviewdog on pull requests to improve code review experience.' -author: '' +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' @@ -12,13 +11,13 @@ inputs: ### Flags for reviewdog ### tool_name: description: 'Tool name to use for reviewdog reporter.' - default: '' + 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]. @@ -32,9 +31,9 @@ inputs: reviewdog_flags: description: 'Additional reviewdog flags.' default: '' - ### Flags for ### - locale: - description: '-locale flag of misspell. (US/UK)' + ### Flags for typos ### + typos_flags: + description: 'flags for typos' default: '' runs: using: 'composite' @@ -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' diff --git a/script.sh b/script.sh index 644fe84..44bd47e 100755 --- a/script.sh +++ b/script.sh @@ -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::' diff --git a/testdata/text.md b/testdata/text.md index 5025db8..7d27c68 100644 --- a/testdata/text.md +++ b/testdata/text.md @@ -1,5 +1,11 @@ -Determinisitic result is important. +Determinisitic result is important! colour # <= Check -locale langauge + +varius + +A abd B + +It SHOUL be A diff --git a/to-rdjsonl.jq b/to-rdjsonl.jq new file mode 100644 index 0000000..db9c116 --- /dev/null +++ b/to-rdjsonl.jq @@ -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