Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate label check to ci-workspace #948

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tekton/ci-workspace/jobs/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ resources:
- tekton-org-validation.yaml
- tekton-python-unit-tests.yaml
- tekton-catalog-diff-task.yaml
- e2e-kind.yaml
- e2e-kind.yaml
- tekton-kind-label.yaml
98 changes: 98 additions & 0 deletions tekton/ci-workspace/jobs/tekton-kind-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kind-label
namespace: tektonci
description: |
Verifies that a PR has one valid kind label
spec:
params:
- name: labels
description: The labels attached to the Pull Request
volumes:
- name: label-config-v2
configMap:
name: label-config-v2
stepTemplate:
env:
- name: HOME
value: /tekton/home
steps:
- name: install-pyyaml
image: python:3-alpine
script: |
pip install pyyaml --user
- name: check-labels
image: python:3-alpine
volumeMounts:
- name: label-config-v2
mountPath: /etc/config
script: |
#!/usr/bin/env python

import json
import yaml
import sys

prLabelsText = """$(params.labels)"""
prLabels = json.loads(prLabelsText)

availableLabels = None
with open("/etc/config/labels.yaml", "r") as stream:
availableLabels = yaml.safe_load(stream)["default"]["labels"]

availableKindLabels = {x.get("name"):x.get("description") for x in availableLabels if x.get("name").startswith("kind/")}
foundKindLabels = set([x.get("name") for x in prLabels if x.get("name").startswith("kind/") and x.get("name")])
validKindLabels = set([x for x in foundKindLabels if x in availableKindLabels])

# Check that we have one and only one kind label
foundLabels = len(validKindLabels)
if (foundLabels > 1 or foundLabels == 0):
msg = "Error: {} valid \"kind/*\" labels found".format(foundLabels)
if foundLabels > 1:
msg += "({})".format(validKindLabels)
msg += ", expecting exactly one."
invalidKindLabels = foundKindLabels - validKindLabels
if len(invalidKindLabels) > 0:
msg += " Invalid labels found: {}".format(invalidKindLabels)
print(msg)
print("\nAvailable \"kind/*\" labels are:")
for label, description in availableKindLabels.items():
print("\t{}: {}".format(label, description))

# Check failed. Return exit code 1.
sys.exit(1)
else:
print("Exactly one \"kind/*\" label found: {}".format(validKindLabels))
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: tekton-kind-label
spec:
params:
- name: checkName
description: The name of the GitHub check that this pipeline is used for
- name: gitHubCommand
description: The command that was used to trigger testing
- name: labels
description: The labels attached to the Pull Request
tasks:
- name: check-name-matches
taskRef:
name: check-name-matches
params:
- name: gitHubCommand
value: $(params.gitHubCommand)
- name: checkName
value: $(params.checkName)
- name: kind-label
when: # implicit dependency on the check tasks
- input: $(tasks.check-name-matches.results.check)
operator: in
values: ["passed"]
taskRef:
name: "kind-label"
params:
- name: labels
value: $(params.labels)
56 changes: 55 additions & 1 deletion tekton/ci-workspace/shared/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,58 @@ spec:
# Start with docs, ends with .md or *.rst, but not in vendor/ or thirdparty/
value: "(^docs\\/.*|^(?!vendor\\/)(?!thirdparty\\/).*\\.(md|rst)$)"
- name: package
value: $(tt.params.package)
value: $(tt.params.package)
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: label-check
annotations:
triggers.tekton.dev/old-escape-quotes: "true"
spec:
params:
- name: buildUUID
description: UUID used to track a CI Pipeline Run in logs
- name: package
description: org/repo
- name: pullRequestNumber
description: The pullRequestNumber
- name: pullRequestUrl
description: The HTML URL for the pull request
- name: gitRepository
description: The git repository that hosts context and Dockerfile
- name: gitRevision
description: The Git revision to be used.
- name: gitCloneDepth
description: Number of commits in the change + 1
- name: gitHubCommand
description: |
The GitHub command that was used a trigger. This is only available when
this template is triggered by a comment. The default value is for the
case of a pull_request event.
default: ""
- name: labels
description: List of labels currently on the Pull Request
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: check-pr-labels-
labels:
prow.k8s.io/build-id: $(tt.params.buildUUID)
tekton.dev/check-name: check-pr-has-kind-label
tekton.dev/kind: ci
tekton.dev/pr-number: $(tt.params.pullRequestNumber)
annotations:
tekton.dev/gitRevision: "$(tt.params.gitRevision)"
tekton.dev/gitURL: "$(tt.params.gitRepository)"
spec:
pipelineRef:
name: tekton-kind-label
params:
- name: labels
value: $(tt.params.labels)
- name: checkName
value: check-pr-has-kind-label
- name: gitHubCommand
value: $(tt.params.gitHubCommand)
67 changes: 66 additions & 1 deletion tekton/ci-workspace/shared/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,69 @@ spec:
- ref: tekton-ci-webhook-pr-labels
- ref: tekton-ci-clone-depth
template:
ref: tekton-doc-reviews
ref: tekton-doc-reviews
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: pull-request-label-check
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.full_name.startsWith('tektoncd/') &&
body.repository.name in ['plumbing', 'pipeline', 'triggers', 'cli', 'dashboard', 'hub'] &&
body.action in ['opened', 'synchronize', 'labeled', 'unlabeled']
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
- ref: tekton-ci-webhook-pr-labels
template:
ref: label-check
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: comment-label-check
spec:
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.full_name.startsWith('tektoncd/') &&
body.repository.name in ['plumbing', 'pipeline', 'triggers', 'cli', 'dashboard', 'hub'] &&
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)"
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-comment
- ref: tekton-ci-clone-depth
- ref: tekton-ci-webhook-issue-labels
template:
ref: label-check
117 changes: 1 addition & 116 deletions tekton/ci/eventlistener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,64 +64,6 @@ spec:
- ref: tekton-ci-webhook-issue-labels
template:
ref: tekton-plumbing-ci-pipeline
- name: all-comment-ci
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.full_name.startsWith('tektoncd/') &&
body.repository.name in ['plumbing', 'pipeline', 'triggers', 'cli', 'dashboard', 'hub'] &&
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)"
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-all-ci-pipeline
- name: all-pull-request-ci
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.full_name.startsWith('tektoncd/') &&
body.repository.name in ['plumbing', 'pipeline', 'triggers', 'cli', 'dashboard', 'hub'] &&
(body.action == 'opened' ||
body.action == 'synchronize' ||
body.action == 'labeled' ||
body.action == 'unlabeled')
bindings:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-pull-request
- ref: tekton-ci-webhook-pr-labels
template:
ref: tekton-all-ci-pipeline
- name: cd-trigger
interceptors:
- github:
Expand Down Expand Up @@ -155,61 +97,4 @@ spec:
- ref: tekton-ci-github-base
- ref: tekton-ci-webhook-tektoncd-comment
template:
ref: tekton-cd-triggers
- name: website-pull-request-ci
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- pull_request
- cel:
filter: >-
body.repository.full_name == 'tektoncd/website' &&
(body.action == 'opened' || body.action == '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-website-ci-pipeline
- name: website-comment-ci
interceptors:
- github:
secretRef:
secretName: ci-webhook
secretKey: secret
eventTypes:
- issue_comment
- cel:
filter: >-
body.repository.full_name == 'tektoncd/website' &&
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)"
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-website-ci-pipeline
ref: tekton-cd-triggers
Loading