Skip to content

Commit

Permalink
Merge branch 'version' into 'master'
Browse files Browse the repository at this point in the history
cmd: version command

See merge request devel/gophercap!1
  • Loading branch information
markuskont committed Jan 11, 2021
2 parents 2d2dca6 + 218359a commit 867efa0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ build-binary-buster:
- ./build/ci/build_debian.sh
after_script:
- gzip gopherCap
rules:
- if: '$CI_BUILD_TAG =~ /^build-.*/'
only:
- tags

build-binary-ubuntu-2004:
image: ubuntu:20.04
Expand All @@ -23,5 +23,5 @@ build-binary-ubuntu-2004:
- ./build/ci/build_debian.sh
after_script:
- gzip gopherCap
rules:
- if: '$CI_BUILD_TAG =~ /^build-.*/'
only:
- tags
4 changes: 3 additions & 1 deletion build/ci/build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ GO_VERSION=${GO_VERSION:-1.15.6}
GOROOT_BASE=${GOROOT_BASE:-/opt}
GOROOT=$GOROOT_BASE/go
GOPATH=${GOPATH:-/var/go}
GOPHERCAP_VERSION=${CI_COMMIT_TAG:-git $CI_COMMIT_SHORT_SHA}

apt-get update && apt-get install -y libpcap-dev wget build-essential
wget -O /tmp/golang.tgz https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz
tar -xzf /tmp/golang.tgz -C $GOROOT_BASE
mkdir $GOPATH
$GOROOT/bin/go get -u ./
$GOROOT/bin/go build -o ./gopherCap ./

$GOROOT/bin/go build -ldflags="-X 'gopherCap/cmd.Version=$GOPHERCAP_VERSION'" -o ./gopherCap ./
./gopherCap --help
37 changes: 37 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright © 2020 Stamus Networks [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var Version = "development"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Shows gopherCap version.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("gopherCap", Version)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}

0 comments on commit 867efa0

Please sign in to comment.