Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/upstream/dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
gailazar300 committed Jun 10, 2024
2 parents def18c5 + d887950 commit 6853922
Show file tree
Hide file tree
Showing 100 changed files with 1,494 additions and 4,726 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.22.x
cache: false

- name: Static Code Analysis
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
args: |
--timeout 5m --out-${NO_FUTURE}format colored-line-number --enable errcheck,gosimple,govet,ineffassign,staticcheck,typecheck,unused,gocritic,asasalint,asciicheck,errchkjson,exportloopref,forcetypeassert,makezero,nilerr,unparam,unconvert,wastedassign,usestdlibvars
Expand All @@ -31,10 +32,11 @@ jobs:
- name: Checkout Source
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.22.x
cache: false

- name: Run Gosec Security Scanner
# Temporarily set version 2.18.0 to workaround https://github.com/securego/gosec/issues/1046
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/embedded-jar-test.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/frogbot-scan-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ jobs:
# "frogbot" GitHub environment can approve the pull request to be scanned.
environment: frogbot
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
cache: false

- uses: jfrog/frogbot@v2
env:
JFROG_CLI_LOG_LEVEL: "DEBUG"
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/frogbot-scan-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ jobs:
# The repository scanning will be triggered periodically on the following branches.
branch: [ "dev" ]
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22.x
cache: false

- uses: jfrog/frogbot@v2
env:
JFROG_CLI_LOG_LEVEL: "DEBUG"
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ jobs:
- name: Install pipenv & poetry
run: python -m pip install pipenv poetry

- name: Install Go
uses: actions/setup-go@v3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
go-version: 1.22.x
cache: false

- name: Install NuGet
uses: nuget/setup-nuget@v1
uses: nuget/setup-nuget@v2
with:
nuget-version: 6.x

Expand Down
8 changes: 3 additions & 5 deletions artifactory/commands/buildinfo/adddependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package buildinfo

