Skip to content

Commit

Permalink
Merge static check and report static check tasks
Browse files Browse the repository at this point in the history
There is no reason to keep these 2 Tekton task separate. This commit
merged it into one to save OCP resources and speedup the execution time.

Signed-off-by: Ales Raszka <[email protected]>
  • Loading branch information
Allda committed Feb 13, 2025
1 parent 06c1579 commit fc52404
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -680,29 +680,6 @@ spec:
workspace: results
subPath: summary

- name: static-tests-results
taskRef:
name: report-static-tests-results
kind: Task
runAfter:
- static-tests
params:
- name: pipeline_image
value: "$(params.pipeline_image)"
- name: messages_count
value: "$(tasks.static-tests.results.messages_count)"
- name: failures_count
value: "$(tasks.static-tests.results.failures_count)"
- name: request_url
value: "$(params.git_pr_url)"
- name: github_token_secret_name
value: "$(params.github_token_secret_name)"
- name: github_token_secret_key
value: "$(params.github_token_secret_key)"
workspaces:
- name: output
workspace: results
subPath: summary

# Merge user's registry tokens with service account credentials
# used elsewhere by this pipeline.
Expand All @@ -713,7 +690,7 @@ spec:
# our credentials for that registry will be omitted.
- name: merge-registry-credentials
runAfter:
- static-tests-results
- static-tests
taskRef:
name: merge-registry-credentials
params:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ spec:
- name: affected_catalog_operators
description: All catalog operators affected with the change.

- name: github_host_url
description: |
The GitHub host, adjust this if you run a GitHub enterprise.
default: "https://api.github.com"

- name: github_token_secret_key
description: The key within the Kubernetes Secret that contains the GitHub token.
default: token
Expand Down Expand Up @@ -97,3 +102,68 @@ spec:
| tr -d '\r\n' >$(results.messages_count.path)
jq -r '[(.outputs//[])[]|select(.type=="error")]|length' <$JSON_RESULTS_FILE \
| tr -d '\r\n' >$(results.failures_count.path)
- name: build-and-post-comment
image: "$(params.pipeline_image)"
workingDir: "$(workspaces.output.path)"
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: "$(params.github_token_secret_name)"
key: "$(params.github_token_secret_key)"
script: |
#!/usr/bin/env bash
set -xe
MESSAGE_COUNT=$(cat $(results.messages_count.path))
# If there are no messages, exit
[ -z "$MESSAGE_COUNT" ] || [ "$MESSAGE_COUNT" -eq 0 ] && exit 0
JSON_RESULTS_FILE="$(workspaces.output.path)/static-test-results.json"
MESSAGE_FILE="$(workspaces.output.path)/static-test-results.md"
echo '# Static test results' >$MESSAGE_FILE
echo >>$MESSAGE_FILE
echo '|Status|Check|Message|' >>$MESSAGE_FILE
echo '|:----:|:----|:------|' >>$MESSAGE_FILE
jq -r '(.outputs//[])[]|"|\(.type)|\(.check)|\(.message|gsub("\n";" "))|"' \
<$JSON_RESULTS_FILE >>$MESSAGE_FILE
echo >>$MESSAGE_FILE
# Replace status words with corresponding symbols
sed -ie 's/^|warning|/|:warning:|/g;s/^|error|/|:x:|/g' "$MESSAGE_FILE"
echo "Posting GitHub comment to issue (or PR) $(params.pull_request_url)"
github-add-comment \
--github-host-url "$(params.github_host_url)" \
--request-url "$(params.pull_request_url)" \
--comment-file "$(workspaces.output.path)/static-test-results.md"
- name: check-for-failures
image: "$(params.pipeline_image)"
workingDir: "$(workspaces.output.path)"
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
name: "$(params.github_token_secret_name)"
key: "$(params.github_token_secret_key)"
script: |
#!/usr/bin/env bash
set -xe
FAILURE_COUNT=$(cat $(results.failures_count.path))
if [ -z "$FAILURE_COUNT" ] || [ "$FAILURE_COUNT" -eq 0 ] ; then
github-labels --pull-request-url "$(params.pull_request_url)" \
--remove-labels validation-failed
else
github-labels --pull-request-url "$(params.pull_request_url)" \
--add-labels validation-failed
echo "Static tests failed! A summary was added to the PR."
exit 1
fi

0 comments on commit fc52404

Please sign in to comment.