summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-10-17 12:26:08 +0100
committerNick Thomas <nick@gitlab.com>2019-10-18 11:47:25 +0100
commitede41ee451dd0aa6d0ecd958c7fadbdb3b63f3e4 (patch)
tree0f80f7394231d39970f23a08ba9ba2ce7051e22c
parentff46222a3a75467d6b22c94abb09a3bb6be60623 (diff)
downloadgitlab-shell-ede41ee451dd0aa6d0ecd958c7fadbdb3b63f3e4.tar.gz
Simplify building and testing the Go components
-rw-r--r--Makefile10
-rwxr-xr-xbin/compile20
-rwxr-xr-xbin/install1
-rw-r--r--go.mod4
-rw-r--r--support/gitlab_config.rb3
-rwxr-xr-xsupport/go-format16
-rwxr-xr-xsupport/go-test12
-rw-r--r--support/go_build.rb37
8 files changed, 9 insertions, 94 deletions
diff --git a/Makefile b/Makefile
index 40ae699..4b0ca2c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
.PHONY: validate verify verify_ruby verify_golang test test_ruby test_golang setup _install build compile check clean
-GO_SOURCES := $(shell find go -name '*.go')
+GO_SOURCES := $(shell find . -name '*.go')
validate: verify test
@@ -10,7 +10,7 @@ verify_ruby:
bundle exec rubocop
verify_golang:
- support/go-format check
+ gofmt -s -l $(GO_SOURCES)
test: test_ruby test_golang
@@ -19,7 +19,7 @@ test_ruby:
bundle exec rspec --color --format d spec
test_golang:
- support/go-test
+ go test ./...
setup: _install bin/gitlab-shell
@@ -29,10 +29,10 @@ _install:
build: bin/gitlab-shell
compile: bin/gitlab-shell
bin/gitlab-shell: $(GO_SOURCES)
- bin/compile
+ GOBIN="$(CURDIR)/bin" go install ./cmd/...
check:
bin/check
clean:
- rm -f bin/gitlab-shell bin/gitlab-shell-authorized-keys-check bin/gitlab-shell-authorized-principals-check
+ rm -f bin/check bin/gitlab-shell bin/gitlab-shell-authorized-keys-check bin/gitlab-shell-authorized-principals-check
diff --git a/bin/compile b/bin/compile
deleted file mode 100755
index e6eacca..0000000
--- a/bin/compile
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'fileutils'
-
-require_relative '../support/go_build'
-include GoBuild
-
-BUILD_BIN_GLOB = File.join(BUILD_DIR, 'bin', '*')
-ROOT_BIN = File.join(ROOT_PATH, 'bin')
-
-def main
- ensure_build_dir_exists
-
- run!(GO_ENV, %W[go install ./cmd/...], chdir: GO_DIR)
- executables = Dir[BUILD_BIN_GLOB]
- FileUtils.chmod(0755, executables)
- FileUtils.cp(executables, ROOT_BIN)
-end
-
-main
diff --git a/bin/install b/bin/install
index d6e5357..323e758 100755
--- a/bin/install
+++ b/bin/install
@@ -1,7 +1,6 @@
#!/usr/bin/env ruby
# Load ROOT_PATH and access the minimum necessary config file
-require_relative '../support/go_build'
require_relative '../support/gitlab_config'
config = GitlabConfig.new
diff --git a/go.mod b/go.mod
index 1083d3a..3aa6c46 100644
--- a/go.mod
+++ b/go.mod
@@ -1,16 +1,14 @@
-module gitlab.com/gitlab-org/gitlab-shell/go
+module gitlab.com/gitlab-org/gitlab-shell
go 1.12
require (
github.com/mattn/go-shellwords v0.0.0-20190425161501-2444a32a19f4
github.com/otiai10/copy v1.0.1
- github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/stretchr/testify v1.3.0
gitlab.com/gitlab-org/gitaly v1.68.0
gitlab.com/gitlab-org/labkit v0.0.0-20190221122536-0c3fc7cdd57c
google.golang.org/grpc v1.24.0
- gopkg.in/DataDog/dd-trace-go.v1 v1.9.0 // indirect
gopkg.in/yaml.v2 v2.2.2
)
diff --git a/support/gitlab_config.rb b/support/gitlab_config.rb
index 1416488..52ac5ee 100644
--- a/support/gitlab_config.rb
+++ b/support/gitlab_config.rb
@@ -1,5 +1,8 @@
require 'yaml'
+# Determine the root of the gitlab-shell directory
+ROOT_PATH = ENV.fetch('GITLAB_SHELL_DIR', File.expand_path('..', __dir__))
+
class GitlabConfig
attr_reader :config
diff --git a/support/go-format b/support/go-format
deleted file mode 100755
index 59af23c..0000000
--- a/support/go-format
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/env ruby
-
-def main(check)
- go_files = Dir['go/**/*.go']
- cmd = %w[gofmt -s -l]
- cmd << '-w' unless check
- cmd += go_files
- output = IO.popen(cmd, 'r', &: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')
diff --git a/support/go-test b/support/go-test
deleted file mode 100755
index 0c043f6..0000000
--- a/support/go-test
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/env ruby
-
-require_relative 'go_build'
-include GoBuild
-
-def main
- ensure_build_dir_exists
- run!(GO_ENV, %w[go test ./...], chdir: GO_DIR)
- puts 'OK'
-end
-
-main
diff --git a/support/go_build.rb b/support/go_build.rb
deleted file mode 100644
index 6f4c92b..0000000
--- a/support/go_build.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# Helper functions to build go code in gitlab-shell
-
-require 'fileutils'
-
-# Determine the root of the gitlab-shell directory
-ROOT_PATH = ENV.fetch('GITLAB_SHELL_DIR', File.expand_path('..', __dir__))
-
-module GoBuild
- GO_DIR = File.join(ROOT_PATH, 'go')
- BUILD_DIR = File.join(ROOT_PATH, 'go_build')
-
- GO_ENV = {
- # $GOBIN controls where 'go install' puts binaries. Prior to go mod,
- # this was $GOPATH/bin.
- 'GOBIN' => File.join(BUILD_DIR, 'bin'),
- # Force the use of go mod, even if $GOPATH is set.
- 'GO111MODULE' => 'on',
- # Downloading dependencies via proxy.golang.org is faster and more
- # reliable than downloading from canonical sources. We need this
- # environment variable because as of Go 1.12, the default is still to
- # download from canonical sources.
- 'GOPROXY' => 'https://proxy.golang.org'
- }.freeze
-
- def ensure_build_dir_exists
- FileUtils.mkdir_p(BUILD_DIR)
- end
-
- def run!(env, cmd, options = {})
- raise "env must be a hash" unless env.is_a?(Hash)
- raise "cmd must be an array" unless cmd.is_a?(Array)
-
- unless system(env, *cmd, options)
- abort "command failed: #{env.inspect} #{cmd.join(' ')}"
- end
- end
-end