Merge pull request #501 from epage/action

feat(action): Report typos as annotations
This commit is contained in:
Ed Page 2022-06-16 13:50:27 -05:00 committed by GitHub
commit e1c19af197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 2 deletions

View file

@ -2,7 +2,7 @@ name: Test GitHub Action
on: [pull_request] on: [pull_request]
jobs: jobs:
run: shallow:
name: Spell Check with Typos name: Spell Check with Typos
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -23,3 +23,27 @@ jobs:
uses: ./ uses: ./
with: with:
files: ./file.txt 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
View 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]

View file

@ -1,7 +1,7 @@
FROM ubuntu:20.04 FROM ubuntu:20.04
ARG VERSION=1.9.0 ARG VERSION=1.9.0
ENV VERSION=${VERSION} 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 && \ 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 && \ tar -xzvf typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz && \
mv typos /usr/local/bin mv typos /usr/local/bin

View file

@ -8,6 +8,20 @@ log() {
CMD_NAME="typos" CMD_NAME="typos"
TARGET=${INPUT_FILES:-"."} 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 if [[ -z $(ls ${TARGET} 2>/dev/null) ]]; then
log "ERROR: Input files (${TARGET}) not found" 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" log "ERROR: 'typos' not found"
exit 1 exit 1
fi fi
log "typos: $(typos --version)"
log "jq: $(jq --version)"
COMMAND="${CMD_NAME} ${TARGET}" COMMAND="${CMD_NAME} ${TARGET}"
@ -31,4 +47,9 @@ if [[ -n "${INPUT_CONFIG:-}" ]]; then
fi fi
log "$ ${COMMAND}" 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} ${COMMAND}