Skip to content

Commit

Permalink
feat: replace golint with golangci-lint
Browse files Browse the repository at this point in the history
Signed-off-by: PoAn Yang <poan.yang@suse.com>
  • Loading branch information
FrankYang0529 authored and David Ko committed Dec 26, 2023
1 parent 8f1909a commit 84870bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
16 changes: 8 additions & 8 deletions Dockerfile.dapper
Expand Up @@ -8,7 +8,7 @@ ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
# Setup environment
ENV PATH /go/bin:$PATH
ENV DAPPER_DOCKER_SOCKET true
ENV DAPPER_ENV TAG REPO
ENV DAPPER_ENV TAG REPO DRONE_REPO DRONE_PULL_REQUEST DRONE_COMMIT_REF
ENV DAPPER_OUTPUT bin coverage.out
ENV DAPPER_SOURCE /go/src/github.com/longhorn/backing-image-manager
WORKDIR ${DAPPER_SOURCE}
Expand All @@ -19,22 +19,22 @@ RUN zypper -n addrepo --refresh https://download.opensuse.org/repositories/syste

# Install packages
RUN zypper -n install cmake wget curl git less file \
libkmod-devel libnl3-devel linux-glibc-devel pkg-config psmisc python3-tox fuse python3-devel qemu-tools \
bash-completion librdmacm1 librdmacm-utils libibverbs xsltproc docbook-xsl-stylesheets \
perl-Config-General libaio-devel glibc-devel-static glibc-devel iptables libltdl7 libdevmapper1_03 iproute2 jq docker gcc
libkmod-devel libnl3-devel linux-glibc-devel pkg-config psmisc python3-tox fuse python3-devel qemu-tools \
bash-completion librdmacm1 librdmacm-utils libibverbs xsltproc docbook-xsl-stylesheets \
perl-Config-General libaio-devel glibc-devel-static glibc-devel iptables libltdl7 libdevmapper1_03 iproute2 jq docker gcc

# needed for ${!var} substitution
RUN rm -f /bin/sh && ln -s /bin/bash /bin/sh

RUN if [ ${ARCH} == "s390x" ]; then \
ln -s /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc;\
ln -s /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc;\
fi

# Install Go & tools
ENV GOLANG_ARCH_amd64=amd64 GOLANG_ARCH_arm64=arm64 GOLANG_ARCH_s390x=s390x GOLANG_ARCH=GOLANG_ARCH_${ARCH} \
GOPATH=/go PATH=/go/bin:/usr/local/go/bin:${PATH} SHELL=/bin/bash
RUN wget -O - https://storage.googleapis.com/golang/go1.21.3.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local && \
go install golang.org/x/lint/golint@latest
RUN wget -O - https://storage.googleapis.com/golang/go1.21.3.linux-${!GOLANG_ARCH}.tar.gz | tar -xzf - -C /usr/local
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

VOLUME /tmp
ENV TMPDIR /tmp
Expand Down
23 changes: 16 additions & 7 deletions scripts/validate
Expand Up @@ -9,12 +9,21 @@ PACKAGES="$(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u |

echo Running: go vet
go vet ${PACKAGES}
echo Running: golint
for i in ${PACKAGES}; do
if [ -n "$(golint $i | grep -v 'should have comment.*or be unexported' | tee /dev/stderr)" ]; then
failed=true
fi
done
test -z "$failed"

if [ ! -z "${DRONE_REPO}" ] && [ ! -z "${DRONE_PULL_REQUEST}" ]; then
wget https://github.com/$DRONE_REPO/pull/$DRONE_PULL_REQUEST.patch
echo "Running: golangci-lint run --new-from-patch=${DRONE_PULL_REQUEST}.patch"
golangci-lint run --new-from-patch="${DRONE_PULL_REQUEST}.patch"
rm "${DRONE_PULL_REQUEST}.patch"
elif [ ! -z "${DRONE_COMMIT_REF}" ]; then
echo "Running: golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}"
golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}
else
git symbolic-ref -q HEAD && REV="origin/HEAD" || REV="HEAD^"
headSHA=$(git rev-parse --short=12 ${REV})
echo "Running: golangci-lint run --new-from-rev=${headSHA}"
golangci-lint run --new-from-rev=${headSHA}
fi

echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"

0 comments on commit 84870bd

Please sign in to comment.