Skip to content

Commit

Permalink
add the install and basic-checks subcommand in the makefile
Browse files Browse the repository at this point in the history
install subcommand will install binary to GOBIN path

Signed-off-by: wuxu <wuxu1103@163.com>
  • Loading branch information
wuxuer authored and guoger committed Feb 7, 2021
1 parent fbc2d5c commit 66bfd6f
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 9 deletions.
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# - docker - build the tape image
# - unit-test - runs the go-test based unit tests
# - integration-test - runs the integration tests
# - install - installs a binary program to GOBIN path

FABRIC_VERSION = latest
INTERGATION_CASE = ANDLogic
Expand Down Expand Up @@ -34,7 +35,6 @@ GO_TAGS ?=

export GO_LDFLAGS GO_TAGS FABRIC_VERSION INTERGATION_CASE

#.PHONY: tape
tape:
@echo "Building tape program......"
go build -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" ./cmd/tape
Expand All @@ -53,3 +53,18 @@ unit-test:
integration-test:
@echo "Run integration test......"
./test/integration-test.sh $(FABRIC_VERSION) $(INTERGATION_CASE)

.PHONY: install
install:
@echo "Install tape......"
go install -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" ./cmd/tape

include gotools.mk

.PHONY: basic-checks
basic-checks: gotools-install linter

.PHONY: linter
linter:
@echo "LINT: Running code checks......"
./scripts/golinter.sh
12 changes: 10 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
trigger:
- master

variables:
GOPATH: $(Agent.BuildDirectory)/go
PATH: $(Agent.BuildDirectory)/go/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin

jobs:
- job: ut
strategy:
Expand All @@ -25,9 +29,13 @@ jobs:
- task: GoTool@0
inputs:
version: '1.14'
displayName: install go tools
displayName: install go
- script: make basic-checks
displayName: run basic checks like linter
- script: make tape
displayName: build tape binary program
- script: make install
displayName: install tape to GOBIN
- script: make test
displayName: run unit test

