检查持续集成的格式。

huangapple go评论88阅读模式
英文:

Check format for Continous integration

问题

我正在尝试编写一个Makefile命令,如果Go代码格式不正确,将输出一个错误。这是为了CI步骤。我在如何在Makefile中使其工作方面遇到了困难。这个解决方案在bash命令行上可以工作:

! gofmt -l . 2>&1 | read

但是将其复制到Makefile中:

ci-format:
    @echo "$(OK_COLOR)==> Checking formatting$(NO_COLOR)"
    @go fmt ./...
    @! gofmt -l . 2>&1 | read

我得到以下错误:

/bin/sh: 1: read: arg count
英文:

I am trying to write a Makefile command that will output an error if the Go code is not correctly formatted. This is for a CI step. I am struggling with how to get it working in the make file. This solution works on the bash command line:

! gofmt -l . 2>&1 | read

But copying this into the Makefile:

ci-format:
    @echo "$(OK_COLOR)==> Checking formatting$(NO_COLOR)"
    @go fmt ./...
    @! gofmt -l . 2>&1 | read

I get the following error:

/bin/sh: 1: read: arg count

答案1

得分: 15

这些天,我使用golangci-lint,其中包括gofmt检查作为一个选项。

但是,如果出于某种原因你想自己做这个,我之前用于这个目的的命令是:

diff -u <(echo -n) <(gofmt -d ./)

例如,你可以查看我项目中的.travis.yml文件。

英文:

These days, I use golangci-lint, which includes gofmt checking as an option.

But if for some reason you want to do this yourself, the command I previously used for precisely that purpose is:

diff -u <(echo -n) <(gofmt -d ./)

See, for example, the .travis.yml files on one of my projects.

huangapple
  • 本文由 发表于 2017年2月28日 21:30:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/42510140.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定