From cfe1b9fbc2b8772d6b879e784814c52ab9c93b6a Mon Sep 17 00:00:00 2001 From: Yvonnick Esnault Date: Tue, 6 Feb 2018 09:01:57 +0100 Subject: [PATCH] chore: package with cds (#135) Signed-off-by: Yvonnick Esnault --- .travis.yml | 35 ----------------------------- cli/venom/update/cmd.go | 24 +++++++++----------- package.sh | 3 ++- release.sh | 50 ----------------------------------------- venom.go | 8 +++---- 5 files changed, 16 insertions(+), 104 deletions(-) delete mode 100644 .travis.yml delete mode 100755 release.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a37630b7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: go -go: -- tip - -env: - global: - - PROJECT_NAME="venom" - - PROJECT_PATH="github.com/ovh" - -install: true - -script: - - go test github.com/ovh/venom/lib - - chmod +x package.sh && ./package.sh - -before_deploy: - - gem install mime-types -v 2.6.2 - -deploy: - provider: releases - api_key: - secure: ai5IY0c73/opsw3XoEAuu5s0qu1blRC0Ru5tz9jjJ/VnIZQH9MgzWIDN2bvtI/TvXsmHyYl5+TSx4DzuqBAeaYDhwkO2ETLZxhTUQrz2gQUfYDljcXJ+8D1pcetg0hxzr86VEnAGHDPm/qiQvvwFmNY8Qz81QpeAE6nx6sIflcPyqLqGha8crFTiGnm0kVMZlTw3G81GCi9cllwOvFuvWw9qbutIPdhJlv/HSBh3ifjZAPoG7vUpJs807eOnv7tIwtfBvphPFqq6yjiUbNAGmpNWDkpNDYRbfYwXDUu7fK4q/b/ZnEiFPxp/PJ4Kh7eTc2Y9kSzlKHwHoBQIIpS2LJmn6xo8F8HQyB1xNnAW1fp3PyIJzaprFxkHB2lBG8Ep9eQKaVwq2Mh7w+xXTg5eOKKhpXn6aAdG6/U96NrsXy3xahnxk2I3pOoQRbYwSb9Uvam6sgvYXxKah9O98GB+hUiezURawfOzrSdtPYTfArm+vCMb+MBoMTeRi9nCc7utSTGgNNvUapotLhxOuPzNE473ov/WxZ+G531vCVwEs1w9nJajRQFWqNbraXx4jlSn+0wuLqSFes0rpWsi4laloydlFZs4ZiwyKsjAMieVfYbEvyTnLCz4ZCRz7y2pmyEDSMNlEg4NAIuqkOoxtNaBsqLhXqj7p+7fiD0wBO7yARc= - file: - - cli/venom/bin/venom-darwin-386 - - cli/venom/bin/venom-darwin-amd64 - - cli/venom/bin/venom-freebsd-386 - - cli/venom/bin/venom-freebsd-amd64 - - cli/venom/bin/venom-linux-386 - - cli/venom/bin/venom-linux-amd64 - - cli/venom/bin/venom-linux-arm - - cli/venom/bin/venom-windows-386 - - cli/venom/bin/venom-windows-amd64 - on: - repo: ovh/venom - tags: true diff --git a/cli/venom/update/cmd.go b/cli/venom/update/cmd.go index 7c120718..703e41c5 100644 --- a/cli/venom/update/cmd.go +++ b/cli/venom/update/cmd.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + "runtime" + "strings" "github.com/google/go-github/github" "github.com/inconshreveable/go-update" @@ -11,8 +13,6 @@ import ( "github.com/spf13/cobra" ) -// used by CI to inject architecture (linux-amd64, etc...) at build time -var architecture string var urlGitubReleases = "https://github.com/ovh/venom/releases" // Cmd update @@ -21,11 +21,11 @@ var Cmd = &cobra.Command{ Short: "Update venom to the latest release version: venom update", Long: `venom update`, Run: func(cmd *cobra.Command, args []string) { - doUpdate("", architecture) + doUpdate() }, } -func getURLArtifactFromGithub(architecture string) string { +func getURLArtifactFromGithub() string { client := github.NewClient(nil) release, resp, err := client.Repositories.GetLatestRelease(context.TODO(), "ovh", "venom") if err != nil { @@ -34,7 +34,9 @@ func getURLArtifactFromGithub(architecture string) string { if len(release.Assets) > 0 { for _, asset := range release.Assets { - if *asset.Name == "venom-"+architecture { + assetName := strings.Replace(*asset.Name, ".", "-", -1) + current := fmt.Sprintf("venom-%s-%s", runtime.GOOS, runtime.GOARCH) + if assetName == current { return *asset.BrowserDownloadURL } } @@ -55,14 +57,8 @@ func getContentType(resp *http.Response) string { return "" } -func doUpdate(baseurl, architecture string) { - if architecture == "" { - text := "You seem to have a custom build of venom.\n" - text += "Please download latest release on %s\n" - cli.Exit(text, urlGitubReleases) - } - - url := getURLArtifactFromGithub(architecture) +func doUpdate() { + url := getURLArtifactFromGithub() fmt.Printf("Url to update venom: %s\n", url) resp, err := http.Get(url) @@ -79,7 +75,7 @@ func doUpdate(baseurl, architecture string) { cli.Exit("Error http code: %d, url called: %s\n", resp.StatusCode, url) } - fmt.Printf("Getting latest release from : %s ...\n", url) + fmt.Printf("Getting latest release from: %s ...\n", url) defer resp.Body.Close() if err = update.Apply(resp.Body, update.Options{}); err != nil { cli.Exit("Error when updating venom from url: %s err:%s\n", url, err.Error()) diff --git a/package.sh b/package.sh index 69bc2f2f..19534110 100755 --- a/package.sh +++ b/package.sh @@ -9,5 +9,6 @@ for DIST in `go tool dist list | grep -v '^android/' | grep -v '^nacl/' | grep - echo "Building ${architecture} ${path}" export GOOS=$GOOS export GOARCH=$GOARCH - go build -ldflags "-X github.com/ovh/venom/cli/venom/update.architecture=${architecture}" -o bin/venom.${architecture} + + go build -ldflags "-X github.com/ovh/venom.Version=${GIT_DESCRIBE}" -o bin/venom.${architecture} done diff --git a/release.sh b/release.sh deleted file mode 100755 index 77bcc43f..00000000 --- a/release.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -# -# Tag release and push to origin remotes. -# - -if [ $# -ne 1 ] -then - echo "Tag and push master to 'origin' remotes" - echo "Usage: `basename $0` version" - exit 1 -fi - -version="$1" -current_branch=`git rev-parse --abbrev-ref HEAD` - -# Check we are on master branch -if [ "$current_branch" != "master" ] -then - echo -e "$0 only works from *master* branch. When ready, Please run \n\tgit checkout master\n\t$0" - exit 1 -fi - -# Check there is no pending changes --> branch is clean -if [ -n "`git status --porcelain`" ] -then - echo "There are pending/uncommitted changes in current branch." - echo "Please commit or stash them." - exit 1 -fi - -# Ensure commit is tagged and annotated -current_tag=$(git describe --exact-match 2>/dev/null) -if [ -n "$current_tag" ] -then - if [ "$current_tag" != "v$version" ] - then - echo "Error: version mismatch '$current_tag' != 'v$version'" - fi -else - sed -i.bak "s/const Version =.*/const Version = \"$version\"/g" venom.go - rm -f venom.go.bak - - git commit -am "[auto] bump version to v$version" - git tag -s "v$version" -fi - -echo "Pushing master and 'v$version'" -git push origin master -git push origin "v$version" diff --git a/venom.go b/venom.go index 2694aa1f..40af262b 100644 --- a/venom.go +++ b/venom.go @@ -8,10 +8,10 @@ import ( pb "gopkg.in/cheggaaa/pb.v1" ) -// Version of Venom -// One Line for this, used by release.sh script -// Keep "const Version on one line" -const Version = "0.16.0" +var ( + //Version is set with -ldflags "-X github.com/ovh/venom/venom.Version=$(VERSION)" + Version = "snapshot" +) func New() *Venom { v := &Venom{