Skip to content

Commit

Permalink
Merge pull request #103 from yangcao77/761-multiversion-support
Browse files Browse the repository at this point in the history
Update index generator to generate new index schema which supports multi versions
  • Loading branch information
yangcao77 authored Mar 1, 2022
2 parents 7a90a42 + 860d6d1 commit 018c568
Show file tree
Hide file tree
Showing 66 changed files with 6,150 additions and 1,764 deletions.
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

0 comments on commit 018c568

Please sign in to comment.