From d37c3ff782b0b22d34bd989aa2079d7022c6d134 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 11:06:10 -0500 Subject: [PATCH 1/7] test: Cactch YAML mistakes --- .pre-commit-config.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .pre-commit-config.yaml 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] From bed511b57ab1dccd478ebc610539aa38870e405f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 10:53:59 -0500 Subject: [PATCH 2/7] test(action): Verify with and without history --- .github/workflows/test-action.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 From fc7f51746699c0dacd6a3c2a8f594a18c1726336 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 10:09:50 -0500 Subject: [PATCH 3/7] perf(action): Limit checked files to those changed --- docker/Dockerfile | 2 +- docker/entrypoint.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5122bc92..f94c3d32 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 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..8e16d3ca 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -8,6 +8,15 @@ log() { CMD_NAME="typos" TARGET=${INPUT_FILES:-"."} +if [[ -n "${GITHUB_BASE_REF:-}" ]]; then + git config --global --add safe.directory /github/workspace + if git rev-parse --verify master 2>/dev/null ; then + log "Limiting checks to ${GITHUB_BASE_REF}...HEAD" + TARGET=$(git diff ${GITHUB_BASE_REF}...HEAD --name-only --diff-filter=AM -- ${TARGET}) + else + log "WARN: Not limiting checks to ${GITHUB_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" From 2ae4d92451c9147a6384dbc6b45eb386dbc89fd5 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 10:18:42 -0500 Subject: [PATCH 4/7] feat(action): Report typos to github --- docker/Dockerfile | 2 +- docker/entrypoint.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index f94c3d32..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 git +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 8e16d3ca..604e4519 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -40,4 +40,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} From 02fb35d0ebdf7ec3b12fc9e9216829e0f8e36774 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 11:12:15 -0500 Subject: [PATCH 5/7] fix(action): Log program versions --- docker/entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 604e4519..85c6b48a 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -26,6 +26,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}" From a295aeb9ace9a285f852eec31045dd98f3be56c7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 13:08:37 -0500 Subject: [PATCH 6/7] fix(action): Filter files in more cases --- docker/entrypoint.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 85c6b48a..d89f50d4 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -9,12 +9,13 @@ 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 master 2>/dev/null ; then + if git rev-parse --verify ${BASE_REF} 2>/dev/null ; then log "Limiting checks to ${GITHUB_BASE_REF}...HEAD" - TARGET=$(git diff ${GITHUB_BASE_REF}...HEAD --name-only --diff-filter=AM -- ${TARGET}) + TARGET=$(git diff ${BASE_REF}...HEAD --name-only --diff-filter=AM -- ${TARGET}) else - log "WARN: Not limiting checks to ${GITHUB_BASE_REF}...HEAD, ${GITHUB_BASE_REF} is not available" + log "WARN: Not limiting checks to ${BASE_REF}...HEAD, ${GITHUB_BASE_REF} is not available" fi fi From 4df83719b27afc591c601906f9fe7d0eadc149ac Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 16 Jun 2022 13:40:37 -0500 Subject: [PATCH 7/7] fix(action): Don't check all when no checked files are changed --- docker/entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d89f50d4..5dfe375d 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -14,6 +14,10 @@ if [[ -n "${GITHUB_BASE_REF:-}" ]]; then 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