From 74aba82f93a02ffb30973c371b7f387950e7680b Mon Sep 17 00:00:00 2001 From: ChrisAdderley Date: Wed, 16 Jan 2019 15:26:45 -0800 Subject: [PATCH] Add build scripts --- .gitattributes | 23 +-- .gitignore | 9 + .travis.yml | 59 +++++++ .../Versioning/NearFuturePropulsion.version | 8 +- README.md | 69 ++++++++ build_scripts/build.py | 159 ++++++++++++++++++ build_scripts/build_data.json | 36 ++++ build_scripts/build_support/__init__.py | 0 build_scripts/build_support/build_helpers.py | 73 ++++++++ build_scripts/build_support/curseforge.py | 113 +++++++++++++ build_scripts/build_support/dependencies.py | 67 ++++++++ build_scripts/build_support/s3.py | 21 +++ build_scripts/build_support/spacedock.py | 104 ++++++++++++ build_scripts/deploy.py | 84 +++++++++ changelog.txt | 7 + readme.txt | 21 ++- 16 files changed, 819 insertions(+), 34 deletions(-) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 build_scripts/build.py create mode 100644 build_scripts/build_data.json create mode 100644 build_scripts/build_support/__init__.py create mode 100644 build_scripts/build_support/build_helpers.py create mode 100644 build_scripts/build_support/curseforge.py create mode 100644 build_scripts/build_support/dependencies.py create mode 100644 build_scripts/build_support/s3.py create mode 100644 build_scripts/build_support/spacedock.py create mode 100644 build_scripts/deploy.py diff --git a/.gitattributes b/.gitattributes index 412eeda..7ff990a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,22 +1 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +build_scripts/* linguist-vendored diff --git a/.gitignore b/.gitignore index fc690e2..785db6d 100644 --- a/.gitignore +++ b/.gitignore @@ -212,3 +212,12 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +# Specific items for packaging scripts +*.pyc +.idea/ +build/ +tmp/ +deploy/ +build_scripts/version.txt +build_scripts/changelog.md diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..64474b3 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,59 @@ +language: python +python: + - 3.6 +install: + - pip install awscli boto3 requests requests_toolbelt +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: script + script: python build_scripts/deploy.py --curse + skip_cleanup: true + on: + condition: $TRAVIS_BRANCH = master + - provider: script + script: python build_scripts/deploy.py --spacedock + skip_cleanup: true + on: + condition: $TRAVIS_BRANCH = master + - 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-propulsion + 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 diff --git a/GameData/NearFuturePropulsion/Versioning/NearFuturePropulsion.version b/GameData/NearFuturePropulsion/Versioning/NearFuturePropulsion.version index cbc0b82..70568f4 100644 --- a/GameData/NearFuturePropulsion/Versioning/NearFuturePropulsion.version +++ b/GameData/NearFuturePropulsion/Versioning/NearFuturePropulsion.version @@ -6,23 +6,23 @@ { "MAJOR":1, "MINOR":0, - "PATCH":4, + "PATCH":5, "BUILD":0 }, "KSP_VERSION": { "MAJOR":1, - "MINOR":5, + "MINOR":6, "PATCH":0 }, "KSP_VERSION_MIN":{ "MAJOR":1, - "MINOR":5, + "MINOR":6, "PATCH":0 }, "KSP_VERSION_MAX":{ "MAJOR":1, - "MINOR":5, + "MINOR":6, "PATCH":99 } } diff --git a/README.md b/README.md new file mode 100644 index 0000000..885e1e7 --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# Near Future Propulsion + +A mod pack for Kerbal Space Program, delivering fancy electic propulsion solutions for your Kerbals. + +* [Features](#features) +* [Dependencies](#dependencies) +* [Installation](#installation) +* [Optional Patches](#optional-patches) +* [External Compatibility](#features) +* [Contributing](#contributing) + +## Features + +A number of electric propulsion parts designed off real technology and prototypes. + +* **Gridded Ion Engines:** Like the stock Dawn, they have low TWR and great Isp. They run on Xenon fuel. +* **Hall Effect Thrusters:** Similar to Gridded thrusters, but with better TWR at the cost of some Isp. They run on Argon fuel and are pretty cheap! +* **Magnetoplasmadynamic Thrusters:** With the best TWR of all electric engines, these engines are very power-hungry. They run on Lithium fuel. +* **Pulsed Inductive Thrusters:** Similar to Hall thrusters, they run on Argon fuel and have the unique ability to dump extra electricity into the engine, increasing Isp but generating more heat. +* **VASIMR Engines:** High tech and fancy, these engines run on either Xenon or Argon fuel. They can be tuned for high-thrust, low Isp operation, or low-thrust, high-Isp operation +* **Electric RCS:** Available in several flavours - a mini gridded thruster, mini Hall thruster, disposable PPT and set of small magnetoplasmadynamic thruster blocks +* **New Tanks**: More Xenon tanks and full tank sets for Argon and Lithium fuels + +## Dependencies + +### Required +These components are required for the mod to function and are bundled as part of any download: +* [ModuleManager (3.1.3)](https://github.com/sarbian/ModuleManager) +* [B9PartSwitch (2.6.0)](https://github.com/blowfishpro/B9PartSwitch) +* [Community Resource Pack (1.0.0)](https://github.com/BobPalmer/CommunityResourcePack) + +## Installation + +To install, place the GameData folder inside your Kerbal Space Program folder. If asked to overwrite files, please do so. + +NOTE: Do NOT rename or move folders within the GameData folder - this mod uses absolute paths to assets and will break if this happens. + +## Optional Patches + +Some extra patches are bundled that you can use to tweak your installation. To install them, drop the correct folder from the **Extras** folder into your KSP GameData Folder + +* **XenonHallThrusters**: Converts the Argon fuelled HETs into Xenon fuelled versions with no changes in stats (but changes in FX) + +## External Mod Compatibility + +This mod includes compatibility patches for the following mods: +* [KSP-AVC](https://github.com/CYBUTEK/KSPAddonVersionChecker): Provides version checking +* [Community Tech Tree](https://github.com/ChrisAdderley/CommunityTechTree): Provides an expanded, community-sourced technology tree for modders to use +* CryoTanks: installed, a new set of LH2-powered MPDT RCS thrusters are added + +## Contributing + +I certainly accept pull requests. Please target all such things to the `dev` branch though! + +## Licensing + +The art assets in this pack (all .dds, .png and .mu files) are distributed under an All Rights Reserved license. You may not redistribute or re-use these assets without express permission from the author. + +Any bundled mods are distributed under their own licenses: +* ModuleManager by ialdabaoth and sarbian is distributed under a Creative Commons Sharealike license. More details, including source code, can be found [here](http://forum.kerbalspaceprogram.com/threads/31342-0-20-ModuleManager-1-3-for-all-your-stock-modding-needs?p=528607&viewfull=1#post528607) +* [Community Tech Tree](https://github.com/ChrisAdderley/CommunityTechTree): Provides an expanded, community-sourced technology tree for modders to use +* B9PartSwitch by blowfish is also distributed under its own license. Please find source and more details [here](https://github.com/blowfishpro/B9PartSwitch) + +Everything else is distributed under the MIT license. + +Copyright (c) 2019 Chris Adderley +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/build_scripts/build.py b/build_scripts/build.py new file mode 100644 index 0000000..58d7643 --- /dev/null +++ b/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) diff --git a/build_scripts/build_data.json b/build_scripts/build_data.json new file mode 100644 index 0000000..4cf1568 --- /dev/null +++ b/build_scripts/build_data.json @@ -0,0 +1,36 @@ +{ + "mod_name": "NearFuturePropulsion", + "dependencies": + { + "B9PartSwitch": + { + "version": "2.6.0", + "location": "s3" + }, + "ModuleManager": + { + "version": "3.1.3", + "location": "s3" + }, + "CommunityResourcePack": + { + "version": "1.0.0", + "location": "s3" + }, + "NearFutureProps": + { + "location": "github", + "repository": "ChrisAdderley/NearFutureProps", + "tag": "0.5.0" + } + }, + "spacedock": + { + "mod-id": 557 + }, + "curseforge": + { + "mod-id": 220670 + } + +} diff --git a/build_scripts/build_support/__init__.py b/build_scripts/build_support/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/build_scripts/build_support/build_helpers.py b/build_scripts/build_support/build_helpers.py new file mode 100644 index 0000000..0cbe5a4 --- /dev/null +++ b/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) diff --git a/build_scripts/build_support/curseforge.py b/build_scripts/build_support/curseforge.py new file mode 100644 index 0000000..c6b3ace --- /dev/null +++ b/build_scripts/build_support/curseforge.py @@ -0,0 +1,113 @@ +import requests +from contextlib import closing +from requests_toolbelt.multipart.encoder import MultipartEncoder +import json + +class CurseForgeAPI(object): + + base_url = "https://kerbal.curseforge.com" + versions_url = "api/game/versions" + upload_file_url = "api/projects/{mod_id}/upload-file" + + def __init__(self, token, session=None): + """ + Initializes the API session + + Inputs: + token (str): Curse authentication token + """ + self.auth_token = token + if isinstance(session, requests.Session): + self.session = session + else: + self.session = requests.Session() + + def query_version(self): + """ + Queries the API and returns a list of available game versions + """ + url = f'{self.base_url}/{self.versions_url}' + headers = {'X-Api-Token': self.auth_token} + with closing(self.session.get(url, headers=headers)) as resp: + try: + return resp.json() + except requests.exceptions.HTTPError as err: + print(err) + print(f"{resp.url} returned {resp.text}") + return resp.text + + def get_curse_game_version_id(self, game_version): + """ + Gets the curse version id by querying the API and comparing to the provided + ID + + Inputs: + game_version (str): the string game version to match + Returns: + curse_version (int): the integer curse version + """ + versions = self.query_version() + curse_version = None + for version in versions: + if version["name"] == game_version: + curse_version = version["id"] + print(f"Found curse version {curse_version} from string version {game_version}") + + if curse_version is None: + raise Exception(f"Couldn't determine curse version from game version {game_version}") + + return curse_version + + def update_mod(self, mod_id, changelog, game_version, releaseType, zip): + """ + Updates a mod by hitting the project upload files API + + Inputs: + mod_id (str): the curseforge project ID + changelog (str): a Markdown-formatted changelog + game_version (str): the string game version to use + releaseType (str): One of alpha, beta, release + zip (str): the path of the zip to upload + """ + curse_version = int(self.get_curse_game_version_id(game_version)) + url = f'{self.base_url}/{self.upload_file_url}'.format(mod_id=mod_id) + metadata = { + "changelog": changelog, + "changelogType": "markdown", + "gameVersions": [curse_version], + "releaseType": releaseType + } + print(f"File metadata {metadata}, zip {zip}") + headers = {'X-Api-Token': self.auth_token} + print(f"posting {metadata} to {url}") + try: + resp = self.session.post(url, files={'file': open(zip, 'rb')}, data={'metadata': json.dumps(metadata)}, headers=headers) + resp.raise_for_status() + print(f"{resp.url} returned {resp.text}") + return resp.text + except requests.exceptions.HTTPError as err: + print(f"HTTP ERROR: {err}") + print(f"{resp.url} returned {resp.text}") + return resp.text + + def login(self): + """Unneeded""" + pass + + def logout(self): + """Unneeded""" + pass + + def close(self): + self.session.close() + + def __call__(self, **kwargs): + return self.query(**kwargs) + + def __enter__(self): + self.login() + return self + + def __exit__(self, *args): + self.logout() + self.close() diff --git a/build_scripts/build_support/dependencies.py b/build_scripts/build_support/dependencies.py new file mode 100644 index 0000000..6d21233 --- /dev/null +++ b/build_scripts/build_support/dependencies.py @@ -0,0 +1,67 @@ +import os +import shutil +import zipfile +import zlib +from build_support.build_helpers import * +import build_support.s3 as s3 + +DEPENDENCY_BUCKET = "nertea-ksp-modding-dependencies" + +def download_dependency(name, info, temp_path, build_path): + """ + Downloads a dependency record from either S3 (external dependency) or github (internal dependency) + + Inputs: + name (str): name of the dependency + info (dict): dictionary describing the dependency + temp_path (str): path to store dependency zips to + build_path (str): path to stage to + """ + if info["location"] == "s3": + print(f"> Collecting {name} {info['version']} from S3") + download_dependency_s3(name, info["version"], temp_path, build_path) + + if info["location"] == "github": + print(f"> Collecting {name} {info['tag']} from repository {info['repository']}") + download_dependency_github(name, info['repository'], info["tag"], temp_path, build_path) + +def download_dependency_s3(name, version, temp_path, build_path): + """ + Downloads and unzips a dependency from S3 + + Inputs: + name (str): name of the dependency + version (str): version of the dependency + temp_path (str): path to store dependency zips to + build_path (str): path to stage to + """ + target_name = os.path.join(temp_path, f"{name}_{version}.zip") + print(f"> Pulling s3://{DEPENDENCY_BUCKET}/external/{name}_{version}.zip") + s3.copy(f"s3://{DEPENDENCY_BUCKET}/external/{name}_{version}.zip", + target_name) + + with zipfile.ZipFile(target_name, "r") as z: + z.extractall(build_path) + +def download_dependency_github(name, repo, tag, temp_path, build_path): + """ + Downloads a github repo with a specific tag + + Inputs: + name (str): name of the dependency + repo (str): Account/RepoName + tag (str): version of the dependency (tagged in the repo) + temp_path (str): path to store dependency zips to + build_path (str): path to stage to + """ + wp = os.getcwd() + os.chdir(temp_path) + # Clone into the repo, pull the specified tag + clone_cmd = f"git clone https://github.com/{repo}.git" + tag_cmd = f"git checkout master && git fetch && git fetch --tags && git checkout {tag}" + os.system(clone_cmd) + os.chdir(name) + os.system(tag_cmd) + os.chdir(wp) + # Move the contents of GameData into the build directory + shutil.copytree(os.path.join(temp_path, name, "GameData", name), os.path.join(build_path, "GameData", name)) diff --git a/build_scripts/build_support/s3.py b/build_scripts/build_support/s3.py new file mode 100644 index 0000000..93a9572 --- /dev/null +++ b/build_scripts/build_support/s3.py @@ -0,0 +1,21 @@ +# Useful functions for working with Amazon S3 +import boto3 +import botocore +from urllib.parse import urlparse + +def copy(src, dest): + """ + Copies a file to or from s3. If a link starts with s3: it will be treated + as an S3 path. Uses local AWS keys to do this + + Inputs: + src (str): url of source file + dest (str): url of destination file + """ + s3 = boto3.client('s3', verify=False) + if src.startswith("s3"): + url_parsed = urlparse(src) + s3.download_file(url_parsed.netloc, url_parsed.path[1:], dest) + if dest.startswith("s3"): + url_parsed = urlparse(dest) + s3.upload_file(src, url_parsed.netloc, url_parsed.path) diff --git a/build_scripts/build_support/spacedock.py b/build_scripts/build_support/spacedock.py new file mode 100644 index 0000000..ba47f49 --- /dev/null +++ b/build_scripts/build_support/spacedock.py @@ -0,0 +1,104 @@ +# Class for accessing the SpaceDock API +import requests +from contextlib import closing +from requests_toolbelt.multipart.encoder import MultipartEncoder + +class SpaceDockAPI(object): + + base_url = "https://spacedock.info" + login_url = "api/login" + query_mod_url = "api/mod/{mod_id}" + update_mod_url = "api/mod/{mod_id}/update" + + def __init__(self, login, password, session=None): + """ + Initializes the API session + + Inputs: + login (str): SpaceDock user + password (str): Spacedock PW + """ + self.credentials = {"username":login, "password":password} + self.password = password + if isinstance(session, requests.Session): + self.session = session + else: + self.session =requests.Session() + + def query_mod(self, mod_id): + """ + Queries the API for a mod + + Inputs: + mod_id (str): SpaceDock mod ID + + Returns: + response (str): The query result + """ + url = f'{self.base_url}/{self.query_mod_url}' + print(f"> Getting {url}") + with closing(self.session.get(url)) as resp: + try: + m = getattr(resp, "json") + return m() if callable(m) else m + except requests.exceptions.HTTPError as err: + print(err) + return resp.text + + def update_mod(self, mod_id, version, changelog, game_version, notify_followers, zip): + """ + Submits an update to a mod + + Inputs: + mod_id (str): the Spacedock mod ID + version (str): the string mod version to use + changelog (str): a Markdown-formatted changelog + game_version (str): the string game version to use + notify_followers (bool): email followers + zip (str): the path of the zip to upload + + """ + url = f'{self.base_url}/{self.update_mod_url}'.format(mod_id=mod_id) + payload = { + "version": version, + "changelog": changelog, + "game-version": game_version, + "notify-followers": "yes" if True else "no" + } + print(f"> Posting {payload} to {url}") + + try: + resp = self.session.post(url, data=payload, files={'zipball': open(zip, 'rb')}) + resp.raise_for_status() + print(f"{resp.url} returned {resp.text}") + return resp.text + except requests.exceptions.HTTPError as err: + print(f"HTTP ERROR: {err}") + print(f"{resp.url} returned {resp.text}") + return resp.text + + + def login(self): + with closing(self.session.post(f'{self.base_url}/{self.login_url}', data=self.credentials)) as resp: + if resp.reason == 'OK': + print('"Successfully logged in"') + return self.session + else: + print(resp.text) + + def logout(self): + pass + + def close(self): + self.session.close() + + def __call__(self, **kwargs): + return self.query(**kwargs) + + def __enter__(self): + self.login() + return self + + def __exit__(self, *args): + self.logout() + self.close() diff --git a/build_scripts/deploy.py b/build_scripts/deploy.py new file mode 100644 index 0000000..6a3b914 --- /dev/null +++ b/build_scripts/deploy.py @@ -0,0 +1,84 @@ +# Deploy script entrypoint +import os +import shutil +import zipfile +import zlib +from argparse import ArgumentParser + +from build_support.build_helpers import * +from build_support.spacedock import SpaceDockAPI +from build_support.curseforge import CurseForgeAPI + + +def deploy(spacedock, curse): + """ + Deploys packages to providers + + Inputs: + spacedock (bool): deploy to SpaceDock + curse (bool): deploy to CurseForge + """ + build_data = get_build_data() + version_data = get_version_file_info(build_data["mod_name"]) + changelog = get_changelog() + + print(f"Deploying {build_data['mod_name']} version {get_version(version_data)}\n=================") + print(f"Changes:\n{changelog}") + + print(f"Targets: {'SpaceDock ' if spacedock else ''}{'Curse' if curse else ''}") + zipfile = os.path.join("deploy", f"{build_data['mod_name']}_" + "{MAJOR}_{MINOR}_{PATCH}.zip".format(**version_data["VERSION"])) + print(f"> Deploying file {zipfile}") + if spacedock: + deploy_spacedock( + get_version(version_data), + get_ksp_version(version_data), + build_data['spacedock']['mod-id'], + changelog, + zipfile) + if curse: + deploy_curseforge( + get_ksp_version(version_data), + build_data['curseforge']['mod-id'], + changelog, + zipfile) + +def deploy_curseforge(ksp_version, mod_id, changelog, zipfile): + """ + Performs deployment to CurseForge + + Inputs: + ksp_version (str): version of KSP to target + mod_id (str): CurseForge project ID + changelog (str): Markdown formatted changelog + zipfile (str): path to file to upload + """ + print("> Deploying to CurseForge") + with CurseForgeAPI(os.environ["CURSEFORGE_TOKEN"]) as api: + api.update_mod(mod_id, changelog, ksp_version, "release", zipfile) + +def deploy_spacedock(version, ksp_version, mod_id, changelog, zipfile): + """ + Performs deployment to SpaceDock + + Inputs: + version (str): mod version + ksp_version (str): version of KSP to target + mod_id (str): CurseForge project ID + changelog (str): Markdown formatted changelog + zipfile (str): path to file to upload + """ + print("> Deploying to SpaceDock") + with SpaceDockAPI(os.environ["SPACEDOCK_LOGIN"], os.environ["SPACEDOCK_PASSWORD"]) as api: + api.update_mod(mod_id, version, changelog, ksp_version, True, zipfile) + +if __name__ == "__main__": + parser = ArgumentParser() + parser.add_argument("-c", "--curse", + action="store_true", default=False, + help="deploy to curse") + parser.add_argument("-s", "--spacedock", + action="store_true", default=False, + help="deploy to spacedock") + + args = parser.parse_args() + deploy(args.spacedock, args.curse) diff --git a/changelog.txt b/changelog.txt index 872f630..54eb644 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +v1.0.5 +------ +- KSP 1.6.x +- Updated MM to 3.1.3 +- Updated B9PartSwitch to 2.6.0 +- License change for code and configs to MIT + v1.0.4 ------ - KSP 1.5.0 diff --git a/readme.txt b/readme.txt index b627035..0fe5eb9 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ ================================= -NEAR FUTURE PROPULSION PACK 1.0.4 +NEAR FUTURE PROPULSION PACK 1.0.5 ================================= This pack contains the advanced electric propulsion technologies @@ -12,9 +12,9 @@ DEPENDENCIES ============ Required: -- BP Part Switch (2.4.5) +- BP Part Switch (2.6.0) - Community Resource Pack (1.0.0) -- ModuleManager (3.1.0) +- ModuleManager (3.1.3) Optional - Community Tech Tree (v3.0+) @@ -48,11 +48,16 @@ This mod includes localization support, and includes translations for LICENSING ========= -The cfgs and code in this pack are distributed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-nc-sa/4.0/legalcode). You are free to share and adapt the materials only for non-commercial purposes and when providing appropriate attribution. Any derivatives must be distributed under the same license. -The art assets in this pack (all models and textures) are distributed under an All Rights Reserved License. You may not redistribute or re-use these assets without express permission from me. +The art assets in this pack (all .dds, .png and .mu files) are distributed under an All Rights Reserved license. You may not redistribute or re-use these assets without express permission from the author. -ModuleManager by ialdabaoth and sarbian is distributed under a Creative Commons Sharealike license. More details, including source code, can be found here: http://forum.kerbalspaceprogram.com/threads/31342-0-20-ModuleManager-1-3-for-all-your-stock-modding-needs?p=528607&viewfull=1#post528607 +Any bundled mods are distributed under their own licenses: +- ModuleManager by ialdabaoth and sarbian is distributed under a Creative Commons Sharealike license. More details, including source code, can be found here: http://forum.kerbalspaceprogram.com/threads/31342-0-20-ModuleManager-1-3-for-all-your-stock-modding-needs?p=528607&viewfull=1#post528607 +- The Community Resource Pack by RoverDude is also distributed under its own license. Please find source and more details at https://github.com/BobPalmer/CommunityResourcePack +- B9PartSwitch by blowfish is also distributed under its own license. Please find source and more details at https://github.com/blowfishpro/B9PartSwitch -B9PartSwitch by blowfish is also distributed under its own license. +Everything else is distributed under the MIT license. -The Community Resource Pack by RoverDude is also distributed under its own license +Copyright (c) 2019 Chris Adderley +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.