Skip to content

Commit

Permalink
Set up automated deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisAdderley committed Jan 14, 2019
1 parent 360fae0 commit fc93579
Show file tree
Hide file tree
Showing 18 changed files with 708 additions and 683 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
build_scripts/* linguist-vendored
9 changes: 8 additions & 1 deletion .gitignore
Expand Up @@ -129,7 +129,7 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
Expand Down Expand Up @@ -194,3 +194,10 @@ FakesAssemblies/

# Visual Studio 6 workspace options file
*.opt
*.pyc
.idea/
build/
tmp/
deploy/
build_scripts/version.txt
build_scripts/changelog.md
49 changes: 49 additions & 0 deletions .travis.yml
@@ -0,0 +1,49 @@
language: python
python:
- 3.6
install:
- pip install awscli boto3 requests
branches:
only:
- master
script:
- python build_scripts/build.py
before_deploy:
- VERSION=$(cat build_scripts/version.txt)
- CHANGELOG=$(cat build_scripts/changelog.md)
- IFS='/'; BASENAME=($TRAVIS_REPO_SLUG); unset IFS;
- RELEASE_NAME="${BASENAME[1]} $VERSION"
- echo $VERSION
- git config --local user.name "ChrisAdderley"
- git config --local user.email "cadderley@gmail.com"
- git remote set-url origin https://ChrisAdderley:${GITHUB_OAUTH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
# Only tag if this is the first before_deploy (runs for all providers)
- >
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
export BEFORE_DEPLOY_RUN=1;
git tag $VERSION;
git push origin $VERSION;
fi
deploy:
- provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: "nertea-ksp-modding-releases"
local_dir: deploy
skip_cleanup: true
acl: public_read
region: us-east-2
upload-dir: near-future-props
on:
condition: $TRAVIS_BRANCH = master
- deploy:
provider: releases
api_key: $GITHUB_OAUTH_TOKEN
file_glob: true
file: deploy/*
body: "$CHANGELOG"
name: $RELEASE_NAME
skip_cleanup: true
on:
tags: false
condition: $TRAVIS_BRANCH = master
674 changes: 0 additions & 674 deletions GameData/NearFutureProps/Versioning/MiniAVC-LICENSE.txt

This file was deleted.

Binary file removed GameData/NearFutureProps/Versioning/MiniAVC.dll
Binary file not shown.
14 changes: 7 additions & 7 deletions GameData/NearFutureProps/Versioning/NearFutureProps.version
@@ -1,28 +1,28 @@
{
"NAME":"NearFutureProps",
"URL":"https://raw.githubusercontent.com/ChrisAdderley/NearFutureProps/master/GameData/NearFutureProps/Versioning/NearFutureProps.version",
"DOWNLOAD":"https://forum.kerbalspaceprogram.com/index.php?/topic/166941-131-near-future-props-prop-assets-for-iva-developers-december-15th-2017",
"DOWNLOAD":"https://github.com/ChrisAdderley/NearFutureProps/releases",
"VERSION":
{
"MAJOR":0,
"MINOR":3,
"PATCH":5,
"MINOR":5,
"PATCH":0,
"BUILD":0
},
"KSP_VERSION":
{
"MAJOR":1,
"MINOR":5,
"PATCH":0
"MINOR":6,
"PATCH":1
},
"KSP_VERSION_MIN":{
"MAJOR":1,
"MINOR":5,
"MINOR":6,
"PATCH":0
},
"KSP_VERSION_MAX":{
"MAJOR":1,
"MINOR":5,
"MINOR":6,
"PATCH":99
}
}
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# Near Future Props 0.3.5
# Near Future Props 0.5.0
This is an IVA props set for Kerbal Space Program, useful for building detailed internal spaces. It has all sorts of fun parts, some inspired by real space gadgets, some by general science, and some that are just fun.

## Recent Changes
Expand Down
159 changes: 159 additions & 0 deletions build_scripts/build.py
@@ -0,0 +1,159 @@
# Build script entrypoint
import os
import shutil
import zipfile
import zlib
import sys
from argparse import ArgumentParser

from build_support.build_helpers import *
from build_support.dependencies import download_dependency


# Build paths
TEMP_PATH = "tmp"
BUILD_PATH = "build"
DEPLOY_PATH = "deploy"

# Root directoy files to keep in the archives
VALID_FILES = ["changelog.txt", "readme.txt"]

def build_nodep_release(version_data, mod_name):
"""
Builds the release zip with no included dependencies
Inputs:
version_data (dict): Contents of the .version file
mod_name (str): name of the mod
"""
build_path = os.path.join(DEPLOY_PATH,
f"{mod_name}_Core_" + "{MAJOR}_{MINOR}_{PATCH}".format(**version_data["VERSION"]))
shutil.make_archive(build_path, 'zip', os.path.join(BUILD_PATH))
print(f"> Built {build_path}")

def build_full_release(version_data, mod_name):
"""
Builds the release zip with a full set of required dependencies
Inputs:
version_data (dict): Contents of the .version file
mod_name (str): name of the mod
"""
build_path = os.path.join(DEPLOY_PATH,
f"{mod_name}_" + "{MAJOR}_{MINOR}_{PATCH}".format(**version_data["VERSION"]))
shutil.make_archive(build_path, 'zip', os.path.join(BUILD_PATH))
print(f"> Built {build_path}")

def build_extras(version_data, build_packages=False):
"""
Compiles and optionally builds packages for all Extras in the mod
Inputs:
version_data (dict): Contents of the .version file
build_packages (bool): whether to create an individual zipfile for each package
"""
for root, dirs, files in os.walk("Extras"):
for name in dirs:
build_extra(name, version_data, build_packages)

def build_extra(name, version_data, build_package):
"""
Compiles and optionally builds a single Extras package
Inputs:
name (str): name of the extra
version_data (dict): Contents of the .version file
build_package (bool): whether to create an individual zipfile for the package
"""
extra_path = os.path.join(DEPLOY_PATH, f"{name}" + "{MAJOR}_{MINOR}_{PATCH}".format(**version_data["VERSION"]))
print(f"> Compiling Extra {name}")
ensure_path(os.path.join(BUILD_PATH,"Extras"))
shutil.copytree(os.path.join("Extras", name), os.path.join(BUILD_PATH,"Extras", name))

if build_package:
print(f"> Building {name}")
shutil.make_archive(extra_path, "zip", os.path.join(BUILD_PATH, "Extras", name))
print(f"> Built {extra_path}")

def collect_dependencies(dep_data):
"""
Finds and downloads all the mod's dependencies
Inputs:
dep_data (dict): dictionart of dependecies from build_data.json
"""
clean_path(TEMP_PATH)
for name, info in dep_data.items():
download_dependency(name, info, TEMP_PATH, BUILD_PATH)
cleanup()

def cleanup():
"""
Cleans up the trailing files in the main directory for packaging by excluding all expect the
specified items in VALID_FILES
"""
onlyfiles = [f for f in os.listdir(BUILD_PATH) if os.path.isfile(os.path.join(BUILD_PATH, f))]
for f in onlyfiles:
if f not in VALID_FILES:
os.remove(os.path.join(BUILD_PATH,f))

def bundle(core_release, extras_release, complete_release):
"""
Compiles and builds the set of release packages according to information from
the .version file and the build_data.json file
"""
# Collect build information
build_data = get_build_data()
version_data = get_version_file_info(build_data["mod_name"])

print(f"Building {build_data['mod_name']} version {get_version(version_data)}\n=================")

# Clean/recreate the build, deploy and temp paths
clean_path(os.path.join(BUILD_PATH))
clean_path(os.path.join(DEPLOY_PATH))
clean_path(os.path.join(TEMP_PATH))

# Copy main mod content
print(f"Compiling core mod content")
shutil.copytree(os.path.join("GameData", build_data["mod_name"]), os.path.join(BUILD_PATH, "GameData", build_data["mod_name"]))
shutil.copy("changelog.txt", os.path.join(BUILD_PATH, "changelog.txt"))
shutil.copy("readme.txt", os.path.join(BUILD_PATH, "readme.txt"))

if core_release:
print(f"Building BASIC release package")
build_nodep_release(version_data, build_data['mod_name'])

if os.path.exists("Extras"):
print(f"Compiling and building EXTRAS release packages")
build_extras(version_data, extras_release)

print(f"Compiling complete release package")
print(f"> Collecting dependencies")
collect_dependencies(build_data["dependencies"])

if complete_release:
print(f"Building COMPLETE release package")
build_full_release(version_data, build_data['mod_name'])

# Write the version/changelog out in text for Travis deploy scripts to take advantage of as env variables set are not persisted
with open(os.path.join("build_scripts", 'version.txt'), "w") as f:
f.write(get_version(version_data))

with open(os.path.join("build_scripts", 'changelog.md'), "w") as f:
f.write(get_changelog())

if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("-c", "--complete",
action="store_true", default=True,
help="write complete package")
parser.add_argument("-e", "--extras",
action="store_true", default=False,
help="write extras package")
parser.add_argument("-b", "--basic",
action="store_true", default=False,
help="write basic no dependency package")

args = parser.parse_args()

bundle(args.basic, args.extras, args.complete)
6 changes: 6 additions & 0 deletions build_scripts/build_data.json
@@ -0,0 +1,6 @@
{
"mod_name": "NearFutureProps",
"dependencies":
{
}
}
Empty file.
73 changes: 73 additions & 0 deletions build_scripts/build_support/build_helpers.py
@@ -0,0 +1,73 @@
# Useful functions for build scripts
import os
import json
import stat

BUILD_SCRIPT_PATH = "build_scripts"
BUILD_DATA_NAME = "build_data.json"
CHANGELOG_PATH = "changelog.txt"

class tcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

def get_version(version_data):
"""Returns a formatted version string from the version data dictionary"""
return "{MAJOR}.{MINOR}.{PATCH}".format(**version_data["VERSION"])

def get_ksp_version(version_data):
"""Returns a formatted KSP version string from the version data dictionary"""
return "{MAJOR}.{MINOR}.{PATCH}".format(**version_data["KSP_VERSION"])

def get_version_file_info(mod_name):
"""Extracts version info from the .version file"""
version_path = os.path.join("GameData", mod_name, "Versioning", f"{mod_name}.version")
with open(version_path, "r") as f:
version_data = json.load(f)
return version_data

def get_build_data():
"""Loads the information from the build data file"""
build_data_path = os.path.join(BUILD_SCRIPT_PATH, BUILD_DATA_NAME)
with open(build_data_path, "r") as f:
build_data = json.load(f)
return build_data

def ensure_path(path):
"""Ensure a path exists, make it if not"""
if os.path.exists(path):
return
else:
os.makedirs(path)

def clean_path(path):
"""Creates a clean copy of a path if it exists"""
if os.path.exists(path):
for root, dirs, files in os.walk(path, topdown=False):
for name in files:
filename = os.path.join(root, name)
os.chmod(filename, stat.S_IWUSR)
os.remove(filename)
for name in dirs:
os.rmdir(os.path.join(root, name))
else:
os.makedirs(path)

def get_changelog():
"""Extracts a markdown formatted version of the latest changelog.txt entry"""
log_lines = []
with open(CHANGELOG_PATH, "r") as f:
for idx, line in enumerate(f):
if line.startswith("---") or line.startswith("v"):
pass
else:
log_lines.append(line.replace("- ", "* "))
if idx > 1 and line == "\n":
break
return "".join(log_lines)

0 comments on commit fc93579

Please sign in to comment.