Skip to content

Commit

Permalink
run-checks: added golangci-lint to run-checks (#14464)
Browse files Browse the repository at this point in the history
* run-checks: added golangci-lint run

* run-checks: review corrections - remove superfluous exit

* run-checks: review corrections

* run-checks: added check for go version of golangci-lint and go

* tests: added golagnci-lint skip in spread test

* run-checks: review corrections - run golangci-lint also on older go and made clearer env variable and comment

* run-checks: review corrections - allow for non-snap installation of golangci-lint

* run-checks: review corrections
  • Loading branch information
maykathm authored Sep 17, 2024
1 parent 89cf620 commit 91bc7cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GITHUB_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
BASE_REF: ${{ github.base_ref }}

strategy:
# we cache successful runs so it's fine to keep going
Expand Down Expand Up @@ -186,22 +187,9 @@ jobs:
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/c-vendor && ./vendor.sh
- name: golangci-lint
if: ${{ matrix.gochannel == 'latest/stable' }}
uses: golangci/golangci-lint-action@v3
with:
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest`
# to use the latest version
version: v1.60.1
working-directory: ./src/github.com/snapcore/snapd
# show only new issues
# use empty path prefix to make annotations work
args: --new-from-rev=${{ github.base_ref }} --path-prefix=
# skip all additional steps
skip-pkg-cache: true
skip-build-cache: true
# XXX: does no work with working-directory
# only-new-issues: true
- name: Install golangci-lint snap
run: |
sudo snap install --classic golangci-lint
- name: Get changed files
id: changed-files
Expand Down
35 changes: 35 additions & 0 deletions run-checks
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,41 @@ if [ "$STATIC" = 1 ]; then
echo "$got"
exit 1
fi

if [ -z "${SKIP_GOLANGCI_LINT-}" ]; then

echo "Checking installation of golangci-lint"
gcil="$(command -v golangci-lint || true)"
if [ -z "$gcil" ]; then
echo "ERROR: Cannot find golangci-lint. You need to first install the golangci-lint"
exit 1
fi

if echo "$gcil" | grep -q '/snap/bin/' ; then
# golangci-lint was installed from the snap
if snap refresh --list | grep -q golangci-lint; then
echo "WARNING: your golangci-lint snap is out of date. The CI will install a fresh version, which may differ from yours."
fi
if ! snap list golangci-lint | grep -q latest; then
echo "WARNING: your golangci-lint snap is not installed from the latest/* channel."
fi
fi

# Check whether golangci-lint was built with go version >= the installed go version
gcil_go_ver=$(golangci-lint --version | grep -o 'go[0-9]*\.[0-9]*\.[0-9]*' | cut -c 3-)
go_ver=$(go version | grep -o 'go[0-9]*\.[0-9]*\.[0-9]*' | cut -c 3-)
if [ "$(printf '%s\n' "$go_ver" "$gcil_go_ver" | sort -V | head -n1)" != "$go_ver" ]; then
echo "WARNING: Your go version ($go_ver) is greater than the version of go that golangci-lint was built with ($gcil_go_ver)."
fi

if [ -n "${BASE_REF:-}" ]; then
echo "Running golangci-lint"
golangci-lint --new-from-rev="$BASE_REF" --path-prefix= run
else
echo "Running golangci-lint without the --new-from-rev option. If you would rather use that option, specify the branch in the BASE_REF environment variable."
golangci-lint --path-prefix= run
fi
fi
fi

if [ "$UNIT" = 1 ]; then
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/go/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ execute: |
skip="${skip:-} SKIP_NAKEDRET=1"
fi
# golangci-lint checks are system agnostic and were already checked in the github
# test workflow static checks. They can therefore be safely skipped here.
skip="${skip:-} SKIP_GOLANGCI_LINT=1"
if not os.query is-trusty; then
if [ "$VARIANT" = "static" ] ; then
tests.session -u test exec sh -c "cd /tmp/static-unit-tests/src/github.com/snapcore/snapd && \
Expand Down

0 comments on commit 91bc7cb

Please sign in to comment.