Skip to content

Commit

Permalink
Merge pull request #32 from HebaruSan/fix/injection-and-cache
Browse files Browse the repository at this point in the history
Fix dependency injection and shared cache
  • Loading branch information
techman83 authored Jan 5, 2018
2 parents d63a88c + 38081bf commit 745d6de
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 72 deletions.
100 changes: 54 additions & 46 deletions CKAN-meta/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ then
echo "Using CLI argument of $1"
ghprbActualCommit=$1
fi

# ------------------------------------------------
# Function for creating dummy KSP directories to
# test on. Takes version as an argument.
# ------------------------------------------------
create_dummy_ksp () {
KSP_VERSION=$KSP_VERSION_DEFAULT
KSP_NAME=$KSP_NAME_DEFAULT

# Set the version to the requested KSP version if supplied.
if [ $# -eq 2 ]
then
KSP_VERSION=$1
KSP_NAME=$2
fi

# TODO: Manual hack, a better way to handle this kind of identifiers may be needed.
case $KSP_VERSION in
"0.23")
Expand Down Expand Up @@ -119,51 +119,54 @@ create_dummy_ksp () {
esac

echo "Creating a dummy KSP '$KSP_VERSION' install"

# Remove any existing KSP dummy install.
if [ -d "dummy_ksp/" ]
then
rm -rf dummy_ksp
rm -rf --verbose dummy_ksp
fi

# Create a new dummy KSP.
mkdir dummy_ksp
mkdir dummy_ksp/CKAN
mkdir dummy_ksp/GameData
mkdir dummy_ksp/Ships/
mkdir dummy_ksp/Ships/VAB
mkdir dummy_ksp/Ships/SPH
mkdir dummy_ksp/Ships/@thumbs
mkdir dummy_ksp/Ships/@thumbs/VAB
mkdir dummy_ksp/Ships/@thumbs/SPH

mkdir -p --verbose \
dummy_ksp \
dummy_ksp/CKAN \
dummy_ksp/GameData \
dummy_ksp/Ships/ \
dummy_ksp/Ships/VAB \
dummy_ksp/Ships/SPH \
dummy_ksp/Ships/@thumbs \
dummy_ksp/Ships/@thumbs/VAB \
dummy_ksp/Ships/@thumbs/SPH

# Link to the shared downloads cache.
# NOTE: If this isn't done before ckan.exe uses the instance,
# it will be auto-created as a plain directory!
ln -s --verbose ../../downloads_cache/ dummy_ksp/CKAN/downloads/

echo "Version $KSP_VERSION" > dummy_ksp/readme.txt

# Copy in resources.
cp ckan.exe dummy_ksp/ckan.exe
cp --verbose ckan.exe dummy_ksp/ckan.exe

# Reset the Mono registry.
if [ "$USER" = "jenkins" ]
then
REGISTRY_FILE=$HOME/.mono/registry/CurrentUser/software/ckan/values.xml
if [ -r $REGISTRY_FILE ]
then
rm -f $REGISTRY_FILE
rm -f --verbose $REGISTRY_FILE
fi
fi

# Register the new dummy install.
mono ckan.exe ksp add $KSP_NAME "`pwd`/dummy_ksp"

# Set the instance to default.
mono ckan.exe ksp default $KSP_NAME

# Point to the local metadata instead of GitHub.
mono ckan.exe repo add local "file://`pwd`/master.tar.gz"
mono ckan.exe repo remove default

# Link to the downloads cache.
ln -s ../../downloads_cache/ dummy_ksp/CKAN/downloads/
}

# ------------------------------------------------
Expand All @@ -179,25 +182,27 @@ inject_metadata () {
if [ $# -ne 1 ]
then
echo "Nothing to inject."
cp metadata.tar.gz master.tar.gz
cp --verbose metadata.tar.gz master.tar.gz
return 0
fi

# Extract the metadata into a new folder.
rm -rf CKAN-meta-master
rm -rf --verbose CKAN-meta-master
tar -xzf metadata.tar.gz

# Copy in the files to inject.
# TODO: Unsure why this suddenly needs [*] declaration
# but it does work
for f in ${OTHER_FILES[*]}
do
echo "Injecting $f"
cp $f CKAN-meta-master
DEST="CKAN-meta-master/$f"
mkdir -p --verbose $(dirname "$DEST")
cp --verbose $f "$DEST"
done

# Recompress the archive.
rm -f master.tar.gz
rm -f --verbose master.tar.gz
tar -czf master.tar.gz CKAN-meta-master
}

Expand All @@ -220,23 +225,23 @@ fi
# Make sure we start from a clean slate.
if [ -d "downloads_cache/" ]
then
rm -rf downloads_cache
rm -rf --verbose downloads_cache
fi

if [ -e "master.tar.gz" ]
then
rm -f master.tar.gz
rm -f --verbose master.tar.gz
fi

if [ -e "metadata.tar.gz" ]
then
rm -f metadata.tar.gz
rm -f --verbose metadata.tar.gz
fi

# CKAN Validation files
wget --quiet $LATEST_CKAN_VALIDATE -O ckan-validate.py
wget --quiet $LATEST_CKAN_SCHEMA -O CKAN.schema
chmod a+x ckan-validate.py
chmod a+x --verbose ckan-validate.py

# fetch latest ckan.exe
echo "Fetching latest ckan.exe"
Expand All @@ -251,7 +256,7 @@ wget --quiet $LATEST_CKAN_META -O metadata.tar.gz
# TODO: Point to cache folder here instead if possible.
if [ ! -d "downloads_cache/" ]
then
mkdir downloads_cache
mkdir --verbose downloads_cache
fi

for ckan in $COMMIT_CHANGES
Expand All @@ -261,7 +266,7 @@ do
echo "Lets try not to validate our build script with CKAN"
continue
fi

./ckan-validate.py $ckan
echo ----------------------------------------------
cat $ckan | python -m json.tool
Expand All @@ -270,17 +275,17 @@ do
# Extract identifier and KSP version.
CURRENT_IDENTIFIER=$($JQ_PATH '.identifier' $ckan)
CURRENT_KSP_VERSION=$($JQ_PATH 'if .ksp_version then .ksp_version else .ksp_version_max end' $ckan)

# Strip "'s.
CURRENT_IDENTIFIER=${CURRENT_IDENTIFIER//'"'}
CURRENT_KSP_VERSION=${CURRENT_KSP_VERSION//'"'}

echo "Extracted $CURRENT_IDENTIFIER as identifier."
echo "Extracted $CURRENT_KSP_VERSION as KSP version."

# Get a list of all the OTHER files.
OTHER_FILES=()

for o in $COMMIT_CHANGES
do
if [ "$ckan" != "$o" ] && [ "$ckan" != "build.sh" ]
Expand All @@ -292,7 +297,7 @@ do

# Inject into metadata.
inject_metadata $OTHER_FILES

# Create a dummy KSP install.
create_dummy_ksp $CURRENT_KSP_VERSION $ghprbActualCommit

Expand All @@ -305,10 +310,13 @@ do
# Show all installed mods.
echo "Installed mods:"
mono --debug ckan.exe list --porcelain

# Check the installed files for this .ckan file.
mono ckan.exe show $CURRENT_IDENTIFIER

# Cleanup.
mono ckan.exe ksp forget $KSP_NAME

# Blank line between files
echo
done
61 changes: 35 additions & 26 deletions NetKAN/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,32 +133,38 @@ create_dummy_ksp () {
# Remove any existing KSP dummy install.
if [ -d "dummy_ksp/" ]
then
rm -rf dummy_ksp
rm -rf --verbose dummy_ksp
fi

# Create a new dummy KSP.
mkdir dummy_ksp
mkdir dummy_ksp/CKAN
mkdir dummy_ksp/GameData
mkdir dummy_ksp/Ships/
mkdir dummy_ksp/Ships/VAB
mkdir dummy_ksp/Ships/SPH
mkdir dummy_ksp/Ships/@thumbs
mkdir dummy_ksp/Ships/@thumbs/VAB
mkdir dummy_ksp/Ships/@thumbs/SPH
mkdir -p --verbose \
dummy_ksp \
dummy_ksp/CKAN \
dummy_ksp/GameData \
dummy_ksp/Ships/ \
dummy_ksp/Ships/VAB \
dummy_ksp/Ships/SPH \
dummy_ksp/Ships/@thumbs \
dummy_ksp/Ships/@thumbs/VAB \
dummy_ksp/Ships/@thumbs/SPH

# Link to the downloads cache.
# NOTE: If this isn't done before ckan.exe uses the instance,
# it will be auto-created as a plain directory!
ln -s --verbose ../../downloads_cache/ dummy_ksp/CKAN/downloads/

echo "Version $KSP_VERSION" > dummy_ksp/readme.txt

# Copy in resources.
cp ckan.exe dummy_ksp/ckan.exe
cp --verbose ckan.exe dummy_ksp/ckan.exe

# Reset the Mono registry.
if [ "$USER" = "jenkins" ]
then
REGISTRY_FILE=$HOME/.mono/registry/CurrentUser/software/ckan/values.xml
if [ -r $REGISTRY_FILE ]
then
rm -f $REGISTRY_FILE
rm -f --verbose $REGISTRY_FILE
fi
fi

Expand All @@ -171,9 +177,6 @@ create_dummy_ksp () {
# Point to the local metadata instead of GitHub.
mono ckan.exe repo add local "file://`pwd`/master.tar.gz"
mono ckan.exe repo remove default

# Link to the downloads cache.
ln -s ../../downloads_cache/ dummy_ksp/CKAN/downloads/
}

# ------------------------------------------------
Expand All @@ -189,14 +192,14 @@ inject_metadata () {
if [ $# -ne 1 ]
then
echo "Nothing to inject."
cp metadata.tar.gz master.tar.gz
cp --verbose metadata.tar.gz master.tar.gz
return 0
fi

echo "Injecting into metadata."

# Extract the metadata into a new folder.
rm -rf CKAN-meta-master
rm -rf --verbose CKAN-meta-master
tar -xzf metadata.tar.gz

# Copy in the files to inject.
Expand All @@ -205,11 +208,13 @@ inject_metadata () {
for f in ${OTHER_FILES[*]}
do
echo "Injecting: $f"
cp $f CKAN-meta-master
DEST="CKAN-meta-master/$f"
mkdir -p --verbose $(dirname "$DEST")
cp --verbose $f "$DEST"
done

# Recompress the archive.
rm -f master.tar.gz
rm -f --verbose master.tar.gz
tar -czf master.tar.gz CKAN-meta-master
}

Expand All @@ -229,22 +234,22 @@ fi
# Make sure we start from a clean slate.
if [ -d "built/" ]
then
rm -rf built
rm -rf --verbose built
fi

if [ -d "downloads_cache/" ]
then
rm -rf downloads_cache
rm -rf --verbose downloads_cache
fi

if [ -e "master.tar.gz" ]
then
rm -f master.tar.gz
rm -f --verbose master.tar.gz
fi

if [ -e "metadata.tar.gz" ]
then
rm -f metadata.tar.gz
rm -f --verbose metadata.tar.gz
fi

# Check our new NetKAN is not in the root of our repo
Expand Down Expand Up @@ -300,8 +305,9 @@ done
echo ""

# Create folders.
mkdir built
mkdir downloads_cache # TODO: Point to cache folder here instead if possible.
mkdir --verbose built
# Point to cache folder here
mkdir --verbose downloads_cache

# Fetch latest ckan and netkan executable.
echo "Fetching latest ckan.exe"
Expand All @@ -315,7 +321,7 @@ mono netkan.exe --version
# CKAN Validation files
wget --quiet $LATEST_CKAN_VALIDATE -O ckan-validate.py
wget --quiet $LATEST_CKAN_SCHEMA -O CKAN.schema
chmod a+x ckan-validate.py
chmod a+x --verbose ckan-validate.py

# Fetch the latest metadata.
echo "Fetching latest metadata"
Expand Down Expand Up @@ -415,4 +421,7 @@ do
printf '%s\n' "Path: ${gamedata[@]}"
exit 1;
fi

# Blank line between files
echo
done

0 comments on commit 745d6de

Please sign in to comment.