Skip to content

Commit

Permalink
fixed Makefile and add some scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
erickyan86 committed Apr 4, 2019
1 parent d43aa95 commit feabf13
Show file tree
Hide file tree
Showing 39 changed files with 1,409 additions and 214 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ build/_workspace
profile.out

coverage.out

commit_hash.txt
65 changes: 65 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- main: ./cmd/ft
ldflags:
- -s -w
- -X github.com/fractalplatform/fractal/utils.commit={{.Commit}}
- -X github.com/fractalplatform/fractal/utils.date={{.Date}}
archive:
replacements:
darwin: Darwin
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

- main: ./cmd/ftkey
ldflags:
- -s -w
- -X github.com/fractalplatform/fractal/utils.commit={{.Commit}}
- -X github.com/fractalplatform/fractal/utils.date={{.Date}}
archive:
replacements:
darwin: Darwin
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

- main: ./cmd/build_ftfinder
ldflags:
- -s -w
- -X github.com/fractalplatform/fractal/utils.commit={{.Commit}}
- -X github.com/fractalplatform/fractal/utils.date={{.Date}}
archive:
replacements:
darwin: Darwin
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
language: go

go:
- 1.9.2
- 1.12

before_install:
- go get golang.org/x/tools/cmd/cover
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [fractal](https://github.com/fractalplatform/fractal) Changelog
## [0.0.5] - 2019-04-04
### Added
- [README] add license badge
- [SCRIPTS] add is_checkout_dirty.sh release.sh tag_release.sh commit_hash.sh
### Fixed
- [MAKEFILE] add check fmt tag_release release command


[0.0.5]: https://github.com/fractalplatform/fractal/commits/v0.0.5
125 changes: 105 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,116 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

SHELL:=/bin/bash
REPO := $(shell pwd)
GOFILES_NOVENDOR := $(shell go list -f "{{.Dir}}" ./...)
PACKAGES_NOVENDOR := $(shell go list ./...)
WORK_SPACE := ${REPO}/build/_workspace
FT_DIR :=${WORK_SPACE}/src/github.com/fractalplatform

all: ft ftkey ftfinder
export GOPATH := ${WORK_SPACE}

ft:
@./build/env.sh \
"go install ./cmd/ft" \
"go build ./cmd/ft" \
"mv ft ./build/bin" \
define build
@cd ${FT_DIR}/fractal && go build -ldflags " \
-X github.com/fractalplatform/fractal/cmd/utils.commit=$(shell cat commit_hash.txt) \
-X github.com/fractalplatform/fractal/cmd/utils.date=$(shell date '+%Y-%m-%d') \
-X 'github.com/fractalplatform/fractal/cmd/utils.goversion=$(shell go version)'" \
-o ${FT_DIR}/fractal/build/bin/$(1) ./cmd/$(1)
endef

ftkey:
@./build/env.sh \
"go install ./cmd/ftkey" \
"go build ./cmd/ftkey" \
"mv ftkey ./build/bin"

ftfinder:
@./build/env.sh \
"go install ./cmd/ftfinder" \
"go build ./cmd/ftfinder" \
"mv ftfinder ./build/bin"
### Check and format code

# check the code for style standards; currently enforces go formatting.
# display output first, then check for success
.PHONY: check
check:
@echo "Checking code for formatting style compliance."
@gofmt -l -d ${GOFILES_NOVENDOR}
@gofmt -l ${GOFILES_NOVENDOR} | read && echo && echo "Your marmot has found a problem with the formatting style of the code." 1>&2 && exit 1 || true

# fmt runs gofmt -w on the code, modifying any files that do not match
# the style guide.
.PHONY: fmt
fmt:
@echo "Correcting any formatting style corrections."
@gofmt -l -w ${GOFILES_NOVENDOR}

### Building project

# Output commit_hash but only if we have the git repo (e.g. not in docker build
.PHONY: commit_hash
commit_hash:
@git status &> /dev/null && scripts/commit_hash.sh > commit_hash.txt || true

.PHONY: build_workspace
build_workspace:
@[ -d ${FT_DIR} ] || mkdir -p ${FT_DIR}
@[ -d ${FT_DIR}/fractal ] || ln -s ${REPO} ${FT_DIR}

# build all targets
.PHONY: all
all:check build_workspace build_ft build_ftkey build_ftfinder

# build ft
.PHONY: build_ft
build_ft: commit_hash check build_workspace
@echo "Building ft."
$(call build,ft)

# build ftkey
.PHONY: build_ftkey
build_ftkey: commit_hash check build_workspace
@echo "Building ftkey."
$(call build,ftkey)

# build ftfinder
.PHONY: build_ftfinder
build_ftfinder: commit_hash check build_workspace
@echo "Building ftfinder."
$(call build,ftfinder)

### Test

.PHONY: test
test: check build_workspace
@cd ${FT_DIR}/fractal && scripts/test.sh


### Clean up

# clean removes the target folder containing build artefacts
.PHONY: clean
clean:
rm -rf build/bin build/_workspace
-rm -rf ./build/bin ./build/_workspace

### Release and versioning

# Print version
.PHONY: version
version:
@go run ./cmd/project/main.go version

# Generate full changelog of all release notes
CHANGELOG:
@go run ./cmd/project/main.go changelog > CHANGELOG.md

# Generated release note for this version
NOTES:
@go run ./cmd/project/main.go notes > NOTES.md

.PHONY: docs
docs: CHANGELOG NOTES

# Tag the current HEAD commit with the current release defined in
.PHONY: tag_release
tag_release: test check docs all
@scripts/tag_release.sh

.PHONY: release
release: test check docs all
@scripts/is_checkout_dirty.sh || (echo "checkout is dirty so not releasing!" && exit 1)
@scripts/release.sh


test:
./build/env.sh ./test.sh

.PHONY: all clean test ftfinder ft ftkey ftfinder
6 changes: 6 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Added
- [README] add license badge
- [SCRIPTS] add is_checkout_dirty.sh release.sh tag_release.sh commit_hash.sh
### Fixed
- [MAKEFILE] add check fmt tag_release release command

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/fractalplatform/fractal.svg?branch=master)](https://travis-ci.org/fractalplatform/fractal)
[![GoDoc](https://godoc.org/github.com/fractalplatform/fractal?status.svg)](https://godoc.org/github.com/fractalplatform/fractal)
[![Coverage Status](https://coveralls.io/repos/github/fractalplatform/fractal/badge.svg?branch=master)](https://coveralls.io/github/fractalplatform/fractal?branch=master)
[![GitHub](https://img.shields.io/github/license/fractalplatform/fractal.svg)](LICENSE)

Welcome to the Fractal source code repository!

Expand Down
22 changes: 11 additions & 11 deletions asset/asset_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestAssetObject_GetSymbol(t *testing.T) {
fields fields
want string
}{
// TODO: Add test cases.
// {"getexist",fields{}}
// TODO: Add test cases.
// {"getexist",fields{}}
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestAssetObject_SetSymbol(t *testing.T) {
fields fields
args args
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestAssetObject_GetDecimals(t *testing.T) {
fields fields
want uint64
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestAssetObject_SetDecimals(t *testing.T) {
fields fields
args args
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestAssetObject_GetAssetName(t *testing.T) {
fields fields
want string
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -315,7 +315,7 @@ func TestAssetObject_SetAssetName(t *testing.T) {
fields fields
args args
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestAssetObject_GetAssetAmount(t *testing.T) {
fields fields
want *big.Int
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -378,7 +378,7 @@ func TestAssetObject_SetAssetAmount(t *testing.T) {
fields fields
args args
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestAssetObject_GetAssetOwner(t *testing.T) {
fields fields
want common.Name
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestAssetObject_SetAssetOwner(t *testing.T) {
fields fields
args args
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
ao := &AssetObject{
Expand Down
37 changes: 0 additions & 37 deletions build/env.sh

This file was deleted.

2 changes: 2 additions & 0 deletions cmd/ft/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/ethereum/go-ethereum/log"
"github.com/fractalplatform/fractal/blockchain"
"github.com/fractalplatform/fractal/cmd/utils"
"github.com/fractalplatform/fractal/ftservice"
"github.com/fractalplatform/fractal/metrics"
"github.com/fractalplatform/fractal/metrics/influxdb"
Expand Down Expand Up @@ -193,6 +194,7 @@ func initConfig() {
}

func init() {
RootCmd.AddCommand(utils.VersionCmd)
cobra.OnInitialize(initConfig)
falgs := RootCmd.Flags()
// logging
Expand Down
Loading

0 comments on commit feabf13

Please sign in to comment.