Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Comment on lines +37 to +38

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ldflags for GoVersion and Platform are using environment variables set in the Makefile. GoReleaser provides built-in template variables for these, which would make this configuration more self-contained and less dependent on the calling environment. Using GoReleaser's variables is a best practice and improves maintainability.

      - -X github.com/Smartling/smartling-cli/cmd/helpers/build.GoVersion={{ .GoVersion }}
      - -X github.com/Smartling/smartling-cli/cmd/helpers/build.Platform={{ .Os }}/{{ .Arch }}


archives:
- format: tar.gz
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

checksum:
disable: true
Comment on lines +44 to +45

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Disabling checksum generation is not recommended. Checksums are crucial for verifying the integrity of the downloaded artifacts, ensuring they haven't been corrupted or tampered with. Please enable checksum generation unless there is a strong reason not to. You can remove this section to use GoReleaser's default (and recommended) behavior.

checksum:
  name_template: 'checksums.txt'

4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 "*"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason for this change.
Also, don't forget that jenkins does build in a clean env - docker.

'''
Comment on lines +35 to +37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This aws s3 cp command appears to be incorrect and will likely fail to copy any files.

  • It's missing the --recursive flag, which is required to copy the contents of a directory (${WORKSPACE}/bin).
  • The --exclude "*" --include "*" flags are ineffective without --recursive and are likely not what's intended. If the goal is to copy all files from the directory, these flags should be removed.

The previous version of this command used --recursive, which seems correct for this use case.

                sh "aws-profile connectors-staging aws s3 cp ${WORKSPACE}/bin s3://smartling-connectors-releases/cli/ --recursive --acl public-read"

}
}

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
MAINTAINER = Alex Koval <[email protected]>
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
@

Expand Down
21 changes: 21 additions & 0 deletions cmd/build/build.go
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 2 additions & 1 deletion cmd/cmd_root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/Smartling/smartling-cli/cmd/helpers/build"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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) {
Expand Down
46 changes: 46 additions & 0 deletions cmd/helpers/build/build.go
Original file line number Diff line number Diff line change
@@ -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
`,
Comment on lines +27 to +37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The multiline string for the build information starts with a newline character. When this is printed with fmt.Println, it will result in an extra blank line at the beginning of the output, which might not be the intended formatting. Removing the leading newline from the string literal will produce cleaner output.

	return fmt.Sprintf(\`Smartling-cli is a library and CLI tool for managing Smartling projects.\n\nVersion:       %s\nReleaseTag:    %s\nGitCommit:     %s\nBuildDate:     %s\nBuiltBy:       %s\nGoVersion:     %s\nPlatform:      %s\n\`,

CliVersion,
ReleaseTag,
CommitID,
Date,
BuiltBy,
GoVersion,
Platform,
)
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down