test: extract GenerateCIArtifactName to test helpers
A bit of deduplication can never hurt. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
9f80c2ac8e
commit
18258238d9
3 changed files with 24 additions and 33 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -226,3 +227,17 @@ func SetUpTemporaryRepository() (string, error) {
|
|||
func TearDownTemporaryRepository(dir string) error {
|
||||
return os.RemoveAll(dir)
|
||||
}
|
||||
|
||||
// GenerateCIArtifactName generates a new identifier for CI artifacts which is based
|
||||
// on environment variables specified by Jenkins
|
||||
// note: in case of migration to sth else like Github Actions, change it to whatever variables GH Action provides
|
||||
func GenerateCIArtifactName(prefix string) (string, error) {
|
||||
distroCode := os.Getenv("DISTRO_CODE")
|
||||
branchName := os.Getenv("BRANCH_NAME")
|
||||
buildId := os.Getenv("BUILD_ID")
|
||||
if branchName == "" || buildId == "" || distroCode == "" {
|
||||
return "", fmt.Errorf("The environment variables must specify BRANCH_NAME, BUILD_ID, and DISTRO_CODE")
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s-%s-%s", prefix, distroCode, branchName, buildId), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue