mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
Merge pull request #501 from epage/action
feat(action): Report typos as annotations
This commit is contained in:
commit
e1c19af197
4 changed files with 63 additions and 2 deletions
26
.github/workflows/test-action.yml
vendored
26
.github/workflows/test-action.yml
vendored
|
@ -2,7 +2,7 @@ name: Test GitHub Action
|
|||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
shallow:
|
||||
name: Spell Check with Typos
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -23,3 +23,27 @@ jobs:
|
|||
uses: ./
|
||||
with:
|
||||
files: ./file.txt
|
||||
|
||||
deep:
|
||||
name: Spell Check with Type w/History
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Actions Repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Prepare file with mistakes.
|
||||
run: echo "Finallizes" > file.txt
|
||||
- name: Test force pass with mistakes
|
||||
continue-on-error: true
|
||||
uses: ./
|
||||
with:
|
||||
files: ./file.txt
|
||||
|
||||
- name: Prepare file with no mistakes.
|
||||
run: echo "Finalizes" > file.txt
|
||||
- name: Test pass with no mistakes
|
||||
uses: ./
|
||||
with:
|
||||
files: ./file.txt
|
||||
|
|
16
.pre-commit-config.yaml
Normal file
16
.pre-commit-config.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
stages: [commit]
|
||||
- id: check-json
|
||||
stages: [commit]
|
||||
- id: check-toml
|
||||
stages: [commit]
|
||||
- id: check-merge-conflict
|
||||
stages: [commit]
|
||||
- id: check-case-conflict
|
||||
stages: [commit]
|
||||
- id: detect-private-key
|
||||
stages: [commit]
|
|
@ -1,7 +1,7 @@
|
|||
FROM ubuntu:20.04
|
||||
ARG VERSION=1.9.0
|
||||
ENV VERSION=${VERSION}
|
||||
RUN apt-get update && apt-get install -y wget
|
||||
RUN apt-get update && apt-get install -y wget git jq
|
||||
RUN wget https://github.com/crate-ci/typos/releases/download/v${VERSION}/typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz && \
|
||||
tar -xzvf typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz && \
|
||||
mv typos /usr/local/bin
|
||||
|
|
|
@ -8,6 +8,20 @@ log() {
|
|||
|
||||
CMD_NAME="typos"
|
||||
TARGET=${INPUT_FILES:-"."}
|
||||
if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
|
||||
BASE_REF=HEAD~ # HACK: GITHUB_BASE_REF is failing the `--verify` but `HEAD~ should be the same for pull requests
|
||||
git config --global --add safe.directory /github/workspace
|
||||
if git rev-parse --verify ${BASE_REF} 2>/dev/null ; then
|
||||
log "Limiting checks to ${GITHUB_BASE_REF}...HEAD"
|
||||
TARGET=$(git diff ${BASE_REF}...HEAD --name-only --diff-filter=AM -- ${TARGET})
|
||||
if [[ -z "${TARGET:-}" ]]; then
|
||||
log "INPUT_FILES are unchanged"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
log "WARN: Not limiting checks to ${BASE_REF}...HEAD, ${GITHUB_BASE_REF} is not available"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $(ls ${TARGET} 2>/dev/null) ]]; then
|
||||
log "ERROR: Input files (${TARGET}) not found"
|
||||
|
@ -17,6 +31,8 @@ if [[ -z $(which ${CMD_NAME} 2>/dev/null) ]]; then
|
|||
log "ERROR: 'typos' not found"
|
||||
exit 1
|
||||
fi
|
||||
log "typos: $(typos --version)"
|
||||
log "jq: $(jq --version)"
|
||||
|
||||
COMMAND="${CMD_NAME} ${TARGET}"
|
||||
|
||||
|
@ -31,4 +47,9 @@ if [[ -n "${INPUT_CONFIG:-}" ]]; then
|
|||
fi
|
||||
|
||||
log "$ ${COMMAND}"
|
||||
${COMMAND} --format json |
|
||||
jq --sort-keys --raw-output '"::warning file=\(.path),line=\(.line_num),col=\(.byte_offset)::\"\(.typo)\" should be \"" + (.corrections // [] | join("\" or \"") + "\".")' |
|
||||
while IFS= read -r line; do
|
||||
echo "$line"
|
||||
done || true
|
||||
${COMMAND}
|
||||
|
|
Loading…
Reference in a new issue