Skip to content

Commit

Permalink
CI check for missing TA Task variants
Browse files Browse the repository at this point in the history
A script and a GitHub workflow change to check if a new Task was added
that uses a PVC-backed workspace without a Trusted Artifacts Task
variant.

Reference: https://issues.redhat.com/browse/EC-934
  • Loading branch information
zregvart committed Oct 21, 2024
1 parent 3234271 commit c8bc225
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/check-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- name: Check Trusted Artifact variants
id: check
run: hack/generate-ta-tasks.sh
- name: Check missing Trusted Artifact variants
id: missing
run: hack/missing-ta-tasks.sh
- name: Attach patch
if: ${{ always() && steps.check.conclusion == 'failure' }}
uses: actions/upload-artifact@v4
Expand Down
106 changes: 106 additions & 0 deletions hack/missing-ta-tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail
shopt -s globstar

git_root=$(git rev-parse --show-toplevel)

tmp_files=()
trap 'rm "${tmp_files[@]}" > /dev/null 2>&1' EXIT

# names of workspaces that will not be mounted via PVC, as inline array
non_pvc_workspaces='["ssh-directory", "basic-auth", "gitops-auth", "git-basic-auth", "netrc"]'

# Tasks that are currently missing Trusted Artifact variant
todo=(
task/buildah-10gb/0.2/kustomization.yaml
task/buildah-20gb/0.2/kustomization.yaml
task/buildah-24gb/0.2/kustomization.yaml
task/buildah-6gb/0.2/kustomization.yaml
task/buildah-8gb/0.2/kustomization.yaml
task/buildah-min/0.2/kustomization.yaml
task/buildah-rhtap/0.1/buildah-rhtap.yaml
task/download-sbom-from-url-in-attestation/0.1/download-sbom-from-url-in-attestation.yaml
task/fbc-related-image-check/0.1/fbc-related-image-check.yaml
task/fbc-validation/0.1/fbc-validation.yaml
task/gather-deploy-images/0.1/gather-deploy-images.yaml
task/generate-odcs-compose/0.2/generate-odcs-compose.yaml
task/generate-odcs-compose/0.2/kustomization.yaml
task/inspect-image/0.1/inspect-image.yaml
task/operator-sdk-generate-bundle/0.1/operator-sdk-generate-bundle.yaml
task/opm-get-bundle-version/0.1/opm-get-bundle-version.yaml
task/opm-render-bundles/0.1/opm-render-bundles.yaml
task/sast-unicode-check/0.1/sast-unicode-check.yaml
task/tkn-bundle/0.1/tkn-bundle.yaml
task/upload-sbom-to-trustification/0.1/upload-sbom-to-trustification.yaml
)

emit() {
if [ "${GITHUB_ACTIONS:-false}" == "true" ]; then
printf "::error file=%s,line=1,col=0::%s\n" "$1" "$2"
else
printf "INFO: \033[1m%s\033[0m %s\n" "$1" "$2"
fi
}

{
cd "${git_root}"
missing=0
for task in task/**/*.yaml; do
task_file="${task}"
case "${task}" in
*/kustomization.yaml)
tmp=$(mktemp)
tmp_files+=("${tmp}")
kustomize build "${task%/kustomization.yaml}" > "${tmp}"
task_file="${tmp}"
;;
*/recipe.yaml | */patch.yaml)
continue
;;
esac

for t in "${todo[@]}"; do
[[ "${t}" == "${task}" ]] && continue 2
done

# we are looking at a Task
yq -e '.kind != "Task"' "${task_file}" > /dev/null 2>&1 && continue

# path elements of the task file path
readarray -d / paths <<< "${task}"
# PVC non-optional workspaces used
readarray -t workspaces <<< "$(yq '[.spec.workspaces[] | select(.optional != true) | .name] - '"${non_pvc_workspaces}"' | .[] | {"x": .} | "\(.x)"' "${task_file}")"

# is the task using a workspace(s) to share files?
[[ "${#workspaces}" -eq 0 ]] && continue

# is there a newer version of the task
base_task_path=("${paths[@]}")
unset 'base_task_path[-1]'
version="${base_task_path[-1]/\/}"
unset 'base_task_path[-1]'
for dir in $(IFS=''; echo "${base_task_path[*]}*"); do
[[ ! -d "${dir}" ]] && continue
[[ "${version}" < "${dir/*\/}" ]] && continue 2
done

# there is no Trusted Artifacts variant of the task
unset 'paths[-1]'
paths[-2]="${paths[-2]%/}-oci-ta/"
ta_dir="$(IFS=''; echo "${paths[*]}")"
if [[ ! -d "${ta_dir}" ]]; then
emit "${task}" "Task is using a workspace(s): ${workspaces[*]}, to share data and needs a corresponding Trusted Artifacts Task variant in ${ta_dir}"
missing=$((missing + 1))
fi
done

if [[ ${missing} -gt 0 ]]; then
if [ "${GITHUB_ACTIONS:-false}" == "true" ]; then
echo '::notice title=Missing Trusted Artifact Task Variant::Found Tasks that share data via PersistantVolumeClaim volumes without a corresponding Trusted Artifacts Variant. Please create the Trusted Artifacts Variant of the Task as well'
exit 1
fi
fi
}

0 comments on commit c8bc225

Please sign in to comment.