-
Notifications
You must be signed in to change notification settings - Fork 93
Add parent dependency check on samples #397
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
Merged
michael-valdron
merged 24 commits into
devfile:main
from
michael-valdron:testing/check-parents
May 28, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
aced28b
ignore cached remote samples
michael-valdron da8dfc7
nightly script for building sample parent stack list
michael-valdron cecd9ca
init check parent stacks script
michael-valdron b19f793
convert nightly parents build to on the fly parents build.
michael-valdron 804853f
multi version support for build parent stacks
michael-valdron c99a656
ignore any local parents file.
michael-valdron 1d3f552
rename check_parent_stacks.sh to build_parents_file.sh, build_parents…
michael-valdron a3092cb
validate devfile schemas test suite parameters now changeable
michael-valdron 50dfb62
validate samples workflow
michael-valdron 6e8a981
add check for if there are samples to be checked under validate sampl…
michael-valdron b1a6ec7
add README instruction on dependency check changes
michael-valdron 19004ef
yq 4.x installation guide link added to testing prerequisites list.
michael-valdron 4a227ca
add missing link to test suite
michael-valdron 46193a0
validate_devfile_schemas script accepts relative or absolute paths
michael-valdron f45e89d
use registry-support cache samples
michael-valdron 959bbce
use yq v4.44.1
michael-valdron 3b38651
validate-samples actions match revision from other workflows
michael-valdron 6ef053d
create verbose mode for build_parents_file.sh script, defaults to false
michael-valdron a4ac51c
validate_devfile_schemas.sh script unzips resource files if samples
michael-valdron a99d261
update README
michael-valdron 06ee1f7
correct plural meaning to singular meaning for operation names
michael-valdron fd0b438
add verbose mode to validate_devfile_schemas script
michael-valdron f09095c
set default sample cache dir to .cache/samples
michael-valdron 8e5576e
remove unused minikube env vars
michael-valdron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# | ||
# Copyright 2023 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
name: Validate child samples | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
schedule: | ||
- cron: 0 5 * * * | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
YQ_VERSION: "v4.44.1" | ||
TEST_DELTA: false | ||
|
||
jobs: | ||
validate-devfile-schema: | ||
name: validate devfile schemas | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 | ||
with: | ||
go-version: "1.19" | ||
|
||
- name: Install Ginkgo | ||
run: go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo@v2.13.0 | ||
|
||
- name: Install yq | ||
run: curl -sL -O https://github.com/mikefarah/yq/releases/download/${{ env.YQ_VERSION }}/yq_linux_amd64 -o /usr/local/bin/yq && mv ./yq_linux_amd64 /usr/local/bin/yq && chmod +x /usr/local/bin/yq | ||
|
||
- name: Test delta if on a pull request | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: echo "TEST_DELTA=true" >> $GITHUB_ENV | ||
|
||
- name: Build parents file and get child samples | ||
run: echo "STACKS=$(bash tests/build_parents_file.sh)" >> $GITHUB_ENV | ||
|
||
- name: Validate samples | ||
if: ${{ env.STACKS != '' }} | ||
run: STACKS_DIR=$(pwd)/samples/.cache bash tests/validate_devfile_schemas.sh --samples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ registry-support/ | |
.idea/ | ||
devfile-web/ | ||
vendor/ | ||
.odo | ||
.odo | ||
.cache | ||
parents.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
#!/bin/bash | ||
|
||
POSITIONAL_ARGS=() | ||
VERBOSE="false" | ||
|
||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-v|--verbose) | ||
VERBOSE="true" | ||
shift # past argument | ||
;; | ||
-*|--*) | ||
echo "Unknown option $1" | ||
exit 1 | ||
;; | ||
*) | ||
POSITIONAL_ARGS+=("$1") # save positional arg | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
|
||
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters | ||
|
||
# default samples file path | ||
samples_file=$(pwd)/extraDevfileEntries.yaml | ||
# Cached remote samples directory | ||
samples_dir=$(pwd)/.cache/samples | ||
# default stacks directory | ||
stacks_dir=${STACKS:-"$(pwd)/stacks"} | ||
parents_file=$(pwd)/parents.yaml | ||
# Base directory path | ||
base_path=$(realpath $(dirname $(dirname $0))) | ||
|
||
# YAML query cmd path | ||
YQ_PATH=${YQ_PATH:-yq} | ||
|
||
# Read samples file as first argument | ||
# if unset use default samples file path | ||
if [ ! -z "${1}" ]; then | ||
samples_file=${1} | ||
fi | ||
|
||
get_parent_version() { | ||
devfile=$1 | ||
name=$2 | ||
version=$($YQ_PATH eval .parent.version ${devfile}) | ||
|
||
if [ "${version}" == "null" ] && [ -f "${stacks_dir}/${name}/stack.yaml" ]; then | ||
version=$($YQ_PATH eval '.versions | filter(.default) | .[0].version' ${stacks_dir}/${name}/stack.yaml) | ||
fi | ||
|
||
echo ${version} | ||
} | ||
|
||
# Get parent index if exists, else returns -1 | ||
parent_index() { | ||
name=$1 | ||
version=$2 | ||
|
||
if [ -z "${version}" ]; then | ||
result=$($YQ_PATH eval ".parents | to_entries | filter(.value.name == \"${name}\") | .[0].key" ${parents_file}) | ||
else | ||
result=$($YQ_PATH eval ".parents | to_entries | filter(.value.name == \"${name}\" and .value.version == \"${version}\") | .[0].key" ${parents_file}) | ||
fi | ||
|
||
if [ "${result}" == "null" ]; then | ||
echo "-1" | ||
else | ||
echo ${result} | ||
fi | ||
} | ||
|
||
# Get child index if exists, else returns -1 | ||
child_index() { | ||
parent_idx=$1 | ||
name=$2 | ||
version=$3 | ||
|
||
if [ -z "${version}" ]; then | ||
result=$($YQ_PATH eval ".parents.[${parent_idx}].children | to_entries | filter(.value.name == \"${name}\") | .[0].key" ${parents_file}) | ||
else | ||
result=$($YQ_PATH eval ".parents.[${parent_idx}].children | to_entries | filter(.value.name == \"${name}\" and .value.version == \"${version}\") | .[0].key" ${parents_file}) | ||
fi | ||
|
||
if [ "${result}" == "null" ]; then | ||
echo "-1" | ||
else | ||
echo ${result} | ||
fi | ||
} | ||
|
||
# Builds sample parent | ||
build_parent() { | ||
parent_name=$1 | ||
parent_version=$2 | ||
|
||
if [ "${parent_version}" == "null" ]; then | ||
parent_version="" | ||
fi | ||
|
||
if [ "${parent_name}" != "null" ]; then | ||
if [ ! -f ${parents_file} ]; then | ||
$YQ_PATH eval -n ".parents[0].name = \"${parent_name}\"" > ${parents_file} | ||
if [ "${parent_version}" != "" ]; then | ||
$YQ_PATH eval ".parents[0].version = \"${parent_version}\"" -i ${parents_file} | ||
fi | ||
|
||
return | ||
fi | ||
|
||
if [ "$($YQ_PATH eval .parents ${parents_file})" == "null" ]; then | ||
$YQ_PATH eval ".parents[0].name = \"${parent_name}\"" -i ${parents_file} | ||
if [ "${parent_version}" != "" ]; then | ||
$YQ_PATH eval ".parents[0].version = \"${parent_version}\"" -i ${parents_file} | ||
fi | ||
|
||
return | ||
fi | ||
|
||
parent_idx=$(parent_index ${parent_name} ${parent_version}) | ||
if [ "${parent_idx}" == "-1" ]; then | ||
next_idx=$($YQ_PATH eval ".parents | length" ${parents_file}) | ||
$YQ_PATH eval ".parents[${next_idx}].name = \"${parent_name}\"" -i ${parents_file} | ||
if [ "${parent_version}" != "" ]; then | ||
$YQ_PATH eval ".parents[${next_idx}].version = \"${parent_version}\"" -i ${parents_file} | ||
fi | ||
fi | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Builds a child of a parent stack | ||
build_child() { | ||
parent_name=$1 | ||
parent_version=$2 | ||
sample_name=$3 | ||
sample_version=$4 | ||
|
||
parent_idx=$(parent_index ${parent_name} ${parent_version}) | ||
|
||
if [ "$($YQ_PATH eval .parents[${parent_idx}].children ${parents_file})" == "null" ]; then | ||
$YQ_PATH eval ".parents[${parent_idx}].children[0].name = \"${sample_name}\"" -i ${parents_file} | ||
if [ "${sample_version}" != "" ]; then | ||
$YQ_PATH eval ".parents[${parent_idx}].children[0].version = \"${sample_version}\"" -i ${parents_file} | ||
fi | ||
|
||
return | ||
fi | ||
|
||
child_idx=$(child_index ${parent_idx} ${sample_name} ${sample_version}) | ||
if [ "${child_idx}" == "-1" ]; then | ||
next_idx=$($YQ_PATH eval ".parents[${parent_idx}].children | length" ${parents_file}) | ||
$YQ_PATH eval ".parents[${parent_idx}].children[${next_idx}].name = \"${sample_name}\"" -i ${parents_file} | ||
if [ "${sample_version}" != "" ]; then | ||
$YQ_PATH eval ".parents[${parent_idx}].children[${next_idx}].version = \"${sample_version}\"" -i ${parents_file} | ||
fi | ||
fi | ||
} | ||
|
||
build_parents_file() { | ||
samples_len=$($YQ_PATH eval '.samples | length' ${samples_file}) | ||
|
||
for ((s_idx=0;s_idx<${samples_len};s_idx++)); do | ||
sample_name=$($YQ_PATH eval .samples.${s_idx}.name ${samples_file}) | ||
sample_versions=($($YQ_PATH eval .samples.${s_idx}.versions.[].version ${samples_file})) | ||
|
||
# Iterate through sample versions if sample has multi version support | ||
if [ ${#sample_versions[@]} -ne 0 ]; then | ||
for ((v_idx=0;v_idx<${#sample_versions[@]};v_idx++)); do | ||
devfile=${samples_dir}/${sample_name}/${sample_versions[$v_idx]}/devfile.yaml | ||
parent_name=$($YQ_PATH eval .parent.id ${devfile}) | ||
parent_version=$(get_parent_version ${devfile} ${parent_name}) | ||
build_parent ${parent_name} ${parent_version} | ||
|
||
if [ $? -eq 0 ]; then | ||
build_child "${parent_name}" "${parent_version}" "${sample_name}" "${sample_versions[$v_idx]}" | ||
fi | ||
done | ||
else | ||
devfile=${samples_dir}/${sample_name}/devfile.yaml | ||
parent_name=$($YQ_PATH eval .parent.id ${devfile}) | ||
parent_version=$(get_parent_version ${devfile} ${parent_name}) | ||
build_parent ${parent_name} ${parent_version} | ||
|
||
if [ $? -eq 0 ]; then | ||
build_child "${parent_name}" "${parent_version}" "${sample_name}" "" | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
# Gets the children sample paths of parents. | ||
# When TEST_DELTA is set to true, only children of parents | ||
# with changes are returned. | ||
get_children_of_parents() { | ||
stack_dirs=$(bash $(pwd)/tests/get_stacks.sh) | ||
children=() | ||
|
||
for stack_dir in $stack_dirs; do | ||
if [ "$(basename $(dirname $stack_dir))" == "." ]; then | ||
stack_name=$(basename $stack_dir) | ||
|
||
names=($($YQ_PATH eval ".parents | filter(.name == \"${stack_name}\") | .[0].children.[].name" ${parents_file})) | ||
versions=($($YQ_PATH eval ".parents | filter(.name == \"${stack_name}\") | .[0].children.[].version" ${parents_file})) | ||
else | ||
stack_name=$(basename $(dirname $stack_dir)) | ||
stack_version=$(basename $stack_dir) | ||
|
||
names=($($YQ_PATH eval ".parents | filter(.name == \"${stack_name}\" and .version == \"${stack_version}\") | .[0].children.[].name" ${parents_file})) | ||
versions=($($YQ_PATH eval ".parents | filter(.name == \"${stack_name}\" and .version == \"${stack_version}\") | .[0].children.[].version" ${parents_file})) | ||
fi | ||
|
||
|
||
for ((c_idx=0;c_idx<${#names[@]};c_idx++)); do | ||
if [ "${versions[$c_idx]}" == "null" ]; then | ||
children+=("${names[$c_idx]}") | ||
else | ||
children+=("${names[$c_idx]}/${versions[$c_idx]}") | ||
fi | ||
done | ||
done | ||
|
||
echo ${children[@]} | ||
} | ||
|
||
if [ ! -d ${base_path}/registry-support ] | ||
then | ||
if [ "$VERBOSE" == "true" ] | ||
then | ||
git clone https://github.com/devfile/registry-support ${base_path}/registry-support | ||
else | ||
git clone -q https://github.com/devfile/registry-support ${base_path}/registry-support | ||
fi | ||
fi | ||
|
||
if [ "$VERBOSE" == "true" ] | ||
then | ||
bash ${base_path}/registry-support/build-tools/cache_samples.sh ${samples_file} ${samples_dir} | ||
else | ||
bash ${base_path}/registry-support/build-tools/cache_samples.sh ${samples_file} ${samples_dir} > /dev/null 2>&- echo | ||
fi | ||
|
||
if [ -f ${parents_file} ]; then | ||
rm ${parents_file} | ||
fi | ||
|
||
build_parents_file | ||
|
||
get_children_of_parents |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.