Skip to content

Commit 40b70ab

Browse files
fixed merge conflicts
2 parents 655c290 + 018c568 commit 40b70ab

File tree

31 files changed

+2987
-1489
lines changed

31 files changed

+2987
-1489
lines changed

build-tools/build.sh

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
buildToolsFolder="$(dirname "$0")"
13+
buildToolsDir="$PWD"
1314
generatorFolder=$buildToolsFolder/../index/generator
1415

1516
display_usage() {
@@ -22,6 +23,22 @@ cleanup_and_exit() {
2223
exit $1
2324
}
2425

26+
tar_files_and_cleanup() {
27+
# Find the files to add to the tar archive
28+
tarFiles=$(find . \( -not -name 'devfile.yaml' \
29+
-a -not -name "meta.yaml" \
30+
-a -not -name "*.vsx" \
31+
-a -not -name "." \
32+
-a -not -name "logo.svg" \
33+
-a -not -name "logo.png" \) -maxdepth 1)
34+
35+
# There are files that need to be pulled into a tar archive
36+
if [[ ! -z $tarFiles ]]; then
37+
tar -czvf archive.tar $tarFiles > /dev/null
38+
rm -rf $tarFiles
39+
fi
40+
}
41+
2542
# build_registry <registry-folder> <output>
2643
# Runs the steps to build the registry. Mainly:
2744
# 1. Copying over registry repository to build folder
@@ -41,29 +58,26 @@ build_registry() {
4158
echo "Failed to build index-generator tool"
4259
return 1
4360
fi
44-
echo "Successfully built the index-generator tool\n"
61+
echo "Successfully built the index-generator tool"
4562

4663
cd "$OLDPWD"
4764

4865
# Generate the tar archive
49-
for stackDir in $outputFolder/stacks/*/
66+
for stackDir in $outputFolder/stacks/*
5067
do
5168
cd $stackDir
52-
# Find the files to add to the tar archive
53-
tarFiles=$(find . \( -not -name 'devfile.yaml' \
54-
-a -not -name "meta.yaml" \
55-
-a -not -name "*.vsx" \
56-
-a -not -name "." \
57-
-a -not -name "logo.svg" \
58-
-a -not -name "logo.png" \) -maxdepth 1)
59-
60-
# There are files that need to be pulled into a tar archive
61-
if [[ ! -z $tarFiles ]]; then
62-
tar -czvf archive.tar $tarFiles > /dev/null
63-
rm -rf $tarFiles
69+
if [[ -f "stack.yaml" ]]; then
70+
for versionDir in $stackDir/*
71+
do
72+
cd $versionDir
73+
tar_files_and_cleanup
74+
done
75+
else
76+
tar_files_and_cleanup
6477
fi
6578
cd "$OLDPWD"
6679
done
80+
cd "$buildToolsDir"
6781

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

88102
# check_params validates that the arguments passed into the script are valid

build-tools/cache_samples.sh

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ function cache_sample() {
1414
local sampleName="$1"
1515
local outputDir="$2"
1616
tempDir=$(mktemp -d)
17+
sampleDir=$tempDir/$sampleName
1718

1819
# Git clone the sample project
19-
local gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.git.remotes.origin)' -)"
20-
git clone "$gitRepository" "$tempDir/$sampleName"
20+
gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.git.remotes.origin)' -)"
21+
if [[ $gitRepository == "null" ]]; then
22+
for version in $(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.versions[].version)' -); do
23+
gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.versions[] | select(.version == "'${version}'")' -| yq e '.git.remotes.origin' -)"
24+
git clone "$gitRepository" "$sampleDir/$version"
25+
mkdir $outputDir/$version
26+
cache_devfile $sampleDir/$version $outputDir/$version $sampleName
27+
done
28+
else
29+
git clone "$gitRepository" "$sampleDir"
30+
cache_devfile $sampleDir $outputDir/ $sampleName
31+
fi
2132

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

48+
# Archive the sample project
49+
(cd $tempDir && zip -r sampleName.zip $sampleName/)
50+
cp $tempDir/sampleName.zip $outputDir/
51+
52+
}
53+
54+
function cache_devfile() {
55+
local srcDir="$1"
56+
local outputDir="$2"
57+
local sampleName="$3"
3758
# Cache the devfile for the sample
38-
if [[ -f "$tempDir/$sampleName/devfile.yaml" ]]; then
39-
cp $tempDir/$sampleName/devfile.yaml $outputDir/
40-
elif [[ -f "$tempDir/$sampleName/.devfile/devfile.yaml" ]]; then
41-
cp $tempDir/$sampleName/.devfile/devfile.yaml $outputDir/
59+
if [[ -f "$srcDir/devfile.yaml" ]]; then
60+
cp $srcDir/devfile.yaml $outputDir/
61+
elif [[ -f "$srcDir/.devfile/devfile.yaml" ]]; then
62+
cp $srcDir/.devfile/devfile.yaml $outputDir/
4263
else
43-
echo "A devfile for sample $sampleName could not be found."
64+
echo "A devfile for sample $sampleName, version $(basename $srcDir) could not be found."
4465
echo "Please ensure a devfile exists in the root of the repository or under .devfile/"
4566
exit 1
4667
fi
47-
48-
49-
# Archive the sample project
50-
(cd $tempDir && zip -r sampleName.zip $sampleName/)
51-
cp $tempDir/sampleName.zip $outputDir/
52-
5368
}
5469

5570
devfileEntriesFile=$1

0 commit comments

Comments
 (0)