diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 74947f51..4695c57f 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..f777b130 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/docker/Dockerfile b/docker/Dockerfile index 5122bc92..93bfddf8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a5e0af4c..5dfe375d 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -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}