From c44f738ba8159950372aa09483a4e23b2d044e07 Mon Sep 17 00:00:00 2001 From: Jguer Date: Sun, 13 Oct 2019 20:10:46 +0100 Subject: [PATCH] Convert linting to Makefile action. Patch Dockerfile and CI script --- Dockerfile | 3 +-- Makefile | 5 +++++ testdata/travis.sh | 39 +++++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 979f3fa5..5e54e5d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,8 @@ RUN pacman -Syu --overwrite=* --needed --noconfirm \ gcc gnupg libldap go git tar make awk linux-api-headers pacman-contrib && paccache -rfk0 # Dependency for linting -RUN go get -u golang.org/x/lint/golint && mv /root/go/bin/golint /bin/ - RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b /bin v1.20.0 +RUN go get golang.org/x/lint/golint && mv /root/go/bin/golint /bin/ ENV ARCH=$BUILD_ARCH ADD . . diff --git a/Makefile b/Makefile index f4512174..2e25708d 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,11 @@ test-vendor: vendor exit 1; \ fi; +.PHONY: lint +lint: + golangci-lint run + golint -set_exit_status . ./pkg/... + .PHONY: fmt fmt: #go fmt -mod=vendor $(GOFILES) ./... Doesn't work yet but will be supported soon diff --git a/testdata/travis.sh b/testdata/travis.sh index d2b075d5..972329d1 100755 --- a/testdata/travis.sh +++ b/testdata/travis.sh @@ -1,35 +1,50 @@ #!/bin/bash -set -evx +#set -evx # Objective of this script is to be the most vendor agnostic possible # It builds and tests yay independently of hardware -export VERSION=$(git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g') +VERSION="$(git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g')" +export VERSION export ARCH="x86_64" -echo '::set-env name=VERSION::$VERSION' -echo '::set-env name=ARCH::$ARCH' -docker build --build-arg BUILD_ARCH=${ARCH} --target builder_env -t yay-builder_env . -docker build --build-arg BUILD_ARCH=${ARCH} --target builder -t yay-builder . +docker build --build-arg BUILD_ARCH=${ARCH} --target builder_env -t yay-builder_env . || exit $? +docker build --build-arg BUILD_ARCH=${ARCH} --target builder -t yay-builder . || exit $? # Our unit test and packaging container -docker run --name yay-go-tests yay-builder_env:latest make test && golint && golangci-lint run +docker run --name yay-go-tests yay-builder_env:latest make test +rc=$? docker rm yay-go-tests -# docker run yay-builder make lint +if [[ $rc != 0 ]]; then + exit $rc +fi + +# Lint project +docker run --name yay-go-lint yay-builder_env:latest make lint +rc=$? +docker rm yay-go-lint + +if [[ $rc != 0 ]]; then + exit $rc +fi # Build image for integration testing -docker build -t yay . - +# docker build -t yay . || exit $? # Do integration testing # TODO # Create a release asset -docker run --name artifact_factory yay-builder make release ARCH=${ARCH} VERSION=${VERSION} +docker run --name artifact_factory yay-builder make release ARCH=${ARCH} VERSION="${VERSION}" +rc=$? +if [[ $rc != 0 ]]; then + docker rm artifact_factory + exit $rc +fi # Copy bin and release to artifacts folder mkdir artifacts -docker cp artifact_factory:/app/yay_${VERSION}_${ARCH}.tar.gz ./artifacts/ +docker cp artifact_factory:/app/yay_"${VERSION}"_${ARCH}.tar.gz ./artifacts/ # Cleanup docker docker rm artifact_factory