Skip to content

Commit

Permalink
Update cache_samples to support multiple sample versions and revisions (
Browse files Browse the repository at this point in the history
devfile#178)

Signed-off-by: [email protected]

Signed-off-by: [email protected]
Signed-off-by: thepetk <[email protected]>
  • Loading branch information
thepetk committed Aug 23, 2023
1 parent 88a8b45 commit e15b929
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions build-tools/cache_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,26 @@
# The downloaded samples are cached under /registry/samples in the devfile registry container
set -eu

# download_sample takes in a given sample name (e.g. nodejs-basic), and git clones its corresponding repository
# clone_sample_repo clones a given git repository to the sampleDir. Before cloning it checks
# whether or not a revision exists.
# Parameters:
# 1: gitRepository (git repository url)
# 2: sampleDir (output directory of the clone command)
# 3: revision (the prefered revision of the git repo we want to clone)
function clone_sample_repo() {
local repoUrl="$1"
local repoOutputDir="$2"
local repoRevision="$3"
git clone $repoUrl $repoOutputDir
if [[ $repoRevision != "null" ]]; then
cd $repoOutputDir && git checkout $repoRevision && cd -
fi
}

# cache_sample takes in a given sample name (e.g. nodejs-basic), and git clones its corresponding repository
# Parameters:
# 1: Sample name (e.g. nodejs-basic)
# 2: Path to extraDevfileEntries.yaml
# 3: Output directory
# 2: Output directory
function cache_sample() {
local sampleName="$1"
local outputDir="$2"
Expand All @@ -18,15 +33,17 @@ function cache_sample() {

# Git clone the sample project
gitRepository="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.git.remotes.origin)' -)"
revision="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.git.checkoutFrom.revision)' -)"
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"
revision="$(yq e '(.samples[] | select(.name == "'${sampleName}'")' $devfileEntriesFile | yq e '(.versions[] | select(.version == "'${version}'")' -| yq e '.git.checkoutFrom.revision' -)"
clone_sample_repo $gitRepository $sampleDir/$version $revision
mkdir $outputDir/$version
cache_devfile $sampleDir/$version $outputDir/$version $sampleName
done
else
git clone "$gitRepository" "$sampleDir"
clone_sample_repo $gitRepository $sampleDir $revision
cache_devfile $sampleDir $outputDir/ $sampleName
fi

Expand Down

0 comments on commit e15b929

Please sign in to comment.