Skip to content

Commit

Permalink
check-task-pipeline-bundle-repos.sh check for PRs
Browse files Browse the repository at this point in the history
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.

The URL being checked for existence now checks against the Docker
registry API, the quay.io REST API has no endpoint to check for
existence of tags. Also the non-pull request artifacts are checked for
their correct tag/version now.
  • Loading branch information
zregvart committed Jan 30, 2023
1 parent 3972fff commit a3b8b66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .tekton/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,20 @@ 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:
params:
- name: pr_commit
type: string
steps:
- name: fail-when-repo-is-missed
image: registry.redhat.io/openshift4/ose-cli:v4.11
workingDir: $(workspaces.source.path)
script: |
#!/usr/bin/env bash
.tekton/scripts/check-task-pipeline-bundle-repos.sh
PULL_REQUEST=1 .tekton/scripts/check-task-pipeline-bundle-repos.sh
workspaces:
- name: source
workspaces:
Expand Down
26 changes: 20 additions & 6 deletions .tekton/scripts/check-task-pipeline-bundle-repos.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#!/usr/bin/bash -e
#!/usr/bin/bash

set -o errexit
set -o pipefail
set -o nounset

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
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 -r version="${3}"

if [ "${PULL_REQUEST:-0}" -ne 1 ]; then
curl -I -s -L -w "%{http_code}\n" -o /dev/null "https://quay.io/v2/${QUAY_ORG}/${type}-${object}/manifests/${version}"
else
curl -I -s -L -w "%{http_code}\n" -o /dev/null "https://quay.io/v2/${QUAY_ORG}/pull-request-builds/manifests/${object}-${version}"
fi
}

has_missing_repo=
Expand All @@ -17,18 +28,21 @@ 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")
dir=${task_file%/*}
version="${dir##*/}-$(git log -n 1 --pretty=format:%H -- "${task_file}")"
found=$(locate_bundle_repo task "$task_name" "${version}")
if [ "$found" != "200" ]; then
echo "Missing task bundle repo: task-$task_name"
has_missing_repo=yes
fi
done

# pipelines
version="$(git rev-parse HEAD)"
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" "${version}")
if [ "$found" != "200" ]; then
echo "Missing pipeline bundle repo: pipeline-$pl_name"
echo "Missing pipeline bundle repo: pipeline-$pl_name ${version}"
has_missing_repo=yes
fi
done
Expand Down

0 comments on commit a3b8b66

Please sign in to comment.