diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-05-03 16:10:40 +0200 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-05-23 15:26:35 +0200 |
commit | 5fd923bd748cf789d687dd2e2eac9cb308a1febb (patch) | |
tree | 2b011b05bf8932d9b35f6ef8f4a726a7a3400b0f | |
parent | e3dc9c769f7ba74189b00a63def7cdb2a99f57d9 (diff) | |
download | gitlab-shell-5fd923bd748cf789d687dd2e2eac9cb308a1febb.tar.gz |
Check go formatting in CI
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rwxr-xr-x | support/go-format | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03cd4bf..116fd43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,3 +52,4 @@ go: - which go - bin/compile - support/go-test + - support/go-format check diff --git a/support/go-format b/support/go-format new file mode 100755 index 0000000..d74fc46 --- /dev/null +++ b/support/go-format @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +def main(check) + go_files = Dir['go/**/*.go'].reject { |p| p.start_with?('go/vendor/') } + cmd = %w[gofmt -s -l] + cmd << '-w' unless check + cmd += go_files + output = IO.popen(cmd, 'r') { |io| io.read } + $stdout.write(output) + abort 'gofmt failed' unless $?.success? + if check && output.lines.any? { |l| l != "\n" } + abort "\nPlease run #{$0} to fix formatting" + end +end + +main(ARGV.first == 'check') |