@@ -2,8 +2,6 @@ package main
22
33import (
44 "fmt"
5- "github.com/jfrog/jfrog-client-go/http/httpclient"
6- "github.com/stretchr/testify/require"
75 "net/http"
86 "os"
97 "os/exec"
@@ -12,20 +10,21 @@ import (
1210
1311 biutils "github.com/jfrog/build-info-go/utils"
1412
15- coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
16- clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
17-
1813 buildinfo "github.com/jfrog/build-info-go/entities"
1914 "github.com/jfrog/jfrog-cli-artifactory/artifactory/commands/golang"
15+ "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
2016 "github.com/jfrog/jfrog-cli-core/v2/common/build"
2117 "github.com/jfrog/jfrog-cli-core/v2/common/commands"
2218 "github.com/jfrog/jfrog-cli-core/v2/common/spec"
19+ coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
2320 "github.com/jfrog/jfrog-cli/inttestutils"
24-
2521 "github.com/jfrog/jfrog-cli/utils/tests"
22+ "github.com/jfrog/jfrog-client-go/http/httpclient"
2623 "github.com/jfrog/jfrog-client-go/utils/io/fileutils"
2724 "github.com/jfrog/jfrog-client-go/utils/log"
25+ clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
2826 "github.com/stretchr/testify/assert"
27+ "github.com/stretchr/testify/require"
2928)
3029
3130func TestGoConfigWithModuleNameChange (t * testing.T ) {
@@ -420,3 +419,87 @@ func TestSetupGoCommand(t *testing.T) {
420419 assert .Equal (t , http .StatusOK , res .StatusCode )
421420 }
422421}
422+
423+ // TestGoBuildPublishWithCIVcsProps tests that CI VCS properties are set on Go artifacts
424+ // when running go-publish followed by build-publish in a CI environment (GitHub Actions).
425+ // Go supports direct upload via 'jf gp' which sets CI VCS properties during upload.
426+ func TestGoBuildPublishWithCIVcsProps (t * testing.T ) {
427+ _ , cleanUpFunc := initGoTest (t )
428+ defer cleanUpFunc ()
429+
430+ buildName := tests .GoBuildName + "-civcs"
431+ buildNumber := "1"
432+
433+ // Setup GitHub Actions environment (uses real env vars on CI, mock values locally)
434+ cleanupEnv , actualOrg , actualRepo := tests .SetupGitHubActionsEnv (t )
435+ defer cleanupEnv ()
436+
437+ // Clean old build
438+ inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
439+ defer inttestutils .DeleteBuild (serverDetails .ArtifactoryUrl , buildName , artHttpDetails )
440+
441+ wd , err := os .Getwd ()
442+ assert .NoError (t , err , "Failed to get current dir" )
443+
444+ // Prepare and build the Go project
445+ prepareGoProject ("project1" , t , true )
446+ defer clientTestUtils .ChangeDirAndAssert (t , wd )
447+
448+ // Build the Go project with build info collection
449+ jfrogCli := coretests .NewJfrogCli (execMain , "jfrog" , "" )
450+ err = execGo (jfrogCli , "go" , "build" , "--mod=mod" , "--build-name=" + buildName , "--build-number=" + buildNumber )
451+ assert .NoError (t , err )
452+
453+ // Publish the Go module to Artifactory with build info collection
454+ // This is where CI VCS properties should be set during direct upload
455+ err = execGo (jfrogCli , "gp" , "--build-name=" + buildName , "--build-number=" + buildNumber , "v1.0.0" )
456+ assert .NoError (t , err )
457+
458+ // Publish build info - should also set CI VCS props via batch update if not already set
459+ err = execGo (artifactoryCli , "bp" , buildName , buildNumber )
460+ assert .NoError (t , err )
461+
462+ // Get the published build info to find artifact paths
463+ publishedBuildInfo , found , err := tests .GetBuildInfo (serverDetails , buildName , buildNumber )
464+ assert .NoError (t , err )
465+ assert .True (t , found , "Build info was not found" )
466+
467+ // Create service manager for getting artifact properties
468+ serviceManager , err := utils .CreateServiceManager (serverDetails , 3 , 1000 , false )
469+ assert .NoError (t , err )
470+
471+ // Verify VCS properties on each artifact from build info
472+ // Use same fallback logic as CI VCS: OriginalDeploymentRepo + Path, or Path directly
473+ artifactCount := 0
474+ for _ , module := range publishedBuildInfo .BuildInfo .Modules {
475+ for _ , artifact := range module .Artifacts {
476+ var fullPath string
477+ switch {
478+ case artifact .OriginalDeploymentRepo != "" :
479+ fullPath = artifact .OriginalDeploymentRepo + "/" + artifact .Path
480+ case artifact .Path != "" :
481+ fullPath = artifact .Path
482+ default :
483+ continue // Skip artifacts without any path info
484+ }
485+
486+ props , err := serviceManager .GetItemProps (fullPath )
487+ assert .NoError (t , err , "Failed to get properties for artifact: %s" , fullPath )
488+ assert .NotNil (t , props , "Properties are nil for artifact: %s" , fullPath )
489+
490+ // Validate VCS properties
491+ assert .Contains (t , props .Properties , "vcs.provider" , "Missing vcs.provider on %s" , artifact .Name )
492+ assert .Contains (t , props .Properties ["vcs.provider" ], "github" , "Wrong vcs.provider on %s" , artifact .Name )
493+
494+ assert .Contains (t , props .Properties , "vcs.org" , "Missing vcs.org on %s" , artifact .Name )
495+ assert .Contains (t , props .Properties ["vcs.org" ], actualOrg , "Wrong vcs.org on %s" , artifact .Name )
496+
497+ assert .Contains (t , props .Properties , "vcs.repo" , "Missing vcs.repo on %s" , artifact .Name )
498+ assert .Contains (t , props .Properties ["vcs.repo" ], actualRepo , "Wrong vcs.repo on %s" , artifact .Name )
499+
500+ artifactCount ++
501+ }
502+ }
503+
504+ assert .Greater (t , artifactCount , 0 , "No artifacts were validated for CI VCS properties" )
505+ }
0 commit comments