diff --git a/.github/workflows/cgo.yml b/.github/workflows/cgo.yml index 785985d5c41..109d64cf6a5 100644 --- a/.github/workflows/cgo.yml +++ b/.github/workflows/cgo.yml @@ -1371,6 +1371,45 @@ jobs: - name: Run custom linters run: make golint-custom LINTER_FLAGS="-errstringmatch -panicinlibrarycode -manualmutexunlock -osexitinlibrary -rawloginlib -logfatallibrary -regexpcompileinfunction -fprintlnsprintf -strconvparseignorederror -jsonmarshalignoredeerror -uncheckedtypeassertion -fmterrorfnoverbs -tolowerequalfold -httpnoctx -timeafterleak -errortypeassertion -execcommandwithoutcontext -sprintfint -stringsindexcontains -stringscountcontains -bytesbufferstring -ioutildeprecated -mapclearloop -mapdeletecheck -sprintfbool -appendoneelement -timenowsub -stringsjoinone -writebytestring -lenstringsplit -stringreplaceminusone -osgetenvlibrary -ossetenvlibrary -stringsindexhasprefix -contextcancelnotdeferred -ctxbackground -wgdonenotdeferred -goroutinemissingrecover -trimleftright -walkfuncerrshadow -uncheckedflushreturn -bytescomparestring -nilctxpassed -stringbytesroundtrip -fileclosenotdeferred -timesleepnocontext -sprintferrorsnew -globwalkignorederror -appendbytestring -sortslice -deferinloop -regexpdynamicpattern -test=false" + - name: Determine errormessage lint scope + id: errormessage-scope + env: + EVENT_NAME: ${{ github.event_name }} + BASE_REF: origin/${{ github.base_ref }} + BEFORE_SHA: ${{ github.event.before }} + run: | + set -euo pipefail + files="" + if [ "$EVENT_NAME" = "pull_request" ]; then + if git rev-parse --verify "$BASE_REF" >/dev/null 2>&1; then + files=$(git diff --name-only "$BASE_REF...HEAD" -- '*.go' | tr '\n' ',' | sed 's/,$//') + else + echo "Base ref $BASE_REF not found, falling back to all Go files" + files=$(git ls-files '*.go' | tr '\n' ',' | sed 's/,$//') + fi + elif [ "$EVENT_NAME" = "push" ] && [ -n "$BEFORE_SHA" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then + if git rev-parse --verify "$BEFORE_SHA^{commit}" >/dev/null 2>&1; then + # Push events compare the before and after commit trees directly; + # PR events use base...HEAD above to match GitHub's pull request diff. + files=$(git diff --name-only "$BEFORE_SHA" HEAD -- '*.go' | tr '\n' ',' | sed 's/,$//') + else + echo "Before SHA $BEFORE_SHA not found, skipping push diff" + fi + fi + + echo "files=$files" >> "$GITHUB_OUTPUT" + if [ -n "$files" ]; then + echo "linting files: $files" + else + echo "No changed Go files to lint" + fi + + - name: Run errormessage linter on changed files + if: steps.errormessage-scope.outputs.files != '' + env: + CHANGED_GO_FILES: ${{ steps.errormessage-scope.outputs.files }} + run: /tmp/gh-aw-linters -errormessage -errormessage.changed-files="$CHANGED_GO_FILES" ./... + - name: Run custom linters (wasm) run: GOOS=js GOARCH=wasm make golint-custom LINTER_FLAGS="-errstringmatch -panicinlibrarycode -manualmutexunlock -osexitinlibrary -rawloginlib -logfatallibrary -regexpcompileinfunction -fprintlnsprintf -strconvparseignorederror -jsonmarshalignoredeerror -uncheckedtypeassertion -fmterrorfnoverbs -tolowerequalfold -httpnoctx -timeafterleak -errortypeassertion -execcommandwithoutcontext -sprintfint -stringsindexcontains -stringscountcontains -bytesbufferstring -ioutildeprecated -mapclearloop -mapdeletecheck -sprintfbool -appendoneelement -timenowsub -stringsjoinone -writebytestring -lenstringsplit -stringreplaceminusone -osgetenvlibrary -ossetenvlibrary -stringsindexhasprefix -ctxbackground -wgdonenotdeferred -goroutinemissingrecover -trimleftright -walkfuncerrshadow -uncheckedflushreturn -bytescomparestring -nilctxpassed -stringbytesroundtrip -fileclosenotdeferred -timesleepnocontext -sprintferrorsnew -globwalkignorederror -appendbytestring -sortslice -deferinloop -regexpdynamicpattern -test=false" LINTER_PACKAGES="./pkg/console ./pkg/parser ./pkg/styles ./pkg/tty ./pkg/workflow" diff --git a/.github/workflows/error-message-lint.yml b/.github/workflows/error-message-lint.yml index dc048d31bd9..1548dc1edce 100644 --- a/.github/workflows/error-message-lint.yml +++ b/.github/workflows/error-message-lint.yml @@ -55,7 +55,7 @@ jobs: if: steps.changed.outputs.files != '' env: CHANGED_GO_FILES: ${{ steps.changed.outputs.files }} - run: /tmp/gh-aw-linters -errormessage.changed-files="$CHANGED_GO_FILES" ./... + run: /tmp/gh-aw-linters -errormessage -errormessage.changed-files="$CHANGED_GO_FILES" ./... - name: Check for bare fmt.Println/Printf in pkg/cli run: |