From 9c52e7a2e9f621bd1d784a7ab59151add5bdc58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 10:13:29 +0100 Subject: [PATCH 01/10] Updated the outdated README.md --- .github/README.md | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/README.md b/.github/README.md index bce34586..98dcc989 100644 --- a/.github/README.md +++ b/.github/README.md @@ -11,9 +11,9 @@ [Documentation](https://docs.spacewarp.org) -Space Warp is a mod loader for Kerbal Space Program 2. +Space Warp is a modding API for Kerbal Space Program 2 with support for BepInEx and the official mod loader.* -Note: Use at your own risk, as this is an early version that is expected to undergo many changes. +*\*Note: The official mod loader is unfinished, so BepInEx is currently still required to enable it.* ## Installation @@ -41,11 +41,19 @@ That should be it, you can now launch the game and enjoy! To compile this project, you will need to follow these steps: -1. Install NuGet +1. Install .NET 7+ SDK 2. Run `dotnet restore` inside the top directory to install the packages. -3. Run one of the build scripts (see below for more info) and copy the contents from the correct build output directory into the KSP2 root director +3. Run `dotnet build -c ` to build the project, where `` is one of the following: + - `Debug` - Builds the project in debug mode + - `Deploy` - Builds the project in debug mode and copies the output to the KSP2 directory + - `DeployAndRun` - Builds the project in debug mode, copies the output to the KSP2 directory, and runs the game + - `Release` - Builds the project in release mode, zips the output, and builds a NuGet package -Mods are currently implemented as monobehaviours with two fields: a `Logger` for logging and a `Manager` that points to Spacewarp. A mod template generator exists as a Python script. +or you can use Visual Studio 2022 or JetBrains Rider to build the project. + +There are also scripts in the `scripts` folder that can be used to build the project in each of the configurations, they simply run the `dotnet build` command with the correct arguments. + +The outputs can be found in `dist/`. The Release zip will be in the `dist` folder, and the NuGet package will be in the `nuget` folder. ## Mod Structure @@ -63,23 +71,12 @@ KSP2_Root_Folder/ │ │ │ │ │ ├── *.bundle │ │ │ │ ├── images/ │ │ │ │ │ ├── * +│ │ │ │ ├── soundbanks/ +│ │ │ │ │ ├── *.bnk │ │ │ ├── localizations/ │ │ │ │ ├── *.csv │ │ │ ├── addressables/ │ │ │ │ ├── catalog.json │ │ │ │ ├── * │ │ │ ├── *.dll -``` - -## Build Scripts - -Each build scripts is essentially just a wrapper around `python3 builder.py $@`. The actual builder code is in `builder.py`. -Before running, open a terminal and `cd` into the repo, then run `pip install -r requirements.txt` to install the required dependencies (its just `argparse`). - -The build scripts are: -`build.bat` for Windows, `build.ps1` for Windows (Powershell), and `build.sh` for Linux - -The available arguments are: -- `-r` or `--release` to build in release mode - -When building, the build output will be in `build/SpaceWarp`, and the compressed version will be `build/SpaceWarp-[Debug|Release]-[commit].zip`. +``` \ No newline at end of file From cf5e9551efedcf222b54c0378d6baf363498ca59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 10:26:26 +0100 Subject: [PATCH 02/10] Attempt #2 to fix GH Action building of release zip --- src/SpaceWarp/Directory.Build.targets | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SpaceWarp/Directory.Build.targets b/src/SpaceWarp/Directory.Build.targets index 61d752c9..ac0160e5 100644 --- a/src/SpaceWarp/Directory.Build.targets +++ b/src/SpaceWarp/Directory.Build.targets @@ -78,8 +78,12 @@ - + + + From bdd9bab2d7f4c65bcd38c86c3c0c2bbfefaf498f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 11:09:24 +0100 Subject: [PATCH 03/10] Realized it doesn't make much sense to build in Debug configuration if we're not doing anything with the results --- .github/workflows/build_spacewarp.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/build_spacewarp.yml b/.github/workflows/build_spacewarp.yml index 421f9c16..dfc3e3c8 100644 --- a/.github/workflows/build_spacewarp.yml +++ b/.github/workflows/build_spacewarp.yml @@ -7,16 +7,6 @@ on: branches: [ "main", "dev" ] jobs: - build-debug: - runs-on: ubuntu-latest - - steps: - - name: Check Out Repository - uses: actions/checkout@v3 - - - name: Build the solution - run: dotnet build "SpaceWarp.sln" -c Debug - build-release: runs-on: ubuntu-latest From 44e1cde3d277e731c49623d1dbdd45ce960bd6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 11:10:04 +0100 Subject: [PATCH 04/10] Add actions to upload NuGet package as artifact --- .github/workflows/build_spacewarp.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_spacewarp.yml b/.github/workflows/build_spacewarp.yml index dfc3e3c8..83d31046 100644 --- a/.github/workflows/build_spacewarp.yml +++ b/.github/workflows/build_spacewarp.yml @@ -7,24 +7,36 @@ on: branches: [ "main", "dev" ] jobs: - build-release: + build: runs-on: ubuntu-latest steps: - - name: Check Out Repository + - name: Check out repository uses: actions/checkout@v3 - + - name: Build the solution run: dotnet build "SpaceWarp.sln" -c Release - - - name: Find Zip + + - name: Find zip id: find-zip run: | echo "zip=$(ls -1 dist/SpaceWarp-*.zip | head -n 1)" >> $GITHUB_ENV echo "artifact_name=SpaceWarpRelease" >> $GITHUB_ENV - - name: Upload Artifact + - name: Upload release zip uses: actions/upload-artifact@v3 with: name: ${{ env.artifact_name }} path: ${{ env.zip }} + + - name: Find NuGet package + id: find-nupkg + run: | + echo "nupkg=$(ls -1 nuget/SpaceWarp.*.nupkg | head -n 1)" >> $GITHUB_ENV + echo "artifact_name=SpaceWarpNuGet" >> $GITHUB_ENV + + - name: Upload NuGet package + uses: actions/upload-artifact@v3 + with: + name: ${{ env.artifact_name }} + path: ${{ env.nupkg }} From 4bbb92c4486258c7a7858f68cac301e7af4eab4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 11:41:16 +0100 Subject: [PATCH 05/10] Automatic publishing of NuGet package on release --- .github/workflows/release_nuget.yml | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/release_nuget.yml diff --git a/.github/workflows/release_nuget.yml b/.github/workflows/release_nuget.yml new file mode 100644 index 00000000..b5df2ce6 --- /dev/null +++ b/.github/workflows/release_nuget.yml @@ -0,0 +1,46 @@ +name: Publish NuGet Package + +on: + release: + types: [ "published" ] + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Install jq + uses: dcarbone/install-jq-action@v2.1.0 + + - name: Build the solution + run: dotnet build "SpaceWarp.sln" -c Release + + - name: Extract current version + id: get-version + run: | + version=$(jq -r '.version' plugin_template/BepInEx/plugins/SpaceWarp/swinfo.json) + echo "Version is $version" + echo "::set-output name=version::$version" + + - name: Check if version exists + id: check-version + run: | + version=${{ steps.get-version.outputs.version }} + response=$(curl -s "https://nuget.spacewarp.org/v3/search?q=SpaceWarp") + exists=$(echo "$response" | jq -r --arg id "SpaceWarp" --arg version "$version" '.data[] | select(.id == $id) | .versions[] | select(.version == $version) | .version') + if [ "$exists" == "$version" ]; then + echo "Version $version already exists in the NuGet repository" + exit 1 + else + echo "Version $version does not exist in the NuGet repository" + echo "::set-output name=should_publish::true" + fi + + - name: Publish NuGet package + if: steps.check-version.outputs.should_publish == 'true' + run: | + nupkg_path=$(ls -1 nuget/SpaceWarp.*.nupkg | head -n 1) + dotnet nuget push "$nupkg_path" -s https://nuget.spacewarp.org/v3/index.json -k ${{ secrets.NUGET_SERVER_KEY }} \ No newline at end of file From e53c994a6b5ecbe8fd0c686653ca50fba54dbea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 12:35:09 +0100 Subject: [PATCH 06/10] Remove duplicate reference --- src/SpaceWarp.Game/SpaceWarp.Game.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SpaceWarp.Game/SpaceWarp.Game.csproj b/src/SpaceWarp.Game/SpaceWarp.Game.csproj index 78c4f151..d90289f6 100644 --- a/src/SpaceWarp.Game/SpaceWarp.Game.csproj +++ b/src/SpaceWarp.Game/SpaceWarp.Game.csproj @@ -2,7 +2,6 @@ - From 9017362ed89921e2711b59feec0d52845e8cac8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 12:35:30 +0100 Subject: [PATCH 07/10] NuGet packing with Mono and nuget.exe --- .github/workflows/build_spacewarp.yml | 14 ++++++++++++++ .github/workflows/release_nuget.yml | 14 ++++++++++++++ src/SpaceWarp/Directory.Build.targets | 6 +++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_spacewarp.yml b/.github/workflows/build_spacewarp.yml index 83d31046..c3d04929 100644 --- a/.github/workflows/build_spacewarp.yml +++ b/.github/workflows/build_spacewarp.yml @@ -14,6 +14,20 @@ jobs: - name: Check out repository uses: actions/checkout@v3 + - name: Install Mono + id: install-mono + run: | + apt-get install ca-certificates gnupg + 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 + apt-get update + apt install mono-devel -y + + - name: Download NuGet + id: download-nuget + run: | + curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + - name: Build the solution run: dotnet build "SpaceWarp.sln" -c Release diff --git a/.github/workflows/release_nuget.yml b/.github/workflows/release_nuget.yml index b5df2ce6..339d57c7 100644 --- a/.github/workflows/release_nuget.yml +++ b/.github/workflows/release_nuget.yml @@ -15,6 +15,20 @@ jobs: - name: Install jq uses: dcarbone/install-jq-action@v2.1.0 + - name: Install Mono + id: install-mono + run: | + apt-get install ca-certificates gnupg + 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 + apt-get update + apt install mono-devel -y + + - name: Download NuGet + id: download-nuget + run: | + curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + - name: Build the solution run: dotnet build "SpaceWarp.sln" -c Release diff --git a/src/SpaceWarp/Directory.Build.targets b/src/SpaceWarp/Directory.Build.targets index ac0160e5..6c8a1ef0 100644 --- a/src/SpaceWarp/Directory.Build.targets +++ b/src/SpaceWarp/Directory.Build.targets @@ -1,5 +1,9 @@ + + nuget + mono /usr/local/bin/nuget.exe + @@ -109,7 +113,7 @@ + Command="$(NuGetExecutable) pack "$(SolutionDir)/Package.nuspec" -OutputDirectory "$(SolutionDir)/nuget" -Properties "NoWarn=NU5125;id=$(ProjectName);version=$(Version);authors=$(Authors);description=$(Description);repositoryType=$(RepositoryType);repositoryUrl=$(RepositoryUrl)"" /> Date: Fri, 22 Dec 2023 12:38:58 +0100 Subject: [PATCH 08/10] sudo you dummy --- .github/workflows/release_nuget.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release_nuget.yml b/.github/workflows/release_nuget.yml index 339d57c7..700224a8 100644 --- a/.github/workflows/release_nuget.yml +++ b/.github/workflows/release_nuget.yml @@ -18,16 +18,16 @@ jobs: - name: Install Mono id: install-mono run: | - apt-get install ca-certificates gnupg - 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 - apt-get update - apt install mono-devel -y + sudo apt-get install ca-certificates gnupg + sudo 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" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list + sudo apt-get update + sudo apt-get install mono-devel -y - name: Download NuGet id: download-nuget run: | - curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - name: Build the solution run: dotnet build "SpaceWarp.sln" -c Release From 452cf050df86e6b29e88e77abd499e7013a6922f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 12:40:30 +0100 Subject: [PATCH 09/10] sudo in *both* actions, stupid --- .github/workflows/build_spacewarp.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_spacewarp.yml b/.github/workflows/build_spacewarp.yml index c3d04929..feb73114 100644 --- a/.github/workflows/build_spacewarp.yml +++ b/.github/workflows/build_spacewarp.yml @@ -17,16 +17,16 @@ jobs: - name: Install Mono id: install-mono run: | - apt-get install ca-certificates gnupg - 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 - apt-get update - apt install mono-devel -y + sudo apt-get install ca-certificates gnupg + sudo 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" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list + sudo apt-get update + sudo apt-get install mono-devel -y - name: Download NuGet id: download-nuget run: | - curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - name: Build the solution run: dotnet build "SpaceWarp.sln" -c Release From 01bbc1a713a7be1c56339704fd1fbb7a16577135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bure=C5=A1?= Date: Fri, 22 Dec 2023 12:45:11 +0100 Subject: [PATCH 10/10] Remove mono installation, it's preinstalled in the runner image --- .github/workflows/build_spacewarp.yml | 9 --------- .github/workflows/release_nuget.yml | 9 --------- 2 files changed, 18 deletions(-) diff --git a/.github/workflows/build_spacewarp.yml b/.github/workflows/build_spacewarp.yml index feb73114..78309260 100644 --- a/.github/workflows/build_spacewarp.yml +++ b/.github/workflows/build_spacewarp.yml @@ -14,15 +14,6 @@ jobs: - name: Check out repository uses: actions/checkout@v3 - - name: Install Mono - id: install-mono - run: | - sudo apt-get install ca-certificates gnupg - sudo 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" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list - sudo apt-get update - sudo apt-get install mono-devel -y - - name: Download NuGet id: download-nuget run: | diff --git a/.github/workflows/release_nuget.yml b/.github/workflows/release_nuget.yml index 700224a8..11a70575 100644 --- a/.github/workflows/release_nuget.yml +++ b/.github/workflows/release_nuget.yml @@ -15,15 +15,6 @@ jobs: - name: Install jq uses: dcarbone/install-jq-action@v2.1.0 - - name: Install Mono - id: install-mono - run: | - sudo apt-get install ca-certificates gnupg - sudo 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" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list - sudo apt-get update - sudo apt-get install mono-devel -y - - name: Download NuGet id: download-nuget run: |