Skip to content
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

Update index generator to generate new index schema which supports multi versions #103

Merged
merged 10 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions build-tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


buildToolsFolder="$(dirname "$0")"
buildToolsDir="$PWD"
generatorFolder=$buildToolsFolder/../index/generator

display_usage() {
Expand All @@ -22,6 +23,22 @@ cleanup_and_exit() {
exit $1
}

tar_files_and_cleanup() {
# Find the files to add to the tar archive
tarFiles=$(find . \( -not -name 'devfile.yaml' \
-a -not -name "meta.yaml" \
-a -not -name "*.vsx" \
-a -not -name "." \
-a -not -name "logo.svg" \
-a -not -name "logo.png" \) -maxdepth 1)

# There are files that need to be pulled into a tar archive
if [[ ! -z $tarFiles ]]; then
tar -czvf archive.tar $tarFiles > /dev/null
rm -rf $tarFiles
fi
}

# build_registry <registry-folder> <output>
# Runs the steps to build the registry. Mainly:
# 1. Copying over registry repository to build folder
Expand All @@ -41,29 +58,26 @@ build_registry() {
echo "Failed to build index-generator tool"
return 1
fi
echo "Successfully built the index-generator tool\n"
echo "Successfully built the index-generator tool"

cd "$OLDPWD"

# Generate the tar archive
for stackDir in $outputFolder/stacks/*/
for stackDir in $outputFolder/stacks/*
do
cd $stackDir
# Find the files to add to the tar archive
tarFiles=$(find . \( -not -name 'devfile.yaml' \
-a -not -name "meta.yaml" \
-a -not -name "*.vsx" \
-a -not -name "." \
-a -not -name "logo.svg" \
-a -not -name "logo.png" \) -maxdepth 1)

# There are files that need to be pulled into a tar archive
if [[ ! -z $tarFiles ]]; then
tar -czvf archive.tar $tarFiles > /dev/null
rm -rf $tarFiles
if [[ -f "stack.yaml" ]]; then
for versionDir in $stackDir/*
do
cd $versionDir
tar_files_and_cleanup
done
else
tar_files_and_cleanup
fi
cd "$OLDPWD"
done
cd "$buildToolsDir"

# Cache any devfile samples if needed
if [ -f $registryRepository/extraDevfileEntries.yaml ]; then
Expand All @@ -82,7 +96,7 @@ build_registry() {
echo "Failed to build the devfile registry index"
return 1
fi
echo "Successfully built the devfile registry index\n"
echo "Successfully built the devfile registry index"
}

# check_params validates that the arguments passed into the script are valid
Expand Down
43 changes: 29 additions & 14 deletions build-tools/cache_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ function cache_sample() {
local sampleName="$1"
local outputDir="$2"
tempDir=$(mktemp -d)
sampleDir=$tempDir/$sampleName

# Git clone the sample project
local gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.git.remotes.origin)' -)"
git clone "$gitRepository" "$tempDir/$sampleName"
gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.git.remotes.origin)' -)"
if [[ $gitRepository == "null" ]]; then
for version in $(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.versions[].version)' -); do
gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.versions[] | select(.version == "'${version}'")' -| yq e '.git.remotes.origin' -)"
git clone "$gitRepository" "$sampleDir/$version"
mkdir $outputDir/$version
cache_devfile $sampleDir/$version $outputDir/$version $sampleName
done
else
git clone "$gitRepository" "$sampleDir"
cache_devfile $sampleDir $outputDir/ $sampleName
fi

# Cache the icon for the sample
local iconPath="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.icon)' -)"
Expand All @@ -30,26 +41,30 @@ function cache_sample() {
echo "The specified icon does not exist for sample $sampleName"
exit 1
fi
cp $tempDir/$sampleName/$iconPath $outputDir/
cp $sampleDir/$iconPath $outputDir/
fi
fi

# Archive the sample project
(cd $tempDir && zip -r sampleName.zip $sampleName/)
cp $tempDir/sampleName.zip $outputDir/

}

function cache_devfile() {
local srcDir="$1"
local outputDir="$2"
local sampleName="$3"
# Cache the devfile for the sample
if [[ -f "$tempDir/$sampleName/devfile.yaml" ]]; then
cp $tempDir/$sampleName/devfile.yaml $outputDir/
elif [[ -f "$tempDir/$sampleName/.devfile/devfile.yaml" ]]; then
cp $tempDir/$sampleName/.devfile/devfile.yaml $outputDir/
if [[ -f "$srcDir/devfile.yaml" ]]; then
cp $srcDir/devfile.yaml $outputDir/
elif [[ -f "$srcDir/.devfile/devfile.yaml" ]]; then
cp $srcDir/.devfile/devfile.yaml $outputDir/
else
echo "A devfile for sample $sampleName could not be found."
echo "A devfile for sample $sampleName, version $(basename $srcDir) could not be found."
echo "Please ensure a devfile exists in the root of the repository or under .devfile/"
exit 1
fi


# Archive the sample project
(cd $tempDir && zip -r sampleName.zip $sampleName/)
cp $tempDir/sampleName.zip $outputDir/

}

devfileEntriesFile=$1
Expand Down
Loading