mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-03 15:02:35 +02:00
fix(codeqlExecuteScan): exclude codeqlDB from uploaded sources to github (#4652)
* fixed unzipping db sources without db dir * fixed tests
This commit is contained in:
parent
5dea6237f2
commit
df0c9c7b3f
@ -118,7 +118,7 @@ func (uploader *GitUploaderInstance) UploadProjectToGithub() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
zipPath := path.Join(uploader.dbDir, SrcZip)
|
zipPath := path.Join(uploader.dbDir, SrcZip)
|
||||||
err = unzip(zipPath, tmpDir, strings.Trim(srcLocationPrefix, fmt.Sprintf("%c", os.PathSeparator)))
|
err = unzip(zipPath, tmpDir, strings.Trim(srcLocationPrefix, fmt.Sprintf("%c", os.PathSeparator)), strings.Trim(uploader.dbDir, fmt.Sprintf("%c", os.PathSeparator)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ func push(r repository, token string) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func unzip(zipPath, targetDir, srcDir string) error {
|
func unzip(zipPath, targetDir, srcDir, dbDir string) error {
|
||||||
r, err := zip.OpenReader(zipPath)
|
r, err := zip.OpenReader(zipPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -277,7 +277,7 @@ func unzip(zipPath, targetDir, srcDir string) error {
|
|||||||
fNameSplit[0] = strings.Replace(fNameSplit[0], "_", ":", 1)
|
fNameSplit[0] = strings.Replace(fNameSplit[0], "_", ":", 1)
|
||||||
fName = strings.Join(fNameSplit, fmt.Sprintf("%c", os.PathSeparator))
|
fName = strings.Join(fNameSplit, fmt.Sprintf("%c", os.PathSeparator))
|
||||||
}
|
}
|
||||||
if !strings.Contains(fName, srcDir) {
|
if !strings.Contains(fName, srcDir) || strings.Contains(fName, dbDir) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,6 +210,7 @@ func TestUnzip(t *testing.T) {
|
|||||||
srcFilenames := []string{
|
srcFilenames := []string{
|
||||||
filepath.Join(sourceDir, "file1"),
|
filepath.Join(sourceDir, "file1"),
|
||||||
filepath.Join(sourceDir, "file2"),
|
filepath.Join(sourceDir, "file2"),
|
||||||
|
filepath.Join(sourceDir, "codeqlDB"),
|
||||||
filepath.Join(sourceDir, "subfolder1", "file1"),
|
filepath.Join(sourceDir, "subfolder1", "file1"),
|
||||||
filepath.Join(sourceDir, "subfolder1", "file2"),
|
filepath.Join(sourceDir, "subfolder1", "file2"),
|
||||||
filepath.Join(sourceDir, "subfolder2", "file1"),
|
filepath.Join(sourceDir, "subfolder2", "file1"),
|
||||||
@ -218,7 +219,7 @@ func TestUnzip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
assert.NoError(t, unzip(zipPath, targetDir, sourceDir))
|
assert.NoError(t, unzip(zipPath, targetDir, sourceDir, "codeqlDB"))
|
||||||
targetFilenames := []string{
|
targetFilenames := []string{
|
||||||
filepath.Join(targetDir, "file1"),
|
filepath.Join(targetDir, "file1"),
|
||||||
filepath.Join(targetDir, "file2"),
|
filepath.Join(targetDir, "file2"),
|
||||||
@ -247,7 +248,7 @@ func TestUnzip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
assert.NoError(t, unzip(zipPath, targetDir, sourceDir))
|
assert.NoError(t, unzip(zipPath, targetDir, sourceDir, "codeqlDB"))
|
||||||
checkExistedFiles(t, targetDir, filenames)
|
checkExistedFiles(t, targetDir, filenames)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -264,7 +265,7 @@ func TestUnzip(t *testing.T) {
|
|||||||
defer os.RemoveAll(sourceDir)
|
defer os.RemoveAll(sourceDir)
|
||||||
zipPath := filepath.Join(sourceDir, "src.zip")
|
zipPath := filepath.Join(sourceDir, "src.zip")
|
||||||
|
|
||||||
assert.Error(t, unzip(zipPath, targetDir, sourceDir))
|
assert.Error(t, unzip(zipPath, targetDir, sourceDir, "codeqlDB"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("extra files in zip", func(t *testing.T) {
|
t.Run("extra files in zip", func(t *testing.T) {
|
||||||
@ -294,7 +295,7 @@ func TestUnzip(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
assert.NoError(t, unzip(zipPath, targetDir, sourceDir))
|
assert.NoError(t, unzip(zipPath, targetDir, sourceDir, "codeqlDB"))
|
||||||
targetFilenames := []string{
|
targetFilenames := []string{
|
||||||
filepath.Join(targetDir, "file1"),
|
filepath.Join(targetDir, "file1"),
|
||||||
filepath.Join(targetDir, "file2"),
|
filepath.Join(targetDir, "file2"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user