Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Add Golang 1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
soedar committed Mar 14, 2019
1 parent 5706320 commit 9786593
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions golang/1.12/alpine3.9/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.12-alpine3.9

ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 0

RUN apk --no-cache add build-base git bash \
&& go get -v -u github.com/stretchr/testify \
github.com/tebeka/go2xunit \
github.com/t-yuki/gocover-cobertura \
gopkg.in/alecthomas/gometalinter.v2 \
github.com/moexmen/gas-report-filter \
&& gometalinter.v2 --install \
# Needs to be installed last to override outdated version in gometalinter
&& go get github.com/securego/gosec/cmd/gosec/...

COPY go-test-coverage-lint go-ast-scanner /usr/local/bin/
4 changes: 4 additions & 0 deletions golang/1.12/alpine3.9/go-ast-scanner
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

mkdir -p /log
gosec -exclude=$GLOBAL_WHITELIST -fmt=junit-xml ./... | gas-report-filter -whitelist whitelist.json > /log/report.xml
56 changes: 56 additions & 0 deletions golang/1.12/alpine3.9/go-test-coverage-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

mkdir -p /log

if [ "$#" -eq 0 ]; then
PKG=./...
else
PKG=${@:1}
fi

function test-coverage {
echo "***********"
echo "* go test *"
echo "***********"

# Capture the test result
set -o pipefail
go test -v $PKG | go2xunit > /log/test.xml
code=$?
set +o pipefail

mkdir -p /log/coverage
echo "mode: count" > /log/coverage/coverage.out

# Generate coverage for our source files
for x in $(go list $PKG | grep -v /vendor/); do
file=/log/coverage/$(echo $x | tr / -)
go test -covermode=count -coverprofile=$file "$x"
tail -n +2 $file >> /log/coverage/coverage.out
done

go tool cover -html=/log/coverage/coverage.out -o /log/coverage/index.html
gocover-cobertura < /log/coverage/coverage.out > /log/coverage.xml

exit $code
}

function linters {
echo "************************"
echo "* Running gometalinter *"
echo "************************"
gometalinter.v2 --checkstyle \
--deadline=60s \
--disable-all \
--enable=errcheck \
--enable=golint \
--enable=megacheck \
--enable=misspell \
--enable=vet \
--vendor \
$PKG > /log/checkstyle.xml
}

linters
test-coverage
exit $?

0 comments on commit 9786593

Please sign in to comment.