diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9bc6a78 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Documents +*.gitattributes text +*.gitignore text +*.md text + +# Build files +Dockerfile text eol=lf diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..daef618 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,32 @@ +name: Deploy Mod Installer + +on: + push: + branches: + - main + workflow_dispatch: + repository_dispatch: + types: + - deploy + +jobs: + deploy: + name: Build and deploy + runs-on: ubuntu-latest + steps: + + - name: Install Docker + run: | + curl -fsSL https://get.docker.com -o get-docker.sh + sh get-docker.sh + + - name: Build Docker image + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + if: ${{ env.DOCKERHUB_USERNAME && env.DOCKERHUB_PASSWORD }} + run: | + echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + docker build -t kspckan/mod-installer . + docker tag kspckan/mod-installer kspckan/mod-installer:latest + docker push kspckan/mod-installer:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..66ee517 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:latest +ENV DEBIAN_FRONTEND noninteractive + +# Install build dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + curl ca-certificates gpg dirmngr gpg-agent jq + +# Set up Mono's APT repo +RUN gpg --homedir /tmp --no-default-keyring --keyring /usr/share/keyrings/mono-official-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \ + && echo "deb [signed-by=/usr/share/keyrings/mono-official-archive-keyring.gpg] https://download.mono-project.com/repo/ubuntu stable-focal main" | tee /etc/apt/sources.list.d/mono-official-stable.list + +# Set up CKAN's APT repo +RUN curl -sS -o /usr/share/keyrings/ksp-ckan-archive-keyring.gpg https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/debian/ksp-ckan.gpg \ + && echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/ksp-ckan-archive-keyring.gpg] https://ksp-ckan.s3-us-west-2.amazonaws.com/deb nightly main' | tee /etc/apt/sources.list.d/ksp-ckan.list + +# Install the necessary pieces of Mono and CKAN +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + mono-runtime ca-certificates-mono libmono-microsoft-csharp4.0-cil libmono-system-data4.0-cil libmono-system-runtime-serialization4.0-cil libmono-system-transactions4.0-cil libmono-system-net-http-webrequest4.0-cil \ + ckan + +# Purge APT download cache, package lists, and logs +RUN apt-get clean \ + && rm -r /var/lib/apt/lists /var/log/dpkg.log /var/log/apt + +RUN curl -sf -o ksp-builds.json https://raw.githubusercontent.com/KSP-CKAN/CKAN-meta/master/builds.json +RUN curl -sf -o ksp2-builds.json https://raw.githubusercontent.com/KSP-CKAN/KSP2-CKAN-meta/main/builds.json + +ADD mod-installer.sh /usr/local/bin/. + +ENTRYPOINT ["/usr/local/bin/mod-installer.sh"] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0dac1ed --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,15 @@ +You can use the CKAN and its associated files under the MIT license, +reproduced below. This includes the right to sublicense under compatible +licenses, including (but not limited to) creative commons, GPL, and LGPL +licenses. + +--- + +Copyright the Comprehensive Kerbal Archive Network (CKAN) Authors. +https://github.com/KSP-CKAN/CKAN/graphs/contributors + +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/README.md b/README.md new file mode 100644 index 0000000..724f19e --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# CKAN Mod Installer GitHub Action + +GitHub action that uses CKAN to install mods for building other mods. + +## Usage + +Adding a step like this to your build workflow will create a fake game instance at `.game`, with the requested mods installed inside it: + +```yml +jobs: + Build: + runs-on: ubuntu-latest + steps: + - name: Install mod dependencies + uses: KSP-CKAN/CKAN-ModInstaller@main + with: + output path: .game + game: KSP + game versions: 1.12.5 1.10 1.11 1.12 + mods: ProceduralParts +``` + +See [action.yml](action.yml) for full documentation. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..4773f5b --- /dev/null +++ b/action.yml @@ -0,0 +1,39 @@ +name: CKAN Mod Installer +description: Installs mods for use as build dependencies +author: + - HebaruSan + +inputs: + + output path: + description: |- + Where to put the generated game instance. + required: true + + mods: + description: |- + Descriptors of mods to install. + Either simple identifier or identifier=version. + required: true + + install filters: + description: |- + Substrings of file names to skip installing to save space and time. + required: false + default: .dds .png .bmp .mu .mbm .jpg .wav + + game: + description: |- + Short name of the game for which to install mods, either KSP or KSP2. + required: false + default: KSP + + game versions: + description: |- + Game versions to mark as compatible. + First version is used as the installed version and must be a full version rather than a glob. + required: true + +run: + using: docker + image: docker://kspckan/mod-installer diff --git a/mod-installer.sh b/mod-installer.sh new file mode 100644 index 0000000..9951f98 --- /dev/null +++ b/mod-installer.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +if [[ -z $INPUT_OUTPUT_PATH ]] +then + echo 'Input parameter "output path" is required to specify path of the game instance' + exit 2 +fi + +if [[ -z $INPUT_MODS ]] +then + echo 'Input parameter "mods" is required to specify identifiers of mods to install' + exit 2 +fi + +GAME=${INPUT_GAME:-KSP} +MAIN_GAME_VERSION=${INPUT_GAME_VERSIONS%% *} +OTHER_GAME_VERSIONS=${INPUT_GAME_VERSIONS#* } + +if [[ -z $MAIN_GAME_VERSION ]] +then + case $GAME in + + KSP) + MAIN_GAME_VERSION=$(jq -rM 'last(.builds[])' /ksp-builds.json) + ;; + + KSP2) + MAIN_GAME_VERSION=$(jq -rM last /ksp2-builds.json) + ;; + + *) + echo 'Input parameter "game" is invalid' + exit 2 + ;; + esac +fi + +COMPAT_COMMAND='' +if [[ -n $OTHER_GAME_VERSIONS ]] +then + COMPAT_COMMAND="compat add $OTHER_GAME_VERSIONS" +fi + +FILTER_COMMAND='' +if [[ -n $INPUT_INSTALL_FILTERS ]] +then + FILTER_COMMAND="filter add --global $INPUT_INSTALL_FILTERS" +fi + +# Need quoting in case the path has spaces +ckan instance fake fake_inst "$INPUT_OUTPUT_PATH" $MAIN_GAME_VERSION --game $GAME --set-default + +# Group the remaining commands into one to reduce startup/teardown overhead +ckan prompt --headless <