Skip to content

Commit

Permalink
feat: [CI-16038]: Added Build-Tag support for VCS and updated go version
Browse files Browse the repository at this point in the history
  • Loading branch information
architmallik7 committed Feb 5, 2025
1 parent aea7359 commit 3445f1f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module drone-artifactory-docker-buildinfo

go 1.22.5
go 1.22.7

require (
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/sirupsen/logrus v1.9.3
)

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Args struct {
CommitSha string `envconfig:"DRONE_COMMIT_SHA"`
RepoURL string `envconfig:"DRONE_GIT_HTTP_URL"`
BranchName string `envconfig:"DRONE_REPO_BRANCH"`
TagName string `envconfig:"DRONE_TAG"`
CommitMessage string `envconfig:"DRONE_COMMIT_MESSAGE"`
DefaultPath string `envconfig:"DRONE_WORKSPACE"`
}
Expand Down Expand Up @@ -162,10 +163,20 @@ func Exec(ctx context.Context, args Args) error {

// If Git information is available, add it to the build info
logrus.Info("Setting Git Properties")
if args.RepoURL != "" && args.BranchName != "" && args.CommitSha != "" {
hasVCSInfo := args.RepoURL != "" && args.CommitSha != "" &&
(args.BranchName != "" || args.TagName != "")

if hasVCSInfo {
logrus.WithFields(logrus.Fields{
"repo_url": args.RepoURL,
"commit_sha": args.CommitSha,
"branch_name": args.BranchName,
"tag_name": args.TagName,
}).Info("Adding VCS information")

cmdArgs = []string{"jfrog", "rt", "build-add-git", args.BuildName, args.BuildNumber, args.GitPath}
if err := runCommand(cmdArgs); err != nil {
logrus.Fatalln("error executing jfrog rt build-add-git command:", err)
logrus.Warnf("error executing jfrog rt build-add-git command: %v", err)
}
}

Expand Down

0 comments on commit 3445f1f

Please sign in to comment.