Expand Down Expand Up @@ -81,4 +89,4 @@ jobs:
tagSource: 'auto'
tagPattern: 'v.*'
assets: |
./*.tar.gz
./*.tar.gz
1 change: 0 additions & 1 deletion e2e/mock/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Orderer struct {

func (o *Orderer) Deliver(orderer.AtomicBroadcast_DeliverServer) error {
panic("Not implemented")
return nil
}

func (o *Orderer) Broadcast(srv orderer.AtomicBroadcast_BroadcastServer) error {
Expand Down
2 changes: 0 additions & 2 deletions e2e/mock/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (p *Peer) ProcessProposal(context.Context, *peer.SignedProposal) (*peer.Pro

func (p *Peer) Deliver(peer.Deliver_DeliverServer) error {
panic("Not implemented")
return nil
}

func (p *Peer) DeliverFiltered(srv peer.Deliver_DeliverFilteredServer) error {
Expand All @@ -40,5 +39,4 @@ func (p *Peer) DeliverFiltered(srv peer.Deliver_DeliverFilteredServer) error {

func (p *Peer) DeliverWithPrivateData(peer.Deliver_DeliverWithPrivateDataServer) error {
panic("Not implemented")
return nil
}
29 changes: 29 additions & 0 deletions gotools.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright IBM Corp All Rights Reserved.
# Copyright London Stock Exchange Group All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

GOTOOLS = goimports golint staticcheck
BUILD_DIR ?= build
GOTOOLS_BINDIR ?= $(shell go env GOBIN)

# go tool->path mapping
go.fqp.goimports := golang.org/x/tools/cmd/goimports
go.fqp.golint := golang.org/x/lint/golint
go.fqp.staticcheck := honnef.co/go/tools/cmd/staticcheck

.PHONY: gotools-install
gotools-install: $(patsubst %,$(GOTOOLS_BINDIR)/%, $(GOTOOLS))

.PHONY: gotools-clean
gotools-clean:

# Default rule for gotools uses the name->path map for a generic 'go get' style build
gotool.%:
$(eval TOOL = ${subst gotool.,,${@}})
@echo "Building ${go.fqp.${TOOL}} -> $(TOOL)"
go install ${go.fqp.${TOOL}}

$(GOTOOLS_BINDIR)/%:
$(eval TOOL = ${subst $(GOTOOLS_BINDIR)/,,${@}})
@$(MAKE) -f gotools.mk gotool.$(TOOL)
4 changes: 2 additions & 2 deletions pkg/infra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func LoadConfig(f string) (Config, error) {
return config, errors.Wrapf(err, "error unmarshal %s", f)
}

for i, _ := range config.Endorsers {
for i := range config.Endorsers {
err = config.Endorsers[i].loadConfig()
if err != nil {
return config, err
}
}
for i, _ := range config.Committers {
for i := range config.Committers {
err = config.Committers[i].loadConfig()
if err != nil {
return config, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/infra/proposer_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package infra_test

import (
"tape/pkg/infra"

"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
log "github.com/sirupsen/logrus"
"tape/pkg/infra"
)

var _ = Describe("Proposer", func() {
Expand Down
50 changes: 50 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

function filterExcludedAndGeneratedFiles {
local excluded_files
excluded_files=(
'\.block$'
'^\.build/'
'^build/'
'(^|/)ci\.properties$'
'(^|/)\.git/'
'\.gen\.go$'
'(^|/)go.mod$'
'(^|/)go.sum$'
'(^|/)Gopkg\.lock$'
'\.html$'
'\.json$'
'\.key$'
'(^|/)LICENSE$'
'\.md$'
'\.pb\.go$'
'\.pem$'
'\.png$'
'\.pptx$'
'\.rst$'
'_sk$'
'\.tx$'
'\.txt$'
'^NOTICE$'
'(^|/)testdata\/'
'(^|/)vendor\/'
'(^|/)Pipfile$'
'(^|/)Pipfile\.lock$'
'(^|/)tox\.ini$'
)

local filter
filter=$(local IFS='|' ; echo "${excluded_files[*]}")

read -ra files <<<"$@"
for f in "${files[@]}"; do
file=$(echo "$f" | grep -Ev "$filter" | sort -u)
if [ -n "$file" ]; then
head -n2 "$file" | grep -qE '// Code generated by' || echo "$file"
fi
done
}
53 changes: 53 additions & 0 deletions scripts/golinter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

# Copyright Greg Haskins All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

set -e

# shellcheck source=/dev/null
source "$(cd "$(dirname "$0")" && pwd)/functions.sh"

fabric_dir="$(cd "$(dirname "$0")/.." && pwd)"
source_dirs=()
while IFS=$'\n' read -r source_dir; do
source_dirs+=("$source_dir")
done < <(go list -f '{{.Dir}}' ./... | sed s,"${fabric_dir}".,,g | cut -f 1 -d / | sort -u)

echo "Checking with gofmt"
OUTPUT="$(gofmt -l -s "${source_dirs[@]}")"
OUTPUT="$(filterExcludedAndGeneratedFiles "$OUTPUT")"
if [ -n "$OUTPUT" ]; then
echo "The following files contain gofmt errors"
echo "$OUTPUT"
echo "The gofmt command 'gofmt -l -s -w' must be run for these files"
exit 1
fi

echo "Checking with goimports"
OUTPUT="$(goimports -l "${source_dirs[@]}")"
OUTPUT="$(filterExcludedAndGeneratedFiles "$OUTPUT")"
if [ -n "$OUTPUT" ]; then
echo "The following files contain goimports errors"
echo "$OUTPUT"
echo "The goimports command 'goimports -l -w' must be run for these files"
exit 1
fi

echo "Checking with go vet"
PRINTFUNCS="Debug,Debugf,Print,Printf,Info,Infof,Warning,Warningf,Error,Errorf,Critical,Criticalf,Sprint,Sprintf,Log,Logf,Panic,Panicf,Fatal,Fatalf,Notice,Noticef,Wrap,Wrapf,WithMessage"
OUTPUT="$(go vet -all -printfuncs "$PRINTFUNCS" ./...)"
if [ -n "$OUTPUT" ]; then
echo "The following files contain go vet errors"
echo "$OUTPUT"
exit 1
fi

#echo "Checking with staticcheck"
#OUTPUT="$(staticcheck ./... || true)"
#if [ -n "$OUTPUT" ]; then
# echo "The following staticcheck issues were flagged"
# echo "$OUTPUT"
# exit 1
#fi

0 comments on commit 66bfd6f

Please sign in to comment.