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

Catlin: Report logs back to the PR after execution #758

Merged
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
42 changes: 41 additions & 1 deletion tekton/ci/jobs/tekton-catlin-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,33 @@ spec:
image: gcr.io/tekton-releases/dogfooding/catlin:latest
workingDir: $(resources.inputs.source.path)
script: |
set +e
vinamra28 marked this conversation as resolved.
Show resolved Hide resolved
[[ ! -s $(workspaces.store-changed-files.path)/changed-files.txt ]] && {
echo "No file change detected in task directory"
echo -n "" > $(workspaces.store-changed-files.path)/catlin.txt
exit 0
}
catlin validate $(cat $(workspaces.store-changed-files.path)/changed-files.txt)

# creating a file which will contain the final formatted output
# which needs to be added as a comment(if any)
echo '**Catlin Output**' >> $(workspaces.store-changed-files.path)/catlin.txt
echo '```' >> $(workspaces.store-changed-files.path)/catlin.txt

# performing catlin validate
catlin validate $(cat $(workspaces.store-changed-files.path)/changed-files.txt) | tee -a $(workspaces.store-changed-files.path)/catlin.txt
echo '```' >> $(workspaces.store-changed-files.path)/catlin.txt

# checking if there are any ERROR or WARN messages produced by catlin
isWarning=$(cat $(workspaces.store-changed-files.path)/catlin.txt | grep -c "WARN")
isError=$(cat $(workspaces.store-changed-files.path)/catlin.txt | grep -c "ERROR")

# if there are no ERROR or WARN messages then add a empty string which will not
# add a comment on the Github PR
[[ $isWarning -eq 0 ]] && [[ $isError -eq 0 ]] && \
echo -n "" > $(workspaces.store-changed-files.path)/catlin.txt

# if catlin produced the error then fail the task else success
[[ $isError -eq 1 ]] && exit 1 || exit 0
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
Expand All @@ -65,6 +87,8 @@ spec:
description: The command that was used to trigger testing
- name: checkName
description: The name of the GitHub check that this pipeline is used for
- name: pullRequestUrl
description: The HTML URL for the pull request
tasks:
- name: lint-catalog
conditions:
Expand All @@ -86,3 +110,19 @@ spec:
params:
- name: gitCloneDepth
value: $(params.gitCloneDepth)
finally:
- name: post-comment
taskRef:
name: github-add-comment
params:
- name: COMMENT_OR_FILE
value: "catlin.txt"
- name: GITHUB_TOKEN_SECRET_NAME
value: bot-token-github
- name: GITHUB_TOKEN_SECRET_KEY
value: bot-token
Comment on lines +120 to +123
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a secret setup which contains the base64 personal access token? If yes, then please help me with the correct values that I can substitute over here 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values you have in there are already ok

- name: REQUEST_URL
value: $(params.pullRequestUrl)
workspaces:
- name: comment-file
workspace: store-changed-files
10 changes: 9 additions & 1 deletion tekton/ci/templates/catalog-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,22 @@ spec:
name: catlin-linter
workspaces:
- name: store-changed-files
emptyDir: {}
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Mi
params:
- name: gitCloneDepth
value: $(tt.params.gitCloneDepth)
- name: gitHubCommand
value: $(tt.params.gitHubCommand)
- name: checkName
value: pull-catalog-catlin-lint
- name: pullRequestUrl
value: $(tt.params.pullRequestUrl)
resources:
- name: source
resourceSpec:
Expand Down