Skip to content

Commit

Permalink
Merge pull request #32 from davidovich/fix-scaffold-module-name
Browse files Browse the repository at this point in the history
remove submodule name in generated go.mod
  • Loading branch information
davidovich authored May 8, 2019
2 parents 867c756 + d4545b4 commit 786501b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin
build
42 changes: 38 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
SHELL=/bin/bash

HAS_PACKR2 := $(shell command -v packr2)
HAS_PACKR2 := $(shell command -v packr2)
HAS_GOBIN := $(shell command -v gobin)
HAS_GOCOVERUTIL := $(shell command -v gocoverutil)

ifndef HAS_GOBIN
$(shell GO111MODULE=off go get -u github.com/myitcv/gobin 2>/dev/null)
endif

export GO111MODULE := on

Expand All @@ -9,7 +15,10 @@ PACKR_FILE := pkg/scaffold/scaffold-packr.go

ASSETS := $(shell find templates/scaffold)

all: test $(PACK_FILE) $(SCAFFOLD_BIN)
all: $(PACKR_FILE) test $(SCAFFOLD_BIN)

.PHONY: bin
bin: $(PACKR_FILE) $(SCAFFOLD_BIN)

.PHONY: $(SCAFFOLD_BIN)
$(SCAFFOLD_BIN): $(PACKR_FILE)
Expand All @@ -22,9 +31,34 @@ ifndef HAS_PACKR2
endif
packr2

GO_TESTS := pkg internal cmd
COVERAGE := $(foreach t,$(GO_TESTS),build/coverage/report/$(t))
MERGED_COVERAGE := build/coverage/report/cover.merged.out
HTML_COVERAGE := build/coverage/html/index.html

.PHONY: test
test:
go test -cover -v ./...
test: output-coverage

.PHONY: output-coverage
output-coverage: $(MERGED_COVERAGE) $(HTML_COVERAGE)
go tool cover -func=$<

$(MERGED_COVERAGE): $(COVERAGE)
ifndef HAS_GOCOVERUTIL
gobin github.com/AlekSi/[email protected]
endif
$(call msg,Generating merged coverage report)
gocoverutil -coverprofile=$@ merge $^

$(HTML_COVERAGE): $(MERGED_COVERAGE)
@mkdir -p $(@D)
go tool cover -html=$< -o $@

.PHONY: $(COVERAGE)
$(COVERAGE):
@mkdir -p $(@D)
$(call msg,--> Testing $(@F)...)
go test ./$(@F)/... --cover -coverprofile $@ -v

.PHONY: clean
clean:
Expand Down
6 changes: 3 additions & 3 deletions packrd/packed-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/scaffold/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func TestCreateScaffold(t *testing.T) {
desc: "happy path",
args: []string{".", "example.com/my/assets", "summon"},
file: "go.mod",
content: "module example.com/my/assets/summon",
content: "module example.com/my/assets",
},
{
desc: "output dir",
args: []string{"subdir", "example.com/my/assets", "summon"},
file: "subdir/go.mod",
content: "module example.com/my/assets/summon",
content: "module example.com/my/assets",
},
{
desc: "non empty dir error",
Expand All @@ -51,13 +51,13 @@ func TestCreateScaffold(t *testing.T) {
f.Close()
},
file: "summon/go.mod",
content: "module example.com/my/assets/summon",
content: "module example.com/my/assets",
},
{
desc: "named exe",
args: []string{".", "example.com/my/assets", "my-assets"},
file: "go.mod",
content: "module example.com/my/assets/my-assets",
content: "module example.com/my/assets",
},
{
desc: "README rendered contents",
Expand Down
3 changes: 2 additions & 1 deletion templates/scaffold/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ all: $(SUMMONER_NAME)/packrd/packed-packr.go bin/$(SUMMONER_NAME)

bin/$(SUMMONER_NAME): $(SUMMON_DEPS)
@mkdir -p bin
cd $(SUMMONER_NAME) && go build -o ../$@ summon.go
go build -o $@ $(SUMMONER_NAME)/summon.go

$(SUMMONER_NAME)/packrd/packed-packr.go: $(ASSETS)
ifndef HAS_PACKR2
Expand All @@ -22,3 +22,4 @@ endif
.PHONY: clean
clean:
cd $(SUMMONER_NAME) && packr2 clean
rm -rf bin
15 changes: 12 additions & 3 deletions templates/scaffold/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Summon Data provider repo
Summon Data Provider Repo
=========================

This repository hosts a [{{ .SummonerName }}](https://github.com/davidovich/summon) data
Expand All @@ -18,6 +18,15 @@ Summon `some-asset` like so:
{{ .SummonerName }} some-asset
```

By default, summon will instantiate the asset in the .summoned/ directory and return its path. This can be overriden in the `asssets/summon.config.yaml` file or the `-o` flag.
By default, summon will instantiate the asset in the `.summoned/` directory and return its path. This can be overriden in the `asssets/summon.config.yaml` file or by using the `-o` flag.

Get more help with `{{ .SummonerName }} -h`.
Get more help with `{{ .SummonerName }} -h`.

Updating assets
---------------

1) Make modifications (additions, removals) in the assets/ dir
2) Invoke `make`
3) Commit changes
4) Tag with a semantic version (prefix with `v`)
5) git push --tags
2 changes: 1 addition & 1 deletion templates/scaffold/go.mod
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module {{ .ModName }}/{{.SummonerName}}
module {{ .ModName }}

0 comments on commit 786501b

Please sign in to comment.