summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml1
-rwxr-xr-xsupport/go-format16
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')