Skip to content

Commit 33a4a98

Browse files
authored
Update common github actions (#93)
Signed-off-by: Matt Moore (via Sockpuppet) <[email protected]>
1 parent 6310b3d commit 33a4a98

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

.github/workflows/knative-style.yaml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ jobs:
4040
importpath: golang.org/x/tools/cmd/goimports
4141

4242
steps:
43-
4443
- name: Set up Go 1.15.x
4544
uses: actions/setup-go@v2
4645
with:
@@ -198,6 +197,40 @@ jobs:
198197
199198
echo '::endgroup::'
200199
200+
- name: Redundant Format
201+
shell: bash
202+
if: ${{ always() }}
203+
env:
204+
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
205+
run: |
206+
set -e
207+
cd "${GITHUB_WORKSPACE}" || exit 1
208+
209+
echo '::group:: Flagging possibly unnecessary format calls for trailing argument with reviewdog 🐶 ...'
210+
# Don't fail because of misspell
211+
set +o pipefail
212+
# For all look for formatting calls and extract the ones that
213+
# have only a single formatting argument and that argument is in the last position.
214+
# But exclude the `fmt.Errorf` calls since there's no `fmt.Error` and `errors.New` is not
215+
# as versatile.
216+
# Also ignore `%T` — to print the type and `%q` to quote the final string.
217+
fn=$(find . -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
218+
grep -nE '[^.]+\.(Fatalf|Errorf|Warnf|Infof|Debugf)[^\%]+%[^Tq]",[^,]+' $fn | grep -v "fmt.Errorf" |
219+
while read -r ent ; do
220+
file=$(echo $ent | cut -d':' -f 1);
221+
line=$(echo $ent | cut -d':' -f 2);
222+
ch=$(echo $ent | cut -d':' -f3-);
223+
err=$(echo $ch | sed -E 's/([^.]+\.)(Fatal|Error|Warn|Info|Debug)f([^\%]+)(%[^wq]",)([^,]+)/\1\2\3",\5/');
224+
echo "$file:$line: Please consider avoiding tail format like this:%0A$err"
225+
done |
226+
reviewdog -efm="%f:%l: %m" \
227+
-name="Redundant Format" \
228+
-reporter="github-pr-check" \
229+
-filter-mode="added" \
230+
-fail-on-error="true" \
231+
-level="error"
232+
echo '::endgroup::'
233+
201234
# This is mostly copied from https://github.com/get-woke/woke-action-reviewdog/blob/main/entrypoint.sh
202235
# since their action is not yet released under a stable version.
203236
- name: Language

0 commit comments

Comments
 (0)