diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..54b3635 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,45 @@ +version: 2 + +project_name: smartling-cli +dist: bin + +release: + name_template: "Version {{.Version}}" + disable: true + github: + owner: Smartling + name: smartling-cli + +builds: + - + goos: + - linux + - darwin + - windows + + goarch: + - amd64 + - arm64 + - arm + + ignore: + - goos: darwin + goarch: arm + - goos: windows + goarch: arm + + ldflags: + - -s -w + - -X github.com/Smartling/smartling-cli/cmd/helpers/build.Version={{ .Version }} + - -X github.com/Smartling/smartling-cli/cmd/helpers/build.ReleaseTag={{ .Tag }} + - -X github.com/Smartling/smartling-cli/cmd/helpers/build.CommitID={{ .FullCommit }} + - -X github.com/Smartling/smartling-cli/cmd/helpers/build.Date={{ .Date }} + - -X github.com/Smartling/smartling-cli/cmd/helpers/build.GoVersion={{ .Env.SMARTLING_CLI_GOVERSION }} + - -X github.com/Smartling/smartling-cli/cmd/helpers/build.Platform={{ .Env.SMARTLING_CLI_PLATFORM }} + +archives: + - format: tar.gz + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + +checksum: + disable: true diff --git a/Jenkinsfile b/Jenkinsfile index 457711f..923648a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,7 +32,9 @@ pipeline { branch env.TARGET_BRANCH } steps { - sh "aws-profile connectors-staging aws s3 cp ${WORKSPACE}/bin s3://smartling-connectors-releases/cli/ --recursive --acl public-read" + sh ''' + aws-profile connectors-staging aws s3 cp ${WORKSPACE}/bin s3://smartling-connectors-releases/cli/ --acl public-read --exclude "*" --include "*" + ''' } } diff --git a/Makefile b/Makefile index e72bfdf..fa5a8e3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ MAINTAINER = Alex Koval DESCRIPTION = CLI for Smartling Platform +build_releaser: + export SMARTLING_CLI_PLATFORM=$$(go env GOOS)/$$(go env GOARCH); \ + export SMARTLING_CLI_GOVERSION=$$(go version | awk '{print $$3}'); \ + goreleaser release --clean --skip=publish --snapshot + all: clean get build @ diff --git a/cmd/build/build.go b/cmd/build/build.go new file mode 100644 index 0000000..60eadf9 --- /dev/null +++ b/cmd/build/build.go @@ -0,0 +1,21 @@ +package build + +import ( + "fmt" + + "github.com/Smartling/smartling-cli/cmd/helpers/build" + + "github.com/spf13/cobra" +) + +// NewBuildCmd creates a new build command. +func NewBuildCmd() *cobra.Command { + buildCmd := &cobra.Command{ + Use: "build", + Short: "Print the build information", + Run: func(_ *cobra.Command, _ []string) { + fmt.Println(build.String()) + }, + } + return buildCmd +} diff --git a/cmd/cmd_root.go b/cmd/cmd_root.go index 5cc7ca6..1c5b8de 100644 --- a/cmd/cmd_root.go +++ b/cmd/cmd_root.go @@ -1,6 +1,7 @@ package cmd import ( + "github.com/Smartling/smartling-cli/cmd/helpers/build" "strings" "github.com/spf13/cobra" @@ -30,7 +31,7 @@ func NewRootCmd() *cobra.Command { rootCmd := &cobra.Command{ Use: "smartling-cli", Short: "Manage translation files using Smartling CLI.", - Version: "2.1", + Version: build.CliVersion, Long: `Manage translation files using Smartling CLI. Complete documentation is available at https://www.smartling.com`, PersistentPreRun: func(cmd *cobra.Command, _ []string) { diff --git a/cmd/helpers/build/build.go b/cmd/helpers/build/build.go new file mode 100644 index 0000000..4c92325 --- /dev/null +++ b/cmd/helpers/build/build.go @@ -0,0 +1,46 @@ +package build + +import ( + "fmt" +) + +// These variables will be set via ldflags at build time. +var ( + // CliVersion is version information + CliVersion = "2.1" + // ReleaseTag is the git tag + ReleaseTag = "" + // CommitID is the git commit hash + CommitID = "" + // Date is date of binary built + Date = "" + // BuiltBy is into about builder + BuiltBy = "GoReleaser" + // GoVersion is Go version + GoVersion = "" + // Platform is platform + Platform = "" +) + +// String returns the version information as a formatted string. +func String() string { + return fmt.Sprintf(` +Smartling-cli is a library and CLI tool for managing Smartling projects. + +Version: %s +ReleaseTag: %s +GitCommit: %s +BuildDate: %s +BuiltBy: %s +GoVersion: %s +Platform: %s +`, + CliVersion, + ReleaseTag, + CommitID, + Date, + BuiltBy, + GoVersion, + Platform, + ) +} diff --git a/main.go b/main.go index fab0acc..af1e9ca 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/Smartling/smartling-cli/cmd" + "github.com/Smartling/smartling-cli/cmd/build" "github.com/Smartling/smartling-cli/cmd/files" deletecmd "github.com/Smartling/smartling-cli/cmd/files/delete" importcmd "github.com/Smartling/smartling-cli/cmd/files/import" @@ -26,6 +27,9 @@ func main() { rootCmd := cmd.NewRootCmd() + buildCmd := build.NewBuildCmd() + rootCmd.AddCommand(buildCmd) + initSrvInitializer := initialize.NewSrvInitializer() initCmd := initialize.NewInitCmd(initSrvInitializer) rootCmd.AddCommand(initCmd)