Skip to content

Commit

Permalink
Use TriggerGroups for CI Jobs 🥳
Browse files Browse the repository at this point in the history
TriggerGroups are a new alpha feature in Triggers that allow define
a set of interceptors that will be processed before Trigger resources
for a filtered group of Triggers.

All triggers in CI jobs deal with GitHub event so they share a large
surface of the interceptors. Using TriggerGroups makes it easier to
maintain the triggers for all projects.

The change is not only cosmetic though: interceptors like github,
cel, add-pr-body will be processed only once. The hash in the GitHub
event is going to be validated once. The PR definition will be pulled
from the GitHub API once (per trigger group) instead of once per
trigger.

This paves the way for further changes:
- add the add-team-member custom interceptor and logic so we only
  run tests for authorised users
- add a trigger group to add comments that enahnce the user experience

Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
  • Loading branch information
afrittoli committed Dec 9, 2021
1 parent 680e2c7 commit 6089518
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 309 deletions.
23 changes: 0 additions & 23 deletions tekton/ci/catalog/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,6 @@ spec:
value: $(tt.params.pullRequestBaseRef)
- name: gitRepository
value: "$(tt.params.gitRepository)"
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: tekton-catalog-diff-task-template
spec:
params:
- name: buildUUID
description: UUID used to track a CI Pipeline Run in logs
- name: pullRequestNumber
description: The pullRequestNumber
- name: pullRequestUrl
description: The HTML URL for the pull request
- name: pullRequestBaseRef
description: |
The base git ref for the pull request. This is the branch the
pull request would merge onto once approved.
- name: gitRepository
description: The git repository that hosts context and Dockerfile
- name: gitRevision
description: The Git revision to be used.
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
Expand Down Expand Up @@ -124,4 +102,3 @@ spec:
value: $(tt.params.pullRequestBaseRef)
- name: gitRepository
value: "$(tt.params.gitRepository)"
---
108 changes: 6 additions & 102 deletions tekton/ci/catalog/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: catalog-pull-request
labels:
ci.tekton.dev/trigger-type: github.pull-request
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.full_name == 'tektoncd/catalog' &&
body.action in ['opened','synchronize']
overlays:
- key: git_clone_depth
expression: "string(body.pull_request.commits + 1.0)"
body.repository.full_name == 'tektoncd/catalog'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
Expand All @@ -30,105 +22,17 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: catalog-issue-comment
labels:
ci.tekton.dev/trigger-type: github.issue-comment
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.full_name == 'tektoncd/catalog' &&
body.action == 'created' &&
'pull_request' in body.issue &&
body.issue.state == 'open' &&
body.comment.body.matches('^/test($| [^ ]*[ ]*$)')
overlays:
- key: add_pr_body.pull_request_url
expression: "body.issue.pull_request.url"
- webhook:
objectRef:
kind: Service
name: add-pr-body
apiVersion: v1
namespace: tekton-ci
- cel:
overlays:
- key: git_clone_depth
expression: "string(body.extensions.add_pr_body.pull_request_body.commits + 1.0)"
body.repository.full_name == 'tektoncd/catalog'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-comment
- ref: tekton-ci-clone-depth
- ref: tekton-ci-webhook-issue-labels
template:
ref: tekton-catalog-ci-pipeline
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: catalog-pull-request-diff-task
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.full_name == 'tektoncd/catalog' &&
body.action in ['opened','synchronize']
overlays:
- key: git_clone_depth
expression: "string(body.pull_request.commits + 1.0)"
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
- ref: tekton-ci-clone-depth
- ref: tekton-ci-webhook-pr-labels
template:
ref: tekton-catalog-diff-task-template
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: catalog-issue-comment-diff-task
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.full_name == 'tektoncd/catalog' &&
body.action == 'created' &&
'pull_request' in body.issue &&
body.issue.state == 'open' &&
body.comment.body.matches('^/diff-task')
overlays:
- key: add_pr_body.pull_request_url
expression: "body.issue.pull_request.url"
- webhook:
objectRef:
kind: Service
name: add-pr-body
apiVersion: v1
namespace: tekton-ci
- cel:
overlays:
- key: git_clone_depth
expression: "string(body.extensions.add_pr_body.pull_request_body.commits + 1.0)"
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-comment
- ref: tekton-ci-clone-depth
- ref: tekton-ci-webhook-issue-labels
template:
ref: tekton-catalog-diff-task-template
41 changes: 6 additions & 35 deletions tekton/ci/community/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: community-pull-request
labels:
ci.tekton.dev/trigger-type: github.pull-request
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.name == 'community' &&
body.action in ['opened', 'synchronize', 'labeled', 'unlabeled', 'reopened']
overlays:
- key: git_clone_depth
expression: "string(body.pull_request.commits + 1.0)"
body.repository.name == 'community'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
Expand All @@ -30,34 +22,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: community-issue-comment
labels:
ci.tekton.dev/trigger-type: github.issue-comment
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.name == 'community' &&
body.action == 'created' &&
'pull_request' in body.issue &&
body.issue.state == 'open' &&
body.comment.body.matches('^/test($| [^ ]*[ ]*$)')
overlays:
- key: add_pr_body.pull_request_url
expression: "body.issue.pull_request.url"
- webhook:
objectRef:
kind: Service
name: add-pr-body
apiVersion: v1
namespace: tekton-ci
- cel:
overlays:
- key: git_clone_depth
expression: "string(body.extensions.add_pr_body.pull_request_body.commits + 1.0)"
body.repository.name == 'community'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-comment
Expand Down
41 changes: 6 additions & 35 deletions tekton/ci/pipeline/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: pipeline-pull-request
labels:
ci.tekton.dev/trigger-type: github.pull-request
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.name == 'pipeline' &&
body.action in ['opened', 'synchronize', 'labeled', 'unlabeled', 'reopened']
overlays:
- key: git_clone_depth
expression: "string(body.pull_request.commits + 1.0)"
body.repository.name == 'pipeline'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
Expand All @@ -30,34 +22,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: pipeline-issue-comment
labels:
ci.tekton.dev/trigger-type: github.issue-comment
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.name == 'pipeline' &&
body.action == 'created' &&
'pull_request' in body.issue &&
body.issue.state == 'open' &&
body.comment.body.matches('^/test($| [^ ]*[ ]*$)')
overlays:
- key: add_pr_body.pull_request_url
expression: "body.issue.pull_request.url"
- webhook:
objectRef:
kind: Service
name: add-pr-body
apiVersion: v1
namespace: tektonci
- cel:
overlays:
- key: git_clone_depth
expression: "string(body.extensions.add_pr_body.pull_request_body.commits + 1.0)"
body.repository.name == 'pipeline'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-comment
Expand Down
41 changes: 6 additions & 35 deletions tekton/ci/plumbing/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: plumbing-pull-request
labels:
ci.tekton.dev/trigger-type: github.pull-request
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.name == 'plumbing' &&
body.action in ['opened', 'synchronize', 'labeled', 'unlabeled', 'reopened']
overlays:
- key: git_clone_depth
expression: "string(body.pull_request.commits + 1.0)"
body.repository.name == 'plumbing'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
Expand All @@ -30,34 +22,13 @@ apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: plumbing-issue-comment
labels:
ci.tekton.dev/trigger-type: github.issue-comment
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.name == 'plumbing' &&
body.action == 'created' &&
'pull_request' in body.issue &&
body.issue.state == 'open' &&
body.comment.body.matches('^/test($| [^ ]*[ ]*$)')
overlays:
- key: add_pr_body.pull_request_url
expression: "body.issue.pull_request.url"
- webhook:
objectRef:
kind: Service
name: add-pr-body
apiVersion: v1
namespace: tektonci
- cel:
overlays:
- key: git_clone_depth
expression: "string(body.extensions.add_pr_body.pull_request_body.commits + 1.0)"
body.repository.name == 'plumbing'
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-comment
Expand Down
Loading

0 comments on commit 6089518

Please sign in to comment.