diff --git a/.travis.yml b/.travis.yml index 1c6cff919..89100beb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,24 @@ language: go go: 1.7.4 install: + - go get github.com/alecthomas/gometalinter - go get github.com/Masterminds/glide - glide install script: - go test -cover `glide nv` + - gometalinter --vendor --disable-all \ + --enable=deadcode \ + --enable=ineffassign \ + --enable=gosimple \ + --enable=staticcheck \ + --enable=gofmt \ + --enable=goimports \ + --enable=dupl \ + --enable=misspell \ + --enable=errcheck \ + --deadline=2m \ + ./... after_success: test ! -z "$TRAVIS_TAG" && go run main.go notifications: - email: false \ No newline at end of file + email: false diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..2380be3fa --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at root@carlosbecker.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/README.md b/README.md index ea1a3fb25..1ebd8bc27 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ Deliver Go binaries as fast and easily as possible. GoReleaser builds Go binaries for several platforms, creates a github release and then push a homebrew formulae to a repository. All that wrapped in your favorite CI. + +This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). +By participating, you are expected to uphold this code. Please report unacceptable behavior to root@carlosbecker.com. + ## How it works? The idea started with a [simple shell script](https://github.com/goreleaser/old-go-releaser), @@ -74,7 +78,7 @@ files: ## Wire it with travis-ci -You may want to wire this to auto-deploy your new tags on travis, for examepl: +You may want to wire this to auto-deploy your new tags on travis, for example: ```yaml after_success: diff --git a/config/config.go b/config/config.go index b59e1d38b..f9e6b3879 100644 --- a/config/config.go +++ b/config/config.go @@ -54,7 +54,9 @@ func Load(file string) (config ProjectConfig, err error) { if err != nil { return config, err } - err = yaml.Unmarshal(data, &config) + if err := yaml.Unmarshal(data, &config); err != nil { + return config, err + } config.fillBasicData() if err := config.fillFiles(); err != nil { return config, err diff --git a/config/config_test.go b/config/config_test.go index 5124e6c6e..110f6178a 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -29,73 +29,23 @@ func TestFillFilesMissingFiles(t *testing.T) { } func TestFillFilesUSENMarkdown(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/1") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENSE.md", "README.md"}, config.Files) + assertFiles(t, "./.test/1", []string{"LICENSE.md", "README.md"}) } func TestFillFilesRealENMarkdown(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/2") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENCE.md", "README.md"}, config.Files) + assertFiles(t, "./.test/2", []string{"LICENCE.md", "README.md"}) } func TestFillFilesArbitratryENTXT(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/3") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENCE.txt", "README.txt"}, config.Files) + assertFiles(t, "./.test/3", []string{"LICENCE.txt", "README.txt"}) } func TestFillFilesArbitratryENNoSuffix(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/4") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENCE"}, config.Files) + assertFiles(t, "./.test/4", []string{"LICENCE"}) } func TestFillFilesChangelog(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/5") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"CHANGELOG", "CHANGELOG.md"}, config.Files) + assertFiles(t, "./.test/5", []string{"CHANGELOG", "CHANGELOG.md"}) } func TestValidadeMissingBinaryName(t *testing.T) { @@ -118,3 +68,23 @@ func TestValidadeMinimalConfig(t *testing.T) { config := ProjectConfig{BinaryName: "asd", Repo: "asd/asd"} assert.NoError(config.validate()) } + +func assertFiles(t *testing.T, dir string, files []string) { + assert := assert.New(t) + + cwd, _ := os.Getwd() + if err := os.Chdir(dir); err != nil { + panic(err) + } + defer func() { + if err := os.Chdir(cwd); err != nil { + panic(err) + } + }() + + config := ProjectConfig{} + err := config.fillFiles() + + assert.NoError(err) + assert.Equal(files, config.Files) +} diff --git a/config/git/tag_test.go b/config/git/tag_test.go index f988e38b9..77ba71d14 100644 --- a/config/git/tag_test.go +++ b/config/git/tag_test.go @@ -1,8 +1,9 @@ package git import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestCurrentTag(t *testing.T) { diff --git a/main.go b/main.go index 243a90791..e51ac7fb1 100644 --- a/main.go +++ b/main.go @@ -49,5 +49,7 @@ func main() { log.Println("Done!") return } - app.Run(os.Args) + if err := app.Run(os.Args); err != nil { + log.Fatalln(err) + } } diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 6dce92d60..0160f2c29 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -84,16 +84,13 @@ func (Pipe) Run(config config.ProjectConfig) error { return err } func sha(client *github.Client, owner, repo, name string, out bytes.Buffer) (*string, error) { - var sha *string file, _, _, err := client.Repositories.GetContents( owner, repo, name, &github.RepositoryContentGetOptions{}, ) if err == nil { - sha = file.SHA - } else { - sha = github.String(fmt.Sprintf("%s", sha256.Sum256(out.Bytes()))) + return file.SHA, err } - return sha, err + return github.String(fmt.Sprintf("%s", sha256.Sum256(out.Bytes()))), err } func buildFormulae(config config.ProjectConfig, client *github.Client) (bytes.Buffer, error) { diff --git a/pipeline/compress/compress.go b/pipeline/compress/compress.go index fff42f1b2..9edd3ac58 100644 --- a/pipeline/compress/compress.go +++ b/pipeline/compress/compress.go @@ -41,31 +41,32 @@ func create(system, arch string, config config.ProjectConfig) error { if err != nil { return err } - defer file.Close() gw := gzip.NewWriter(file) - defer gw.Close() tw := tar.NewWriter(gw) - defer tw.Close() + defer func() { + _ = file.Close() + _ = gw.Close() + _ = tw.Close() + }() for _, f := range config.Files { if err := addFile(tw, f, f); err != nil { return err } } - if err := addFile(tw, config.BinaryName+ext(system), binaryPath(system, arch, config.BinaryName)); err != nil { - return err - } - return nil + return addFile(tw, config.BinaryName+ext(system), binaryPath(system, arch, config.BinaryName)) } -func addFile(tw *tar.Writer, name, path string) error { +func addFile(tw *tar.Writer, name, path string) (err error) { file, err := os.Open(path) if err != nil { - return err + return } - defer file.Close() + defer func() { + _ = file.Close() + }() stat, err := file.Stat() if err != nil { - return err + return } header := new(tar.Header) header.Name = name @@ -78,7 +79,7 @@ func addFile(tw *tar.Writer, name, path string) error { if _, err := io.Copy(tw, file); err != nil { return err } - return nil + return } func nameFor(system, arch, binary string) string { diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 4c1d3f348..9f3c463e4 100644 --- a/pipeline/release/release.go +++ b/pipeline/release/release.go @@ -69,10 +69,16 @@ func upload(client *github.Client, releaseID int, owner, repo, system, arch, bin if err != nil { return err } - defer file.Close() + defer func() { + _ = file.Close() + }() log.Println("Uploading", file.Name(), "...") - _, _, err = client.Repositories.UploadReleaseAsset(owner, repo, releaseID, &github.UploadOptions{ - Name: name, - }, file) + _, _, err = client.Repositories.UploadReleaseAsset( + owner, + repo, + releaseID, + &github.UploadOptions{Name: name}, + file, + ) return err } diff --git a/pipeline/release/release_test.go b/pipeline/release/release_test.go index 349ff9216..410d72d8b 100644 --- a/pipeline/release/release_test.go +++ b/pipeline/release/release_test.go @@ -2,8 +2,9 @@ package release import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestDescription(t *testing.T) {