55# The downloaded samples are cached under /registry/samples in the devfile registry container
66set -eu
77
8- # download_sample takes in a given sample name (e.g. nodejs-basic), and git clones its corresponding repository
8+ # clone_sample_repo clones a given git repository to the sampleDir. Before cloning it checks
9+ # whether or not a revision exists.
10+ # Parameters:
11+ # 1: gitRepository (git repository url)
12+ # 2: sampleDir (output directory of the clone command)
13+ # 3: revision (the prefered revision of the git repo we want to clone)
14+ function clone_sample_repo() {
15+ local repoUrl=" $1 "
16+ local repoOutputDir=" $2 "
17+ local repoRevision=" $3 "
18+ git clone $repoUrl $repoOutputDir
19+ if [[ $repoRevision != " null" ]]; then
20+ cd $repoOutputDir && git checkout $repoRevision && cd -
21+ fi
22+ }
23+
24+ # cache_sample takes in a given sample name (e.g. nodejs-basic), and git clones its corresponding repository
925# Parameters:
1026# 1: Sample name (e.g. nodejs-basic)
11- # 2: Path to extraDevfileEntries.yaml
12- # 3: Output directory
27+ # 2: Output directory
1328function cache_sample() {
1429 local sampleName=" $1 "
1530 local outputDir=" $2 "
@@ -18,15 +33,17 @@ function cache_sample() {
1833
1934 # Git clone the sample project
2035 gitRepository=" $( yq e ' (.samples[] | select(.name == "' ${sampleName} ' ")' $devfileEntriesFile | yq e ' (.git.remotes.origin)' -) "
36+ revision=" $( yq e ' (.samples[] | select(.name == "' ${sampleName} ' ")' $devfileEntriesFile | yq e ' (.git.checkoutFrom.revision)' -) "
2137 if [[ $gitRepository == " null" ]]; then
2238 for version in $( yq e ' (.samples[] | select(.name == "' ${sampleName} ' ")' $devfileEntriesFile | yq e ' (.versions[].version)' -) ; do
2339 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 "
40+ revision=" $( yq e ' (.samples[] | select(.name == "' ${sampleName} ' ")' $devfileEntriesFile | yq e ' (.versions[] | select(.version == "' ${version} ' ")' -| yq e ' .git.checkoutFrom.revision' -) "
41+ clone_sample_repo $gitRepository $sampleDir /$version $revision
2542 mkdir $outputDir /$version
2643 cache_devfile $sampleDir /$version $outputDir /$version $sampleName
2744 done
2845 else
29- git clone " $gitRepository " " $sampleDir "
46+ clone_sample_repo $gitRepository $sampleDir $revision
3047 cache_devfile $sampleDir $outputDir / $sampleName
3148 fi
3249
0 commit comments