Skip to content

Commit

Permalink
add --exclusions flag to go-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
sarao1310 committed Jul 5, 2023
1 parent 6edbd46 commit b3c2eb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions artifactory/commands/golang/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,12 @@ func archiveProject(writer io.Writer, dir, mod, version string, excludedPatterns
}
}

excludedPath, err := isPathExcluded(filePath, excludePathPattern)
if err != nil {
return err
}
if excludedPath {
return filepath.SkipDir
}

if info.Mode().IsRegular() {
if !isVendoredPackage(slashPath) {
excludedPath, err := isPathExcluded(filePath, excludePathPattern)
if err != nil {
return err
}
if !isVendoredPackage(slashPath) && !excludedPath {
files = append(files, dirFile{
filePath: filePath,
slashPath: slashPath,
Expand Down Expand Up @@ -163,7 +159,11 @@ func getAbsolutePaths(exclusionPatterns []string) ([]string, error) {

func isPathExcluded(path string, excludePathPattern string) (excludedPath bool, err error) {
if len(excludePathPattern) > 0 {
excludedPath, err = regexp.MatchString(path, excludePathPattern)
fullPath, err := filepath.Abs(path)
if err != nil {
return false, err
}
excludedPath, err = regexp.MatchString(excludePathPattern, fullPath)

Check failure on line 166 in artifactory/commands/golang/archive.go

View workflow job for this annotation

GitHub Actions / Static-Check

ineffectual assignment to err (ineffassign)
}
return
}
Expand Down
1 change: 1 addition & 0 deletions artifactory/commands/golang/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestArchiveProject(t *testing.T) {
{buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"testdata/dir2/*", "testdata/dir3/*"}, map[utils.Algorithm]string{utils.MD5: "28617d6e74fce3dd2bab21b1bd65009b", utils.SHA1: "410814fbf21afdfb9c5b550151a51c2e986447fa", utils.SHA256: "e877c07315d6d3ad69139035defc08c04b400b36cd069b35ea3c2960424f2dc6"}},
{buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"testdata/dir2/*", "testdata/dir4/*"}, map[utils.Algorithm]string{utils.MD5: "bbe78a98ba10c1428f3a364570015e11", utils.SHA1: "99fd22ea2fe9c2c48124e741881fc3a555458a7e", utils.SHA256: "e2299f3c4e1f22d36befba191a347783dc2047e8e38cf6b9b96c273090f6e25b"}},
{buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"testdata/dir3/*"}, map[utils.Algorithm]string{utils.MD5: "c2a2dd6a7af84c2d88a48caf0c3aec34", utils.SHA1: "193d761317a602d18566561678b7bddc4773385c", utils.SHA256: "3efcd8b0d88081ec64333ff98b43616d283c4d52ed26cd7c8df646d9ea452c31"}},
{buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0", []string{"*.txt"}, map[utils.Algorithm]string{utils.MD5: "e93953b4be84d7753e0f33589b7dc4ba", utils.SHA1: "280c7492f57262b6e0af56b06c9db6a128e32ab9", utils.SHA256: "e7357986c59bf670af1e2f4868edb1406a87d328b7681b15cf038491cdc7e88c"}},
}
for _, testData := range archiveWithExclusion {
if err = archiveProject(testData.buff, testData.filePath, testData.mod, testData.version, testData.excludedPatterns); err != nil {
Expand Down

0 comments on commit b3c2eb2

Please sign in to comment.