chore: easier version stream values
make it easy for libraries to add aliases for `@versionStream` in task `uses:gitURL` strings
@@ -2,6 +2,7 @@ package inrepo
import (
"fmt"
+ "github.com/jenkins-x/go-scm/scm"
"io/ioutil"
"net/url"
"os"
@@ -30,6 +31,12 @@ type UsesResolver struct {
cache map[string]*tektonv1beta1.PipelineRun
}
+var (
+ // VersionStreamVersions allows you to register version stream values of ful repository names in the format
+ // `owner/name` mapping to the version SHA/branch/tag
+ VersionStreamVersions = map[string]string{}
+)
+
// UsesSteps lets resolve the sourceURI to a PipelineRun and find the step or steps
// for the given task name and/or step name then lets apply any overrides from the step
func (r *UsesResolver) UsesSteps(sourceURI string, taskName string, step tektonv1beta1.Step) ([]tektonv1beta1.Step, error) {
@@ -117,11 +124,12 @@ func resolveCustomSha(owner string, repo string, sha string) string {
if sha != "versionStream" {
return sha
}
- envVar := strings.ToUpper(fmt.Sprintf("LIGHTHOUSE_VERSIONSTREAM_%s_%s", owner, repo))
- envVar = strings.ReplaceAll(envVar, "-", "_")
- envVar = strings.ReplaceAll(envVar, " ", "_")
- envVar = strings.ReplaceAll(envVar, ".", "_")
- value := os.Getenv(envVar)
+ fullName := scm.Join(owner, repo)
+ value := VersionStreamVersions[fullName]
+ envVar := VersionStreamEnvVar(owner, repo)
+ if value == "" {
+ value = os.Getenv(envVar)
+ }
if value != "" {
return value
}
@@ -132,6 +140,15 @@ func resolveCustomSha(owner string, repo string, sha string) string {
return "HEAD"
}
+// VersionStreamEnvVar creates an environment variable name
+func VersionStreamEnvVar(owner string, repo string) string {
+ envVar := strings.ToUpper(fmt.Sprintf("LIGHTHOUSE_VERSIONSTREAM_%s_%s", owner, repo))
+ envVar = strings.ReplaceAll(envVar, "-", "_")
+ envVar = strings.ReplaceAll(envVar, " ", "_")
+ envVar = strings.ReplaceAll(envVar, ".", "_")
+ return envVar
+}
+
func (r *UsesResolver) findSteps(sourceURI string, pr *tektonv1beta1.PipelineRun, taskName string, step tektonv1beta1.Step) ([]tektonv1beta1.Step, error) {
if pr.Spec.PipelineSpec == nil {
return nil, errors.Errorf("source URI %s has no spec.pipelineSpec", sourceURI)
