Overhaul build script - KSP-CKAN/CKAN#1273

This commit is contained in:
Leon Wright 2015-07-17 18:13:30 +08:00 committed by Leon Wright
parent 64b743d0ba
commit fa22a3df17
1 changed files with 142 additions and 42 deletions

184
build.sh
View File

@ -1,59 +1,159 @@
#!/bin/bash
set -x
set -e
# Locations of CKAN and NetKAN.
# Default flags.
KSP_VERSION_DEFAULT="1.0.2"
KSP_NAME_DEFAULT="dummy"
# Locations of CKAN and validation.
LATEST_CKAN_URL="http://ckan-travis.s3.amazonaws.com/ckan.exe"
LATEST_CKAN_VALIDATE="https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/bin/ckan-validate.py"
LATEST_CKAN_SCHEMA="https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/CKAN.schema"
LATEST_CKAN_META="https://github.com/KSP-CKAN/CKAN-meta/archive/master.tar.gz"
echo Commit hash: ${ghprbActualCommit}
echo Changes in this commit:
export COMMIT_CHANGES="`git diff --diff-filter=AM --name-only --stat origin/master`"
echo ${COMMIT_CHANGES}
# Third party utilities.
JQ_PATH="jq"
wget --quiet https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/bin/ckan-validate.py -O ckan-validate.py
wget --quiet https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/CKAN.schema -O CKAN.schema
# ------------------------------------------------
# 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.
if [ "$KSP_VERSION" == "0.90" ]
then
KSP_VERSION="0.90.0"
fi
echo "Creating a dummy KSP $KSP_VERSION install"
# Remove any existing KSP dummy install.
if [ -d "dummy_ksp/" ]
then
rm -rf 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
echo "Version $KSP_VERSION" > dummy_ksp/readme.txt
# Copy in resources.
cp 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
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
}
# Find the changes to test.
echo "Finding changes to test..."
if [ -n $ghprbActualCommit ]
then
echo Commit hash: ${ghprbActualCommit}
echo Changes in this commit:
export COMMIT_CHANGES="`git diff --diff-filter=AM --name-only --stat origin/master`"
echo ${COMMIT_CHANGES}
else
echo "No commit ID to test"
exit 1
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
# fetch latest ckan.exe
echo "Fetching latest ckan.exe"
wget --quiet $LATEST_CKAN_URL -O ckan.exe
# create a dummy KSP install
mkdir dummy_ksp
echo Version 1.0.4 > dummy_ksp/readme.txt
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
# Fetch the latest metadata.
echo "Fetching latest metadata"
wget --quiet $LATEST_CKAN_META -O metadata.tar.gz
mono --debug ckan.exe ksp add ${ghprbActualCommit} "`pwd`/dummy_ksp"
mono --debug ckan.exe ksp default ${ghprbActualCommit}
mono --debug ckan.exe update
# Create folders.
# TODO: Point to cache folder here instead if possible.
if [ ! -d "downloads_cache/" ]
then
mkdir downloads_cache
fi
for f in ${COMMIT_CHANGES}
do
if [ "$f" != "build.sh" ]; then
./ckan-validate.py $f
echo ----------------------------------------------
echo
cat $f | python -m json.tool
echo ----------------------------------------------
echo
echo Running ckan install -c $f
mono --debug ckan.exe install -c $f --headless
fi
done
# Show all installed mods.
echo "Installed mods:"
mono --debug ckan.exe list --porcelain
perl -e'@installed = `mono --debug ckan.exe list --porcelain`; foreach (@installed) { /^\S\s(?<mod>\S+)/ and system("mono --debug ckan.exe show $+{mod}"); print "\n\n"; } exit 0;'
# set -e doesn't apply inside an if block CKAN#1273
if [ "$f" = "build.sh" ]; then
echo "Lets try not to validate our build script with CKAN"
continue
fi
# Cleanup.
mono ckan.exe ksp forget ${ghprbActualCommit}
./ckan-validate.py $f
echo ----------------------------------------------
cat $f | python -m json.tool
echo ----------------------------------------------
# Extract identifier and KSP version.
CURRENT_IDENTIFIER=$($JQ_PATH '.identifier' $f)
CURRENT_KSP_VERSION=$($JQ_PATH 'if .ksp_version then .ksp_version else .ksp_version_min end' $f)
# 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."
# Create a dummy KSP install.
create_dummy_ksp $CURRENT_KSP_VERSION $ghprbActualCommit
echo Running ckan install -c $f
mono --debug ckan.exe install -c $f --headless
# 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
done