Skip to content

Commit

Permalink
Add pre-release-checks target (#282)
Browse files Browse the repository at this point in the history
Add pre-release-checks target
  • Loading branch information
twpayne committed May 3, 2019
2 parents 1e7327f + 7b61b9f commit 6917265
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ coverage.out:

.PHONY: format
format:
find . -name \*.go | xargs gofumpt -w
find . -name \*.go | xargs gofumports -w

.PHONY: generate
Expand All @@ -25,6 +24,13 @@ lint:
go vet ./...
golangci-lint run

.PHONY: pre-release-checks
pre-release-checks: strict-lint

.PHONY: strict-lint
strict-lint:
golangci-lint run --enable-all ./...

.PHONY: test
test:
go test -race ./...
7 changes: 7 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ that:

Releases are managed with [goreleaser](https://goreleaser.com/).

Before creating a release, please run:

make pre-release-checks

This will run a variety of strict checks. Many can be ignored, but please
manually check each of them before tagging a release.

To create a new release, push a tag, eg:

git tag -a v0.1.0 -m "First release"
Expand Down
4 changes: 2 additions & 2 deletions lib/chezmoi/autotemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (b byValueLength) Less(i, j int) bool {
}
func (b byValueLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

func autoTemplate(contents []byte, data map[string]interface{}) ([]byte, error) {
func autoTemplate(contents []byte, data map[string]interface{}) []byte {
// FIXME this naive approach will generate incorrect templates if the
// variable names match variable values
// FIXME the algorithm here is probably O(N^2), we can do better
Expand Down Expand Up @@ -61,7 +61,7 @@ func autoTemplate(contents []byte, data map[string]interface{}) ([]byte, error)
}
}
}
return []byte(contentsStr), nil
return []byte(contentsStr)
}

func extractVariables(variables []templateVariable, parent []string, data map[string]interface{}) []templateVariable {
Expand Down
4 changes: 1 addition & 3 deletions lib/chezmoi/autotemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ func TestAutoTemplate(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
got, gotErr := autoTemplate([]byte(tc.contentsStr), tc.data)
assert.NoError(t, gotErr)
assert.Equal(t, tc.wantStr, string(got))
assert.Equal(t, tc.wantStr, string(autoTemplate([]byte(tc.contentsStr), tc.data)))
})
}
}
Expand Down
5 changes: 1 addition & 4 deletions lib/chezmoi/targetstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ func (ts *TargetState) Add(fs vfs.FS, addOptions AddOptions, targetPath string,
return err
}
if addOptions.Template {
contents, err = autoTemplate(contents, ts.Data)
if err != nil {
return err
}
contents = autoTemplate(contents, ts.Data)
}
if addOptions.Encrypt {
contents, err = ts.Encrypt(contents)
Expand Down

0 comments on commit 6917265

Please sign in to comment.