@@ -19,7 +19,7 @@ name: Code Style
1919
2020on :
2121 pull_request :
22- branches : [ 'master', 'release-*' ]
22+ branches : [ 'main', ' master', 'release-*' ]
2323
2424jobs :
2525
@@ -209,54 +209,6 @@ jobs:
209209
210210 echo '::endgroup::'
211211
212- - name : Redundant Format
213- shell : bash
214- if : ${{ always() }}
215- env :
216- REVIEWDOG_GITHUB_API_TOKEN : ${{ github.token }}
217- run : |
218- set -e
219- cd "${GITHUB_WORKSPACE}" || exit 1
220-
221- echo '::group:: Flagging possibly unnecessary format calls for trailing argument with reviewdog 🐶 ...'
222- # Don't fail because of misspell
223- set +o pipefail
224- # For all look for formatting calls and extract the ones that
225- # have only a single formatting argument and that argument is in the last position.
226- # But exclude the `fmt.Errorf` calls since there's no `fmt.Error` and `errors.New` is not
227- # as versatile.
228- # Also ignore `%T` — to print the type and `%q` to quote the final string.
229- fn=$(find . -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
230- grep -nE '[^.]+\.(Fatalf|Errorf|Warnf|Infof|Debugf|Logf|Sprintf|Fprintf|Printf)[^\%]+%[^Tqx]",[^,]+' $fn | grep -v "fmt.Errorf" |
231- while read -r ent ; do
232- file=$(echo $ent | cut -d':' -f 1);
233- line=$(echo $ent | cut -d':' -f 2);
234- ch=$(echo $ent | cut -d':' -f3-);
235- err="Unknown printer tool, please file an issue in knative-sandbox/.github and assign to @vagababov: $ch"
236- if echo $ch | grep --quiet -E "^t.(Errorf|Fatalf|Logf)" ; then
237- err=$(echo $ch | sed -E 's/(^t\.)(Fatal|Error|Log)f([^\%]+)( %[^Tqx]",)([^,]+)/\1\2\3",\5/')
238- # Not a test. Here we deal with various loggers and fmt helpers.
239- elif echo $ch | grep --quiet "log" ; then
240- # Capture (x)?log(er)?.
241- err=$(echo $ch | sed -E 's/(.*log.*\.)(Print|Fatal|Error|Info|Warn)f([^\%]+)(%[^Tq]",)([^,]+)/\1\2\3",\5/')
242- elif echo $ch | grep --quiet -E "fmt\.Sprintf" ; then
243- # Always space after sprintf
244- err=$(echo $ch | sed -E 's/(fmt\.)(Sprint)f([^%]+) (%s",)([^,]+)/\1\2\3 ",\5/')
245- elif echo $ch | grep --quiet -E "fmt\." ; then # all other fmt. printers.
246- err=$(echo $ch | sed -E 's/(fmt\.)(Print|Fprint)f([^%]+) (%[^sTxq]",)([^,]+)/\1\2\3",\5/')
247- fi
248- # Trim spaces.
249- ch=$(echo $ch | xargs)
250- echo "$file:$line: Please consider avoiding tail format like this:%0A- $ch%0A+ $err"
251- done |
252- reviewdog -efm="%f:%l: %m" \
253- -name="Redundant Format" \
254- -reporter="github-pr-check" \
255- -filter-mode="added" \
256- -fail-on-error="true" \
257- -level="error"
258- echo '::endgroup::'
259-
260212 # This is mostly copied from https://github.com/get-woke/woke-action-reviewdog/blob/main/entrypoint.sh
261213 # since their action is not yet released under a stable version.
262214 - name : Language
0 commit comments