diff --git a/.gitignore b/.gitignore index 6b72022..eb58055 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -coverage.html -coverage.out \ No newline at end of file +target +vendor +/Dockerfile diff --git a/.travis.yml b/.travis.yml index 5024979..fa7d80e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,15 @@ language: go -sudo: false # silence warning + +sudo: false + +branches: + except: + - release + +branches: + only: + - master + - develop addons: apt: @@ -10,12 +20,25 @@ addons: go: - 1.6 - 1.7 + - tip -install: - - go get -t ./... - - go get github.com/golang/lint/golint +matrix: + allow_failures: + - go: tip + +before_install: + - if [ -n "$GH_USER" ]; then git config --global github.user ${GH_USER}; fi; + - if [ -n "$GH_TOKEN" ]; then git config --global github.token ${GH_TOKEN}; fi; + - go get github.com/mattn/goveralls + +before_script: + - make deps script: - - golint *.go - - go vet ./... - - go test -v ./... + - make qa + +after_failure: + - cat ./target/test/report.xml + +after_success: + - if [ "$TRAVIS_GO_VERSION" = "1.7" ]; then $HOME/gopath/bin/goveralls -covermode=count -coverprofile=target/report/coverage.out -service=travis-ci; fi; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..428d44d --- /dev/null +++ b/Makefile @@ -0,0 +1,178 @@ +# MAKEFILE +# +# @author Nicola Asuni +# @link https://github.com/miracl/go-xmlsec +# ------------------------------------------------------------------------------ + +# List special make targets that are not associated with files +.PHONY: help all test format fmtcheck vet lint coverage cyclo ineffassign misspell astscan qa deps clean nuke buildall dbuild + +# Use bash as shell (Note: Ubuntu now uses dash which doesn't support PIPESTATUS). +SHELL=/bin/bash + +# CVS path (path to the parent dir containing the project) +CVSPATH=github.com/miracl/go-xmlsec + +# Project vendor +VENDOR=miracl + +# Project name +PROJECT=go-xmlsec + +# Project version +VERSION=$(shell cat VERSION) + +# Project release number (packaging build number) +RELEASE=$(shell cat RELEASE) + +# Current directory +CURRENTDIR=$(shell pwd) + +# GO lang path +ifneq ($(GOPATH),) + ifeq ($(findstring $(GOPATH),$(CURRENTDIR)),) + # the defined GOPATH is not valid + GOPATH= + endif +endif +ifeq ($(GOPATH),) + # extract the GOPATH + GOPATH=$(firstword $(subst /src/, ,$(CURRENTDIR))) +endif + +# Add the GO binary dir in the PATH +export PATH := $(GOPATH)/bin:$(PATH) + +# --- MAKE TARGETS --- + +# Display general help about this command +help: + @echo "" + @echo "$(PROJECT) Makefile." + @echo "GOPATH=$(GOPATH)" + @echo "The following commands are available:" + @echo "" + @echo " make qa : Run all the tests and static analysis reports" + @echo " make test : Run the unit tests" + @echo "" + @echo " make format : Format the source code" + @echo " make fmtcheck : Check if the source code has been formatted" + @echo " make vet : Check for suspicious constructs" + @echo " make lint : Check for style errors" + @echo " make coverage : Generate the coverage report" + @echo " make cyclo : Generate the cyclomatic complexity report" + @echo " make ineffassign : Detect ineffectual assignments" + @echo " make misspell : Detect commonly misspelled words in source files" + @echo " make astscan : GO AST scanner" + @echo "" + @echo " make docs : Generate source code documentation" + @echo "" + @echo " make deps : Get the dependencies" + @echo " make clean : Remove any build artifact" + @echo " make nuke : Deletes any intermediate file" + @echo "" + @echo " make buildall : Full build and test sequence" + @echo " make dbuild : Build everything inside a Docker container" + @echo "" + +# Alias for help target +all: help + +# Run the unit tests +test: + @mkdir -p target/test + GOPATH=$(GOPATH) \ + go test -covermode=atomic -bench=. -race -v . | \ + tee >(PATH=$(GOPATH)/bin:$(PATH) go-junit-report > target/test/report.xml); \ + test $${PIPESTATUS[0]} -eq 0 + +# Format the source code +format: + @find . -type f -name "*.go" -exec gofmt -s -w {} \; + +# Check if the source code has been formatted +fmtcheck: + @mkdir -p target + @find . -type f -name "*.go" -exec gofmt -s -d {} \; | tee target/format.diff + @test ! -s target/format.diff || { echo "ERROR: the source code has not been formatted - please use 'make format' or 'gofmt'"; exit 1; } + +# Check for syntax errors +vet: + GOPATH=$(GOPATH) go vet . + +# Check for style errors +lint: + GOPATH=$(GOPATH) PATH=$(GOPATH)/bin:$(PATH) golint . + +# Generate the coverage report +coverage: + @mkdir -p target/report + GOPATH=$(GOPATH) \ + go test -covermode=count -coverprofile=target/report/coverage.out -v . && \ + GOPATH=$(GOPATH) \ + go tool cover -html=target/report/coverage.out -o target/report/coverage.html + +# Report cyclomatic complexity +cyclo: + @mkdir -p target/report + GOPATH=$(GOPATH) gocyclo -avg . | tee target/report/cyclo.txt ; test $${PIPESTATUS[0]} -eq 0 + +# Detect ineffectual assignments +ineffassign: + @mkdir -p target/report + GOPATH=$(GOPATH) ineffassign . | tee target/report/ineffassign.txt ; test $${PIPESTATUS[0]} -eq 0 + +# Detect commonly misspelled words in source files +misspell: + @mkdir -p target/report + GOPATH=$(GOPATH) misspell -error . | tee target/report/misspell.txt ; test $${PIPESTATUS[0]} -eq 0 + +# AST scanner +astscan: + @mkdir -p target/report + GOPATH=$(GOPATH) gas ./*.go | tee target/report/astscan.txt ; test $${PIPESTATUS[0]} -eq 0 + +# Generate source docs +docs: + @mkdir -p target/docs + nohup sh -c 'GOPATH=$(GOPATH) godoc -http=127.0.0.1:6060' > target/godoc_server.log 2>&1 & + wget --directory-prefix=target/docs/ --execute robots=off --retry-connrefused --recursive --no-parent --adjust-extension --page-requisites --convert-links http://127.0.0.1:6060/pkg/github.com/${VENDOR}/${PROJECT}/ ; kill -9 `lsof -ti :6060` + @echo ''${PKGNAME}' Documentation ...' > target/docs/index.html + +# Alias to run targets: fmtcheck test vet lint coverage +qa: fmtcheck test vet lint coverage cyclo ineffassign misspell astscan + +# --- INSTALL --- + +# Get the dependencies +deps: + GOPATH=$(GOPATH) go get $(go list ./... | grep -v /vendor/) + GOPATH=$(GOPATH) go get github.com/inconshreveable/mousetrap + GOPATH=$(GOPATH) go get github.com/golang/lint/golint + GOPATH=$(GOPATH) go get github.com/jstemmer/go-junit-report + GOPATH=$(GOPATH) go get github.com/axw/gocov/gocov + GOPATH=$(GOPATH) go get github.com/fzipp/gocyclo + GOPATH=$(GOPATH) go get github.com/gordonklaus/ineffassign + GOPATH=$(GOPATH) go get github.com/client9/misspell/cmd/misspell + GOPATH=$(GOPATH) go get github.com/HewlettPackard/gas + GOPATH=$(GOPATH) go get gopkg.in/check.v1 + +# Remove any build artifact +clean: + GOPATH=$(GOPATH) go clean ./... + +# Deletes any intermediate file +nuke: + rm -rf ./target + GOPATH=$(GOPATH) go clean -i ./... + +# Full build and test sequence +buildall: deps qa + +# Build everything inside a Docker container +dbuild: + @mkdir -p target + @rm -rf target/* + @echo 0 > target/make.exit + CVSPATH=$(CVSPATH) VENDOR=$(VENDOR) PROJECT=$(PROJECT) MAKETARGET='$(MAKETARGET)' ./dockerbuild.sh + @exit `cat target/make.exit` diff --git a/README.md b/README.md index d10656c..3785e9d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # go-xmlsec -[![](https://godoc.org/github.com/andy-miracl/go-xmlsec?status.png)](http://godoc.org/github.com/andy-miracl/go-xmlsec) [![Build Status](https://travis-ci.org/crewjam/go-xmlsec.svg?branch=master)](https://travis-ci.org/crewjam/go-xmlsec) +[![](https://godoc.org/github.com/miracl/go-xmlsec?status.png)](http://godoc.org/github.com/miracl/go-xmlsec) [![Build Status](https://travis-ci.org/miracl/go-xmlsec.svg?branch=master)](https://travis-ci.org/miracl/go-xmlsec) A partial wrapper for [xmlsec](https://www.aleksey.com/xmlsec). @@ -43,12 +43,12 @@ As seems to be the case for many things in the XMLish world, the xmldsig and xml This package uses cgo to wrap libxmlsec. As such, you'll need libxmlsec headers and a C compiler to make it work. On linux, this might look like: $ apt-get install libxml2-dev libxmlsec1-dev pkg-config - $ go get github.com/andy-miracl/go-xmlsec + $ go get github.com/miracl/go-xmlsec On Mac with homebrew, this might look like: $ brew install libxmlsec1 libxml2 pkg-config - $ go get github.com/andy-miracl/go-xmlsec + $ go get github.com/miracl/go-xmlsec # Static Linking diff --git a/dockerbuild.sh b/dockerbuild.sh new file mode 100755 index 0000000..04a30b0 --- /dev/null +++ b/dockerbuild.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# +# dockerbuild.sh +# +# Build the software inside a Docker container +# +# @author Nicola Asuni +# ------------------------------------------------------------------------------ + +# NOTES: +# This script requires Docker + +# EXAMPLE USAGE: +# VENDOR=vendorname PROJECT=projectname MAKETARGET=buildall ./dockerbuild.sh + +# Get vendor and project name +: ${CVSPATH:=project} +: ${VENDOR:=vendor} +: ${PROJECT:=project} + +# make target to execute +: ${MAKETARGET:=buildall} + +# Name of the base development Docker image +DOCKERDEV=${VENDOR}/dev_${PROJECT} + +# Build the base environment and keep it cached locally +docker build -t ${DOCKERDEV} ./resources/DockerDev/ + +# Define the project root path +PRJPATH=/root/src/${CVSPATH}/${PROJECT} + +# Generate a temporary Dockerfile to build and test the project +# NOTE: The exit status of the RUN command is stored to be returned later, +# so in case of error we can continue without interrupting this script. +cat > Dockerfile <<- EOM +FROM ${DOCKERDEV} +RUN mkdir -p ${PRJPATH} +ADD ./ ${PRJPATH} +WORKDIR ${PRJPATH} +RUN make ${MAKETARGET} || (echo \$? > target/make.exit) +EOM + +# Define the temporary Docker image name +DOCKER_IMAGE_NAME=${VENDOR}/build_${PROJECT} + +# Build the Docker image +docker build --no-cache -t ${DOCKER_IMAGE_NAME} . + +# Start a container using the newly created Docker image +CONTAINER_ID=$(docker run -d ${DOCKER_IMAGE_NAME}) + +# Copy all build/test artifacts back to the host +docker cp ${CONTAINER_ID}:"${PRJPATH}/target" ./ + +# Remove the temporary container and image +docker rm -f ${CONTAINER_ID} || true +docker rmi -f ${DOCKER_IMAGE_NAME} || true diff --git a/resources/DockerDev/Dockerfile b/resources/DockerDev/Dockerfile new file mode 100644 index 0000000..0317aea --- /dev/null +++ b/resources/DockerDev/Dockerfile @@ -0,0 +1,10 @@ +# Dockerfile +# +# Linux development environment +# +# Extend the miracl/alldev image defined in +# https://github.com/miracl/alldev +# ------------------------------------------------------------------------------ + +FROM miracl/alldev +MAINTAINER nicola.asuni@miracl.com