Skip to content

Commit

Permalink
Add gitRef fields
Browse files Browse the repository at this point in the history
Depends on tektoncd#806 for annotation based remote resolution to work
  • Loading branch information
dibyom committed Sep 29, 2022
1 parent c40f888 commit a97e7eb
Show file tree
Hide file tree
Showing 38 changed files with 2,377 additions and 94 deletions.
Empty file added workflows/minimal.yaml
Empty file.
50 changes: 45 additions & 5 deletions workflows/pkg/apis/workflows/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
*
Copyright 2021 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -92,6 +92,14 @@ type WorkflowList struct {
// TODO: Add validation
type PipelineRef struct {
Spec pipelinev1beta1.PipelineSpec `json:"spec,omitempty"`
Git PipelineRefGit `json:"git,omitempty"`
}

type PipelineRefGit struct {
Repo string `json:"repo"`
Commit string `json:"commit"`
Path string `json:"path"`
Pipeline string `json:"pipeline"`
}

// WorkflowWorkspaceBinding maps a Pipeline's declared Workspaces
Expand Down Expand Up @@ -129,12 +137,17 @@ type Event struct {
}

type Repo struct {
Name string `json:"name"`
// Only public GitHub URLs for now
URL string `json:"url,omitempty"`
DefaultBranch string `json:"defaultBranch"`
}

func makeWorkspaces(bindings []WorkflowWorkspaceBinding, secrets []Secret) []pipelinev1beta1.WorkspaceBinding {
if bindings == nil && len(bindings) == 0 {
return []pipelinev1beta1.WorkspaceBinding{}
}

res := []pipelinev1beta1.WorkspaceBinding{}
secretReplacements := map[string]string{}
for _, s := range secrets {
Expand Down Expand Up @@ -179,25 +192,44 @@ func (w *Workflow) ToPipelineRun() (*pipelinev1beta1.PipelineRun, error) {
})
}

return &pipelinev1beta1.PipelineRun{
pr := pipelinev1beta1.PipelineRun{
TypeMeta: metav1.TypeMeta{
Kind: "PipelineRun",
APIVersion: pipelinev1beta1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-run-", w.Name),
Namespace: w.Namespace, // TODO: Do Runs generate from a Workflow always run in the same namespace

// TODO: Propagate labels/annotations from Workflows as well?
},
Spec: pipelinev1beta1.PipelineRunSpec{
PipelineSpec: &w.Spec.Pipeline.Spec, // TODO: Apply transforms
Params: params,
ServiceAccountName: saName,
Timeouts: &w.Spec.Timeout,
Workspaces: makeWorkspaces(w.Spec.Workspaces, w.Spec.Secrets), // TODO: Add workspaces
},
}, nil
}

if w.Spec.Pipeline.Git.Repo != "" {
repo := ""
for _, r := range w.Spec.Repos {
if r.Name == w.Spec.Pipeline.Git.Repo {
repo = r.URL
}
}
pr.ObjectMeta.Annotations = map[string]string{
"resolution.tekton.dev/resolver": "git",
"git.repo": repo,
"git.commit": w.Spec.Pipeline.Git.Commit,
"git.path": w.Spec.Pipeline.Git.Path,
}
pr.Spec.PipelineRef = &pipelinev1beta1.PipelineRef{Name: w.Spec.Pipeline.Git.Pipeline}
pr.Spec.Status = pipelinev1beta1.PipelineRunSpecStatusPending
} else {
pr.Spec.PipelineSpec = &w.Spec.Pipeline.Spec
}

return &pr, nil
}

func (w *Workflow) ToTriggerTemplate() (*triggersv1beta1.TriggerTemplate, error) {
Expand Down Expand Up @@ -226,6 +258,14 @@ func (w *Workflow) ToTriggerTemplate() (*triggersv1beta1.TriggerTemplate, error)
}
}

// HACK
if pr.Annotations != nil {
if _, ok := pr.Annotations["git.commit"]; ok {
paramName := "commit-sha" // TODO: Extract commit-sha/param name
pr.Annotations["git.commit"] = fmt.Sprintf("$(tt.params.%s)", paramName)
}
}

// TODO: Once we add trigger-bindings, we need to match on binding param names
// and replace the values with the ones from binding
prJson, err := json.Marshal(pr)
Expand Down
108 changes: 106 additions & 2 deletions workflows/pkg/apis/workflows/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a97e7eb

Please sign in to comment.