diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-04-11 17:57:08 +0200 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-04-12 11:26:26 +0200 |
commit | 0fba550db58ca508cd92c88e1751e9362b60f100 (patch) | |
tree | fd7fc21ea27ab49c6e62d4339fd6f3a336443811 | |
parent | 684599daddefd2b6149c5f99a620424f6f26166c (diff) | |
download | gitlab-shell-0fba550db58ca508cd92c88e1751e9362b60f100.tar.gz |
Add hello-world executable
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rwxr-xr-x | bin/compile | 36 | ||||
-rw-r--r-- | go/README.md | 6 | ||||
-rw-r--r-- | go/cmd/hello-world/main.go | 7 |
5 files changed, 54 insertions, 0 deletions
@@ -11,3 +11,5 @@ tags .bundle/ custom_hooks hooks/*.d +/go_build +/bin/hello-world @@ -66,9 +66,12 @@ make sudo make install ``` +To install gitlab-shell you also need a Go compiler version 1.5 or newer. https://golang.org/dl/ + ## Setup ./bin/install + ./bin/compile ## Check diff --git a/bin/compile b/bin/compile new file mode 100755 index 0000000..e9936ee --- /dev/null +++ b/bin/compile @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby + +require 'fileutils' + +# This will set the ROOT_PATH variable +require_relative '../lib/gitlab_init' + +GO_DIR = 'go' +GOPATH = File.join(ROOT_PATH, 'go_build') +GO_PACKAGE = File.join('gitlab.com/gitlab-org/gitlab-shell', GO_DIR) + +def main + FileUtils.rm_rf(GOPATH) + build_source_dir = File.join(GOPATH, 'src', GO_PACKAGE) + FileUtils.mkdir_p(build_source_dir) + FileUtils.cp_r(File.join(ROOT_PATH, GO_DIR, '.'), build_source_dir) + env = { + 'GOPATH' => GOPATH, + 'GO15VENDOREXPERIMENT' => '1', + } + run!(env, %W[go install #{GO_PACKAGE}/cmd/...]) + executables = Dir[File.join(GOPATH, 'bin', '*')] + FileUtils.chmod(0755, executables) + FileUtils.cp(executables, File.join(ROOT_PATH, 'bin')) +end + +def run!(env, cmd) + raise "env must be a hash" unless env.is_a?(Hash) + raise "cmd must be an array" unless cmd.is_a?(Array) + + if !system(env, *cmd) + abort "command failed: #{env.inspect} #{cmd.join(' ')}" + end +end + +main diff --git a/go/README.md b/go/README.md new file mode 100644 index 0000000..dfaa0da --- /dev/null +++ b/go/README.md @@ -0,0 +1,6 @@ +# Go executables for gitlab-shell + +This directory contains Go executables for use in gitlab-shell. To add +a new command `foobar` create a subdirectory `cmd/foobar` and put your +code in `package main` under `cmd/foobar`. This will automatically get +compiled into `bin/foobar` by `../bin/compile`. diff --git a/go/cmd/hello-world/main.go b/go/cmd/hello-world/main.go new file mode 100644 index 0000000..f7b60bd --- /dev/null +++ b/go/cmd/hello-world/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello, world!") +} |