-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Pipeline As Code Tekton (#174)
* parse pipeline as code tekton * untrusted checkout pipeline as code tekton * added injection detection for script steps
- Loading branch information
1 parent
b7c3cae
commit b8181bf
Showing
8 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package models | ||
|
||
import "gopkg.in/yaml.v3" | ||
|
||
type PipelineAsCodeTekton struct { | ||
ApiVersion string `json:"api_version" yaml:"apiVersion"` | ||
Kind string `json:"kind"` | ||
Metadata struct { | ||
Name string `json:"name"` | ||
Annotations map[string]string `json:"annotations"` | ||
} `json:"metadata"` | ||
Spec PipelineRunSpec `json:"spec,omitempty" yaml:"spec"` | ||
|
||
Path string `json:"path" yaml:"-"` | ||
} | ||
|
||
type PipelineRunSpec struct { | ||
PipelineSpec *PipelineSpec `json:"pipeline_spec,omitempty" yaml:"pipelineSpec"` | ||
} | ||
|
||
type PipelineSpec struct { | ||
Tasks []PipelineTask `json:"tasks,omitempty" yaml:"tasks"` | ||
} | ||
|
||
type PipelineTask struct { | ||
Name string `json:"name,omitempty"` | ||
|
||
TaskSpec *TaskSpec `json:"task_spec,omitempty" yaml:"taskSpec"` | ||
} | ||
|
||
type TaskSpec struct { | ||
Steps []Step `json:"steps,omitempty"` | ||
} | ||
|
||
type Step struct { | ||
Name string `json:"name"` | ||
Script string `json:"script,omitempty"` | ||
Lines map[string]int `json:"lines" yaml:"-"` | ||
} | ||
|
||
func (o *Step) UnmarshalYAML(node *yaml.Node) error { | ||
type step Step | ||
var s step | ||
if err := node.Decode(&s); err != nil { | ||
return err | ||
} | ||
|
||
if node.Kind == yaml.MappingNode { | ||
s.Lines = map[string]int{"start": node.Line} | ||
for i := 0; i < len(node.Content); i += 2 { | ||
key := node.Content[i].Value | ||
switch key { | ||
case "script": | ||
s.Lines[key] = node.Content[i+1].Line | ||
} | ||
} | ||
} | ||
|
||
*o = Step(s) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: linters | ||
annotations: | ||
pipelinesascode.tekton.dev/on-event: "[push, pull_request]" | ||
pipelinesascode.tekton.dev/on-target-branch: "[*]" | ||
pipelinesascode.tekton.dev/task: "[git-clone]" | ||
spec: | ||
params: | ||
- name: repo_url | ||
value: "{{repo_url}}" | ||
- name: revision | ||
value: "{{revision}}" | ||
pipelineSpec: | ||
params: | ||
- name: repo_url | ||
- name: revision | ||
tasks: | ||
- name: fetchit | ||
displayName: "Fetch git repository" | ||
params: | ||
- name: url | ||
value: $(params.repo_url) | ||
- name: revision | ||
value: $(params.revision) | ||
taskRef: | ||
name: git-clone | ||
workspaces: | ||
- name: output | ||
workspace: source | ||
- name: vale | ||
displayName: "Spelling and Grammar" | ||
runAfter: | ||
- fetchit | ||
taskSpec: | ||
workspaces: | ||
- name: source | ||
steps: | ||
- name: vale-lint | ||
image: jdkato/vale | ||
workingDir: $(workspaces.source.path) | ||
script: | | ||
vale docs/content --minAlertLevel=error --output=line | ||
- name: injection | ||
image: jdkato/vale | ||
workingDir: $(workspaces.source.path) | ||
script: | | ||
binary {{body.pull_request.body}} | ||
workspaces: | ||
- name: source | ||
workspace: source | ||
workspaces: | ||
- name: source | ||
workspaces: | ||
- name: source | ||
volumeClaimTemplate: | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 5Gi |