mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CI: Add CreateTempDir
func and use it in publish packages logic (#57171)
* Add CreateTempDir func and use it in publish packages logic * Fill err return in defer func
This commit is contained in:
parent
b4a03d0cff
commit
e829b50149
@ -69,7 +69,7 @@ func PublishPackages(c *cli.Context) error {
|
|||||||
// In test release mode, the operator should configure different GCS buckets for the package repos,
|
// In test release mode, the operator should configure different GCS buckets for the package repos,
|
||||||
// so should be safe.
|
// so should be safe.
|
||||||
if cfg.ReleaseMode.Mode == config.TagMode {
|
if cfg.ReleaseMode.Mode == config.TagMode {
|
||||||
workDir, err := fsutil.CreateTempFile("")
|
workDir, err := fsutil.CreateTempDir("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -24,3 +24,20 @@ func CreateTempFile(sfx string) (string, error) {
|
|||||||
|
|
||||||
return f.Name(), nil
|
return f.Name(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTempDir generates a temp directory, based on the provided suffix.
|
||||||
|
// A typical generated path looks like /var/folders/abcd/abcdefg/A/1137975807/.
|
||||||
|
func CreateTempDir(sfx string) (string, error) {
|
||||||
|
var suffix string
|
||||||
|
if sfx != "" {
|
||||||
|
suffix = fmt.Sprintf("*-%s", sfx)
|
||||||
|
} else {
|
||||||
|
suffix = sfx
|
||||||
|
}
|
||||||
|
dir, err := os.MkdirTemp("", suffix)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir, nil
|
||||||
|
}
|
@ -26,3 +26,23 @@ func TestCreateTempFile(t *testing.T) {
|
|||||||
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 2)
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateTempDir(t *testing.T) {
|
||||||
|
t.Run("empty suffix, expects pattern like: /var/folders/abcd/abcdefg/A/1137975807/", func(t *testing.T) {
|
||||||
|
filePath, err := CreateTempFile("")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pathParts := strings.Split(filePath, "/")
|
||||||
|
require.Greater(t, len(pathParts), 1)
|
||||||
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("non-empty suffix, expects /var/folders/abcd/abcdefg/A/1137975807-foobar/", func(t *testing.T) {
|
||||||
|
filePath, err := CreateTempFile("foobar")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pathParts := strings.Split(filePath, "/")
|
||||||
|
require.Greater(t, len(pathParts), 1)
|
||||||
|
require.Len(t, strings.Split(pathParts[len(pathParts)-1], "-"), 2)
|
||||||
|
})
|
||||||
|
}
|
@ -122,7 +122,7 @@ func UpdateDebRepo(cfg PublishConfig, workDir string) error {
|
|||||||
repoName = "beta"
|
repoName = "beta"
|
||||||
}
|
}
|
||||||
|
|
||||||
repoRoot, err := fsutil.CreateTempFile("deb-repo")
|
repoRoot, err := fsutil.CreateTempDir("deb-repo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func UpdateRPMRepo(cfg PublishConfig, workDir string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
repoRoot, err := fsutil.CreateTempFile("rpm-repo")
|
repoRoot, err := fsutil.CreateTempDir("rpm-repo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user