import (
"errors"
ioutils "github.com/jfrog/gofrog/io"
regxp "regexp"
"strconv"

Expand Down Expand Up @@ -316,15 +317,12 @@ func convertFileInfoToDependencies(files map[string]*fileutils.FileDetails) []bu
func searchItems(spec *spec.SpecFiles, servicesManager artifactory.ArtifactoryServicesManager) (resultReader *content.ContentReader, err error) {
temp := []*content.ContentReader{}
var searchParams services.SearchParams
var reader *content.ContentReader
defer func() {
for _, reader := range temp {
e := reader.Close()
if err == nil {
err = e
}
ioutils.Close(reader, &err)
}
}()
var reader *content.ContentReader
for i := 0; i < len(spec.Files); i++ {
searchParams, err = utils.GetSearchParams(spec.Get(i))
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions artifactory/commands/buildinfo/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package buildinfo
import (
"errors"
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/commandssummaries"
"github.com/jfrog/jfrog-cli-core/v2/commandsummary"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -139,6 +141,10 @@ func (bpc *BuildPublishCommand) Run() error {
return err
}

if err = recordCommandSummary(buildInfo, buildLink); err != nil {
return err
}

logMsg := "Build info successfully deployed."
if bpc.IsDetailedSummary() {
log.Info(logMsg + " Browse it in Artifactory under " + buildLink)
Expand Down Expand Up @@ -229,3 +235,15 @@ func (bpc *BuildPublishCommand) getNextBuildNumber(buildName string, servicesMan
latestBuildNumber++
return strconv.Itoa(latestBuildNumber), nil
}

func recordCommandSummary(buildInfo *buildinfo.BuildInfo, buildLink string) (err error) {
if !commandsummary.ShouldRecordSummary() {
return
}
buildInfo.BuildUrl = buildLink
buildInfoSummary, err := commandsummary.New(commandssummaries.NewBuildInfo(), "build-info")
if err != nil {
return
}
return buildInfoSummary.Record(buildInfo)
}
57 changes: 57 additions & 0 deletions artifactory/commands/commandssummaries/buildinfosummary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package commandssummaries

import (
"fmt"
buildInfo "github.com/jfrog/build-info-go/entities"
"github.com/jfrog/jfrog-cli-core/v2/commandsummary"
"strings"
"time"
)

const timeFormat = "Jan 2, 2006 , 15:04:05"

type BuildInfoSummary struct{}

func NewBuildInfo() *BuildInfoSummary {
return &BuildInfoSummary{}
}

func (bis *BuildInfoSummary) GenerateMarkdownFromFiles(dataFilePaths []string) (finalMarkdown string, err error) {
// Aggregate all the build info files into a slice
var builds []*buildInfo.BuildInfo
for _, path := range dataFilePaths {
var publishBuildInfo buildInfo.BuildInfo
if err = commandsummary.UnmarshalFromFilePath(path, &publishBuildInfo); err != nil {
return
}
builds = append(builds, &publishBuildInfo)
}

if len(builds) > 0 {
finalMarkdown = bis.buildInfoTable(builds)
}
return
}

func (bis *BuildInfoSummary) buildInfoTable(builds []*buildInfo.BuildInfo) string {
// Generate a string that represents a Markdown table
var tableBuilder strings.Builder
tableBuilder.WriteString("\n\n| Build Info | Time Stamp | \n")
tableBuilder.WriteString("|---------|------------| \n")
for _, build := range builds {
buildTime := parseBuildTime(build.Started)
tableBuilder.WriteString(fmt.Sprintf("| [%s](%s) | %s |\n", build.Name+" "+build.Number, build.BuildUrl, buildTime))
}
tableBuilder.WriteString("\n\n")
return tableBuilder.String()
}

func parseBuildTime(timestamp string) string {
// Parse the timestamp string into a time.Time object
buildInfoTime, err := time.Parse(buildInfo.TimeFormat, timestamp)
if err != nil {
return "N/A"
}
// Format the time in a more human-readable format and save it in a variable
return buildInfoTime.Format(timeFormat)
}
32 changes: 32 additions & 0 deletions artifactory/commands/commandssummaries/buildinfosummary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package commandssummaries

import (
buildinfo "github.com/jfrog/build-info-go/entities"
"github.com/stretchr/testify/assert"
"testing"
)

func TestBuildInfoTable(t *testing.T) {
gh := &BuildInfoSummary{}
var builds = []*buildinfo.BuildInfo{
{
Name: "buildName",
Number: "123",
Started: "2024-05-05T12:47:20.803+0300",
BuildUrl: "http://myJFrogPlatform/builds/buildName/123",
},
}
expected := "\n\n| Build Info | Time Stamp | \n|---------|------------| \n| [buildName 123](http://myJFrogPlatform/builds/buildName/123) | May 5, 2024 , 12:47:20 |\n\n\n"
assert.Equal(t, expected, gh.buildInfoTable(builds))
}

func TestParseBuildTime(t *testing.T) {
// Test format
actual := parseBuildTime("2006-01-02T15:04:05.000-0700")
expected := "Jan 2, 2006 , 15:04:05"
assert.Equal(t, expected, actual)
// Test invalid format
expected = "N/A"
actual = parseBuildTime("")
assert.Equal(t, expected, actual)
}
66 changes: 66 additions & 0 deletions artifactory/commands/commandssummaries/uploadsummary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package commandssummaries

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/commandsummary"
)

type UploadSummary struct {
uploadTree *utils.FileTree
uploadedArtifacts ResultsWrapper
PlatformUrl string
JfrogProjectKey string
}

type UploadResult struct {
SourcePath string `json:"sourcePath"`
TargetPath string `json:"targetPath"`
RtUrl string `json:"rtUrl"`
}

type ResultsWrapper struct {
Results []UploadResult `json:"results"`
}

func NewUploadSummary(platformUrl, projectKey string) *UploadSummary {
return &UploadSummary{
PlatformUrl: platformUrl,
JfrogProjectKey: projectKey,
}
}

func (us *UploadSummary) GenerateMarkdownFromFiles(dataFilePaths []string) (markdown string, err error) {
if err = us.loadResults(dataFilePaths); err != nil {
return
}
// Wrap the markdown in a <pre> tags to preserve spaces
markdown = fmt.Sprintf("\n<pre>\n\n\n" + us.generateFileTreeMarkdown() + "</pre>\n\n")
return
}

// Loads all the recorded results from the given file paths.
func (us *UploadSummary) loadResults(filePaths []string) error {
us.uploadedArtifacts = ResultsWrapper{}
for _, path := range filePaths {
var uploadResult ResultsWrapper
if err := commandsummary.UnmarshalFromFilePath(path, &uploadResult); err != nil {
return err
}
us.uploadedArtifacts.Results = append(us.uploadedArtifacts.Results, uploadResult.Results...)
}
return nil
}

func (us *UploadSummary) generateFileTreeMarkdown() string {
us.uploadTree = utils.NewFileTree()
for _, uploadResult := range us.uploadedArtifacts.Results {
us.uploadTree.AddFile(uploadResult.TargetPath, us.buildUiUrl(uploadResult.TargetPath))
}
return us.uploadTree.String()
}

func (us *UploadSummary) buildUiUrl(targetPath string) string {
template := "%sui/repos/tree/General/%s/?projectKey=%s"
return fmt.Sprintf(template, us.PlatformUrl, targetPath, us.JfrogProjectKey)
}
24 changes: 24 additions & 0 deletions artifactory/commands/commandssummaries/uploadsummary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package commandssummaries

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestBuildUiUrl(t *testing.T) {
gh := &UploadSummary{
PlatformUrl: "https://myplatform.com/",
JfrogProjectKey: "myProject",
}
expected := "https://myplatform.com/ui/repos/tree/General/myPath/?projectKey=myProject"
actual := gh.buildUiUrl("myPath")
assert.Equal(t, expected, actual)

gh = &UploadSummary{
PlatformUrl: "https://myplatform.com/",
JfrogProjectKey: "",
}
expected = "https://myplatform.com/ui/repos/tree/General/myPath/?projectKey="
actual = gh.buildUiUrl("myPath")
assert.Equal(t, expected, actual)
}
10 changes: 2 additions & 8 deletions artifactory/commands/dotnet/dotnetcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ func (dc *DotnetCommand) Exec() (err error) {
}
defer func() {
if callbackFunc != nil {
e := callbackFunc()
if err == nil {
err = e
}
err = errors.Join(err, callbackFunc())
}
}()
if err = buildInfoModule.CalcDependencies(); err != nil {
Expand Down Expand Up @@ -272,10 +269,7 @@ func InitNewConfig(configDirPath, repoName string, server *config.ServerDetails,
}
log.Debug("Nuget config file created at:", configFile.Name())
defer func() {
e := configFile.Close()
if err == nil {
err = errorutils.CheckError(e)
}
err = errors.Join(err, errorutils.CheckError(configFile.Close()))
}()

// We would prefer to write the NuGet configuration using the `nuget add source` command,
Expand Down
Loading

0 comments on commit 6853922

Please sign in to comment.