From 87effb266471e948471f21cf9e5d020c1688d060 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 22 Jun 2022 11:29:25 -0500 Subject: [PATCH 1/3] fix(gh): Don't report bad annotations for binary files Fixes #504 --- docker/entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 5dfe375..b28c6ec 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -48,6 +48,7 @@ fi log "$ ${COMMAND}" ${COMMAND} --format json | + grep '"type":"typo"' | 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" From a3c8693b45a138878905f9d2b5e7c382e65f08ed Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 22 Jun 2022 11:30:58 -0500 Subject: [PATCH 2/3] refactor(gh): Separate command from args --- docker/entrypoint.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index b28c6ec..3b5bc6c 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -34,23 +34,23 @@ fi log "typos: $(typos --version)" log "jq: $(jq --version)" -COMMAND="${CMD_NAME} ${TARGET}" +ARGS="${TARGET}" # Ignore implicit configuration files if [ "${INPUT_ISOLATED:-false}" == "true" ]; then - COMMAND+=" --isolated" + ARGS+=" --isolated" fi # Use a custom configuration file if [[ -n "${INPUT_CONFIG:-}" ]]; then - COMMAND+=" --config ${INPUT_CONFIG}" + ARGS+=" --config ${INPUT_CONFIG}" fi -log "$ ${COMMAND}" -${COMMAND} --format json | +log "$ ${CMD_NAME} ${ARGS}" +${CMD_NAME} ${ARGS} --format json | grep '"type":"typo"' | 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} +${CMD_NAME} ${ARGS} From a950dd27ffe63f9cbfcc2ab872819057685cf20d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 22 Jun 2022 11:33:54 -0500 Subject: [PATCH 3/3] refactor(gh): Pull out formatter This makes for easier local testing. --- docker/Dockerfile | 1 + docker/entrypoint.sh | 9 +++------ docker/format_gh.sh | 9 +++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100755 docker/format_gh.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index c2c5980..70852ae 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,5 +6,6 @@ RUN wget https://github.com/crate-ci/typos/releases/download/v${VERSION}/typos-v tar -xzvf typos-v${VERSION}-x86_64-unknown-linux-musl.tar.gz && \ mv typos /usr/local/bin COPY entrypoint.sh /entrypoint.sh +COPY format_gh.sh /format_gh.sh WORKDIR /github/workspace ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 3b5bc6c..44ddb84 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,6 +2,8 @@ set -eu +SOURCE_DIR="$(dirname -- ${BASH_SOURCE[0]:-$0})"; + log() { echo -e "$1" >&2 } @@ -47,10 +49,5 @@ if [[ -n "${INPUT_CONFIG:-}" ]]; then fi log "$ ${CMD_NAME} ${ARGS}" -${CMD_NAME} ${ARGS} --format json | - grep '"type":"typo"' | - 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 +${CMD_NAME} ${ARGS} --format json | ${SOURCE_DIR}/format_gh.sh || true ${CMD_NAME} ${ARGS} diff --git a/docker/format_gh.sh b/docker/format_gh.sh new file mode 100755 index 0000000..b136160 --- /dev/null +++ b/docker/format_gh.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -eu + +grep '"type":"typo"' | + 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