From dd49758ade291e2f63b759ba1c2d323f8fe7b079 Mon Sep 17 00:00:00 2001 From: Zoran Regvart Date: Fri, 27 Jan 2023 13:20:10 +0100 Subject: [PATCH] check-task-pipeline-bundle-repos.sh check for PRs Passes the pull request commit id to the `check-task-pipeline-repo-existence` step to make the validation consider pull request image references; otherwise the check checks for images that are have resulted from changes pushed to the default branch. --- .tekton/pull-request.yaml | 5 ++++- .../scripts/check-task-pipeline-bundle-repos.sh | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.tekton/pull-request.yaml b/.tekton/pull-request.yaml index 1f4e4f9dec..61e72c903f 100644 --- a/.tekton/pull-request.yaml +++ b/.tekton/pull-request.yaml @@ -151,6 +151,9 @@ spec: oc delete --ignore-not-found deployment --all -n $(params.e2e_test_namespace) oc delete --ignore-not-found eventlisteners --all -n $(params.e2e_test_namespace) - name: check-task-pipeline-repo-existence + params: + - name: pr_commit + value: "$(tasks.fetch-repository.results.commit)" taskSpec: steps: - name: fail-when-repo-is-missed @@ -158,7 +161,7 @@ spec: workingDir: $(workspaces.source.path) script: | #!/usr/bin/env bash - .tekton/scripts/check-task-pipeline-bundle-repos.sh + PULL_REQUEST_COMMIT="$(params.pr_commit)" .tekton/scripts/check-task-pipeline-bundle-repos.sh workspaces: - name: source workspaces: diff --git a/.tekton/scripts/check-task-pipeline-bundle-repos.sh b/.tekton/scripts/check-task-pipeline-bundle-repos.sh index a35d176758..66c97c52f1 100755 --- a/.tekton/scripts/check-task-pipeline-bundle-repos.sh +++ b/.tekton/scripts/check-task-pipeline-bundle-repos.sh @@ -6,8 +6,16 @@ cd "$SCRIPTDIR/../.." QUAY_ORG=redhat-appstudio-tekton-catalog locate_bundle_repo() { - local -r repo_name=$1 - curl -I -s -L -w "%{http_code}\n" -o /dev/null "https://quay.io/api/v1/repository/${QUAY_ORG}/${repo_name}" + local -r type="$1" + local -r object="$2" + + local repo_and_tag + if [ -z ${PULL_REQUEST_COMMIT+x} ]; then + repo_and_tag="${type}-${object}" + else + repo_and_tag="pull-request-builds:${object}-${PULL_REQUEST_COMMIT}" + fi + curl -I -s -L -w "%{http_code}\n" -o /dev/null "https://quay.io/api/v1/repository/${QUAY_ORG}/${repo_and_tag}" } has_missing_repo= @@ -17,7 +25,7 @@ echo "Checking existence of task and pipeline bundle repositories ..." # tasks for task_file in task/*/*/*.yaml; do task_name=$(oc apply --dry-run=client -f "$task_file" -o jsonpath='{.metadata.name}') - found=$(locate_bundle_repo "task-$task_name") + found=$(locate_bundle_repo task "$task_name") if [ "$found" != "200" ]; then echo "Missing task bundle repo: task-$task_name" has_missing_repo=yes @@ -26,7 +34,7 @@ done # pipelines for pl_name in $(oc kustomize pipelines/ | oc apply --dry-run=client -f - -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'); do - found=$(locate_bundle_repo "pipeline-$pl_name") + found=$(locate_bundle_repo pipeline "$pl_name") if [ "$found" != "200" ]; then echo "Missing pipeline bundle repo: pipeline-$pl_name" has_missing_repo=yes