-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The label check is on the legacy ci folder still. Move it across to the ci-workspace folder. Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
- Loading branch information
1 parent
688bbb0
commit f88b65f
Showing
9 changed files
with
222 additions
and
268 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,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) |
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
Oops, something went wrong.