Skip to content

Commit

Permalink
feat: implement skipPaths option for 'license' policy (#121)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and andrewrynhard committed Apr 11, 2019
1 parent c539351 commit ebed4b3
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 135 deletions.
9 changes: 0 additions & 9 deletions .bettercodehub.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .codebeatignore

This file was deleted.

2 changes: 1 addition & 1 deletion .conform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ policies:
spec:
headerLength: 89
dco: true
gpg: true
gpg: false
imperative: true
conventional:
types:
Expand Down
63 changes: 63 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
kind: pipeline
name: default

services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run

steps:
- name: enforce
image: autonomy/build-container:latest
pull: always
commands:
- make build
- build/conform-linux-amd64 enforce
volumes:
- name: dockersock
path: /var/run

- name: test
image: autonomy/build-container:latest
pull: always
commands:
- make test
volumes:
- name: dockersock
path: /var/run

- name: image
image: autonomy/build-container:latest
pull: always
commands:
- make image
volumes:
- name: dockersock
path: /var/run

- name: push
image: autonomy/build-container:latest
pull: always
environment:
DOCKER_USERNAME:
from_secret: docker_username
DOCKER_PASSWORD:
from_secret: docker_password
commands:
- make login
- make push
volumes:
- name: dockersock
path: /var/run
when:
branch:
- master
event:
- push

volumes:
- name: dockersock
temp: {}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ ENV CGO_ENABLED 0
ENV GO111MODULES on

WORKDIR /conform
COPY ./ ./
COPY go.mod ./
COPY go.sum ./
RUN go mod download
RUN go mod verify
RUN go mod tidy
COPY ./ ./
RUN go list -mod=readonly all

FROM common AS build
ARG TAG
Expand Down
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHA := $(shell gitmeta git sha)
TAG := $(shell gitmeta image tag)
BUILT := $(shell gitmeta built)

GOLANG_IMAGE ?= golang:1.11.4
GOLANG_IMAGE ?= golang:1.12.3

COMMON_ARGS := -f ./Dockerfile --build-arg GOLANG_IMAGE=$(GOLANG_IMAGE) --build-arg SHA=$(SHA) --build-arg TAG=$(TAG) --build-arg BUILT="$(BUILT)" .

Expand All @@ -19,30 +19,34 @@ build:
-t conform/$@:$(TAG) \
--target=$@ \
$(COMMON_ARGS)
@docker run --rm -it -v $(PWD)/build:/build conform/$@:$(TAG) cp /conform-linux-amd64 /build
@docker run --rm -it -v $(PWD)/build:/build conform/$@:$(TAG) cp /conform-darwin-amd64 /build
@docker run --rm -v $(PWD)/build:/build conform/$@:$(TAG) cp /conform-linux-amd64 /build
@docker run --rm -v $(PWD)/build:/build conform/$@:$(TAG) cp /conform-darwin-amd64 /build

test:
@docker build \
-t conform/$@:$(TAG) \
--target=$@ \
$(COMMON_ARGS)
@docker run --rm -it -v $(PWD)/build:/build conform/$@:$(TAG) cp /coverage.txt /build
@docker run --rm -v $(PWD)/build:/build conform/$@:$(TAG) cp /coverage.txt /build

image: build
@docker build \
-t autonomy/conform:$(TAG) \
--target=$@ \
$(COMMON_ARGS)

.PHONY: login
login:
@docker login --username $(DOCKER_USERNAME) --password $(DOCKER_PASSWORD)

push: image
@docker tag autonomy/conform:$(TAG) autonomy/conform:latest
@docker push autonomy/conform:$(TAG)
@docker push autonomy/conform:latest

deps:
@GO111MODULES=on CGO_ENABLED=0 go get -u github.com/autonomy/gitmeta
@GO111MODULES=on CGO_ENABLED=0 go get -u github.com/autonomy/conform
@GO111MODULE=on CGO_ENABLED=0 go get -u github.com/autonomy/gitmeta
@GO111MODULE=on CGO_ENABLED=0 go get -u github.com/autonomy/conform

clean:
go clean -modcache
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ policies:
- "scope"
- type: license
spec:
skipPaths:
- .git/
- .build*/
includeSuffixes:
- .ext
excludeSuffixes:
Expand Down
2 changes: 2 additions & 0 deletions hack/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ linters:
disable:
- gas
- typecheck
- gochecknoglobals
- gochecknoinits
disable-all: false
fast: false

Expand Down
30 changes: 2 additions & 28 deletions hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
set -e

CGO_ENABLED=1
GOPACKAGES=$(go list ./...)

lint_packages() {
if [ "${lint}" = true ]; then
echo "linting packages"
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.10.1
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.16.0
golangci-lint run --config "${BASH_SOURCE%/*}/golangci-lint.yaml"
fi
}
Expand All @@ -21,33 +20,13 @@ go_test() {

if [ "${tests}" = true ]; then
echo "performing tests"
go test -v ./...
fi
}

coverage_tests() {
if [ "${coverage}" = true ]; then
echo "performing coverage tests"
local coverage_report="/coverage.txt"
local profile="/profile.out"
if [[ -f ${coverage_report} ]]; then
rm ${coverage_report}
fi
touch ${coverage_report}
for package in ${GOPACKAGES[@]}; do
go test -v -short -race -coverprofile=${profile} -covermode=atomic $package
if [ -f ${profile} ]; then
cat ${profile} >> ${coverage_report}
rm ${profile}
fi
done
go test -v -race -covermode=atomic -coverprofile=/coverage.txt ./...
fi
}

lint=false
short=false
tests=false
coverage=false

case $1 in
--lint)
Expand All @@ -59,21 +38,16 @@ case $1 in
--integration)
tests=true
;;
--coverage)
coverage=true
;;
--all)
lint=true
short=true
tests=true
coverage=true
;;
*)
;;
esac

go_test
coverage_tests
lint_packages

exit 0
8 changes: 3 additions & 5 deletions internal/policy/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ func (c *Commit) Compliance(options *policy.Options) (report policy.Report) {
return
}
msg = string(contents)
} else {
if msg, err = g.Message(); err != nil {
report.Errors = append(report.Errors, errors.Errorf("failed to get commit message: %v", err))
return
}
} else if msg, err = g.Message(); err != nil {
report.Errors = append(report.Errors, errors.Errorf("failed to get commit message: %v", err))
return
}

if c.HeaderLength != 0 {
Expand Down
Loading

0 comments on commit ebed4b3

Please sign in to comment.