Skip to content

Commit 3cc894c

Browse files
Refactor with assorted changes (#20)
* GetRequiredExternalTools target Theres annoyingly no way to export environment variables from msbuild which sucks, so actually using this requires a few bonus flags. Right prints an empty string if no CKAN dependencies are included, otherwise prints "CKAN". Allows extensibility for other tools, like possibly requiring the Unity editor * kill KSP_ROOT environment variables already get passed to msbuild, so the "-p" lines in msbuild calls are unnecessary if you just make the variable names the same * action for installing dependencies now checks if CKAN is required * Make some `uses` calls relative just testing really * Use workflows from the git submodule instead of github ok heres the deal: All the references to "@main" means that if the user wants to pin KSPBuildTools to a specific version or commit (perfectly reasonable if theres ever breaking changes), then any sub-action will still call from the main branch. Alternatively we can just use the file directly from the git submodule, which is needed anyways for KSPCommon.props. That way version pinning is done entirely through the git submodule to a specific commit * slightly more portable msbuild calls Some runners (other than the github one) don't bundle the standalone msbuild (part of VS??) but do include dotnet. afaict these two are identical in use. * add compatible versions and filters to ckan-setup action * actions: use KSPRoot instead of KSP_ROOT environment variable * use the correct ref in nested actions * Change of strategy Instead of a couple big uber-configurable actions, have a handful of small ones. its still only 6 steps total in the template workflow. * ckan-setup: install CKAN, setup an instance, install any mods listed * install-dependencies: run the CKANInstall target in msbuild * compile: Same as before, but no longer calls the previous 2 steps all or none of these can be used by the user depending on what their mod is and how it is set-up I think this will be a lot more modular and easy to use? * fix typo * Fix broken syntax in env nodes * fix syntax redux * yaml i s2g * interpolation syntax is needed here * turns out this was not actually more portable fucking mono vs dotnet shit * Install CKAN using cached apt packages for speed * Revert "Install CKAN using cached apt packages for speed" This reverts commit 4c85562. * Can we just install ckan directly? I mean, its just a mono exe... why bother with apt? as a bonus its cross platform! * oops * oops 2 * fix url * make sure ckan directory exists * fix dir name * quick debug info * bah * maybe this works? * actually download ckan to where its supposed to be * I hate bash string interpolation * use workspace instead of HOME * fix second reference * take the -L * Fix slug generation 🐌 * don't require 'v' in ckan version * fix pinned asset URLs * Move ckan-setup to setup-ckan For commonality with most other "setup" actions in the world * Default KSPRoot to the "KSP_ROOT" environment variable if it exists * Rework ckan dependency installation Now faster by using `ckan prompt`, as well as running before the `Restore` target instead of on its own. Also remove the confusingly named `install-dependencies` action, which is what ran this target before. * Fix broken temp directory path * temp directory instead of file * fix restore call and add debug info * use `gh release` to download ckan instead of url hacks allows using the deb instead of bare exe, thank god. also might be faster on github infra? * yaml lol * fix input reference * why is this even necessary * actually use the .deb * Get working on local nektos-act runners when running in nektos-act, use the custom-latest image and set the `act-local` variable to true * fix var name * Remove mod install step from setup-ckan Probably too confusing. I don't think this needs to be replaced with anything, adding a `ckan install --headless` step in the mod-level workflow is fine? * Documentation and cleanup pass RELEASE_STAGING and KSP_ROOT now have defaults in all actions that use them, inputs are documented, readme updated * Document listing unreferenced dependencies in a .csproj * Better action input defaults when using env variables Values will use the passed input, then the environment variable, then the hardcoded default, in that order. * add install-ckan-mods and fix workflows * Allow manually listing CKAN mods for the compile action Slightly redundant with install-ckan-mods but its one line of bash so who cares * Fix environment variable defaulting Turns out env isnt usable in `input` after all, even though nektos-act supports it! I figured using non-defaults for these values is so unbelievably rare that having an input isnt really needed anyways * remove offending input line * unbreak setup-ckan in debug mode * fix debug and shush apt * ok slightly less verbosity thanks * remove double negative, document what these do * missed one --------- Co-authored-by: JonnyOThan <[email protected]>
1 parent 1cf9e94 commit 3cc894c

File tree

13 files changed

+290
-201
lines changed

13 files changed

+290
-201
lines changed

.github/actions/assemble-release/action.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: assemble-release
22

33
inputs:
44
artifacts:
5-
type: string
5+
description: Space-separated list of file globs to include in the output artifact
66
default: GameData LICENSE* README* CHANGELOG*
77
output-file-name:
8-
type: string
9-
default: ${{ github.event.repository.name }}
8+
description: Output artifact name
9+
default: ${{ github.event.repository.name || 'release'}}
1010

1111
outputs:
1212
artifact-id:
@@ -17,16 +17,20 @@ outputs:
1717
runs:
1818
using: composite
1919
steps:
20+
- name: Set RELEASE_STAGING
21+
if: ${{ !env.RELEASE_STAGING}}
22+
shell: bash
23+
run: echo 'KSP_ROOT=${{ '/tmp/release' }}' >> "$GITHUB_ENV"
24+
2025
- name: Assemble Release
2126
shell: bash
2227
run: |
23-
mkdir ${{ env.RELEASE_STAGING }}
28+
mkdir -p ${{ env.RELEASE_STAGING }}
2429
# TODO: delete pdb files? run some kind of assembly script?
2530
cp -r -v ${{ inputs.artifacts }} ${{ env.RELEASE_STAGING }} || :
2631
cd ${{ env.RELEASE_STAGING }}
2732
zip -r ${{ github.workspace }}/${{ inputs.output-file-name }}.zip .
28-
ARTIFACT_FILENAME="${{ inputs.output-file-name }}"
29-
echo "ARTIFACT_FILENAME=$ARTIFACT_FILENAME" >> $GITHUB_ENV
33+
echo 'ARTIFACT_FILENAME=${{ inputs.output-file-name }}' >> $GITHUB_ENV
3034
3135
- name: Upload Artifact
3236
id: upload-artifact

.github/actions/compile/action.yml

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,79 @@
11
name: compile
2+
description: >
3+
Compiles C# code using `msbuild` into a mod assembly.
4+
This action will install any dependent mods declared in the csproj file and restore NuGet packages.
25
36
inputs:
47
build-configuration:
5-
type: string
68
default: Release
9+
description: The project configuration to build. Defaults to `Release`.
10+
711
ksp-zip-url:
8-
type: string
912
default: https://github.com/KSPModdingLibs/KSPLibs/raw/main/KSP-1.12.5.zip
13+
description: >
14+
A url for a zip file that contains the assemblies from the game to link against. This should either be stripped
15+
so that it only contains public interfaces, or encrypted so that the libraries are not being redistributed unprotected.
16+
17+
Defaults to `https://github.com/KSPModdingLibs/KSPLibs/raw/main/KSP-1.12.5.zip` which contains stripped versions
18+
of the libraries and should be suitable for most users. It does not require a password.
19+
1020
ksp-zip-password:
11-
type: string
12-
dependency-identifiers:
13-
type: string
14-
msbuild-dependency-target:
15-
type: string
21+
description: >
22+
If the ksp library zip is encrypted, this is the password. It should be stored in your repository's secrets.
23+
1624
solution-file-path:
17-
type: string
25+
description: >
26+
The path to the solution file to build. Defaults to empty, which will invoke `msbuild` on the root directory of
27+
the repo and builds any `*.sln` file it finds there.
28+
29+
ckan-identifiers:
30+
description: Space-separated list of CKAN mod identifiers to install
31+
1832

1933
runs:
2034
using: composite
2135
steps:
2236

2337
- name: dump contexts
2438
shell: bash
25-
if: env.ACTIONS_STEP_DEBUG
39+
if: runner.debug
2640
run: |
2741
echo "${{ toJson(env) }}"
2842
echo "${{ toJson(github )}}"
2943
echo "${{ toJson(job) }}"
3044
echo "${{ toJson(steps) }}"
3145
printenv
3246
47+
- name: Set KSP_ROOT
48+
if: ${{ !env.KSP_ROOT }}
49+
shell: bash
50+
run: echo 'KSP_ROOT=${{ '/tmp/ksp' }}' >> "$GITHUB_ENV"
51+
3352
- name: Setup .NET
3453
uses: actions/setup-dotnet@v4
3554
with:
36-
dotnet-version: 5.x
55+
dotnet-version: 7.x
3756

3857
- name: Install Dependencies
39-
if: inputs.dependency-identifiers != '' || inputs.msbuild-dependency-target != ''
40-
uses: KSPModdingLibs/KSPBuildTools/.github/actions/install-dependencies@main
41-
with:
42-
dependency-identifiers: ${{ inputs.dependency-identifiers }}
43-
msbuild-dependency-target: ${{ inputs.msbuild-dependency-target }}
44-
solution-file-path: ${{ inputs.solution-file-path }}
58+
shell: bash
59+
if: ${{ inputs.depedency-identifiers }}
60+
run: ckan install --headless --no-recommends ${{ runner.debug && '--verbose' }} ${{ inputs.dependency-identifiers }}
4561

4662
- name: Download KSP Libs
4763
shell: bash
4864
run: |
4965
wget --quiet ${{ inputs.ksp-zip-url }} -O /tmp/ksp.zip
5066
unzip -q -P "${{ inputs.ksp-zip-password }}" /tmp/ksp.zip -d "${{ env.KSP_ROOT }}"
5167
52-
- name: Restore NuGet Packages
68+
- name: Restore Mod Solution
5369
shell: bash
5470
working-directory: ${{ github.workspace }}
55-
run: nuget restore ${{ inputs.solution-file-path }}
71+
run: dotnet restore ${{ inputs.solution-file-path }} ${{ runner.debug && '-v:detailed' }}
5672

5773
- name: Build Mod Solution
5874
shell: bash
5975
working-directory: ${{ github.workspace }}
60-
run: msbuild /p:Configuration=${{ inputs.build-configuration }} /p:KSPRoot=${{ env.KSP_ROOT }} /p:ManagedRelativePath=KSP_x64_Data/Managed ${{ inputs.solution-file-path }}
61-
76+
run: |
77+
dotnet msbuild -p:Configuration=${{ inputs.build-configuration }} \
78+
-p:ManagedRelativePath=KSP_x64_Data/Managed ${{ inputs.solution-file-path }} \
79+
${{ runner.debug && '-v:detailed' }}
Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,14 @@
1-
name: install-dependencies
1+
name: Install CKAN Mods
2+
description: Install listed dependencies using CKAN. Make sure you run the `setup-ckan` action first!
23

34
inputs:
45
dependency-identifiers:
5-
type: string
6-
msbuild-dependency-target:
7-
type: string
8-
solution-file-path:
9-
type: string
10-
ckan-compatible-versions:
11-
type: string
12-
default: |
13-
1.12
14-
1.11
15-
1.10
16-
1.9
17-
1.8
18-
ckan-filters:
19-
type: string
20-
default: |
21-
.dds
22-
.png
23-
.bmp
24-
.mu
25-
.mbm
26-
.jpg
27-
.wav
6+
description: Space-separated list of CKAN mod identifiers to install
287

298
runs:
309
using: composite
3110
steps:
32-
- name: ckan-install
11+
- name: Install Mods
3312
shell: bash
34-
run: |
35-
sudo curl -sS -o /usr/share/keyrings/ksp-ckan-archive-keyring.gpg https://raw.githubusercontent.com/KSP-CKAN/CKAN/master/debian/ksp-ckan.gpg
36-
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/ksp-ckan-archive-keyring.gpg] https://ksp-ckan.s3-us-west-2.amazonaws.com/deb stable main' | sudo tee /etc/apt/sources.list.d/ksp-ckan.list > /dev/null
37-
sudo apt update
38-
sudo apt install ckan
13+
run: ckan install --headless --no-recommends ${{ runner.debug && '--verbose' }} ${{ inputs.dependency-identifiers }}
3914

40-
- name: ckan-setup-instance
41-
shell: bash
42-
run: |
43-
ckan instance fake --set-default KSP ${{ env.KSP_ROOT }} 1.12.5 --game KSP --MakingHistory 1.9.1 --BreakingGround 1.7.1
44-
ckan update
45-
46-
versions="${{ inputs.ckan-compatible-versions }}"
47-
for version in $versions; do
48-
ckan compat add "$version"
49-
done
50-
51-
filters="${{ inputs.ckan-filters }}"
52-
for filter in $filters; do
53-
ckan filter add "$filter"
54-
done
55-
56-
- name: ckan-install-mod
57-
if: inputs.dependency-identifiers != ''
58-
shell: bash
59-
run: |
60-
identifiers="${{ inputs.dependency-identifiers}}"
61-
ckan install --no-recommends --headless $identifiers
62-
63-
- name: Setup .NET
64-
if: inputs.msbuild-dependency-target != ''
65-
uses: actions/setup-dotnet@v4
66-
with:
67-
dotnet-version: 5.x
68-
69-
- name: msbuild-dependency-target
70-
if: inputs.msbuild-dependency-target != ''
71-
shell: bash
72-
working-directory: ${{ github.workspace }}
73-
run: msbuild /t:${{ inputs.msbuild-dependency-target }} /p:KSPRoot=${{ env.KSP_ROOT }} ${{ inputs.solution-file-path }}
74-
75-
- name: debug
76-
if: env.ACTIONS_STEP_DEBUG
77-
shell: bash
78-
run: |
79-
ls -R ${{ env.KSP_ROOT }}/GameData
80-
echo "${{ toJson(env) }}"
81-
echo "${{ toJson(github )}}"
82-
echo "${{ toJson(job) }}"
83-
echo "${{ toJson(steps) }}"

.github/actions/publish-to-spacedock/action.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: publish-to-spacedock
22

33
inputs:
44
spacedock-username:
5-
type: string
5+
description: Spacedock login username
66
spacedock-password:
7-
type: string
7+
description: Spacedock login password. Store this as a secret!
88
game-id:
9-
type: number
10-
default: 3102 # hardcoded to KSP1 gameid. retrieve from https://spacedock.info/api/games
9+
description: ID of the game we are deploying for. This should probably be left as-is for KSP 1.
10+
default: '3102' # hardcoded to KSP1 gameid. retrieve from https://spacedock.info/api/games
1111
mod-id:
12-
type: number
12+
description: ID of the mod we are deploying. Get this from the end of your mod's spacedock URL
1313

1414
runs:
1515
using: composite
@@ -36,5 +36,5 @@ runs:
3636
if: false
3737
uses: KSP2Community/[email protected]
3838
with:
39-
username: ${{ env.SPACEDOCK_USERNAME }}
40-
password: ${{ env.SPACEDOCK_PASSWORD }}
39+
username: ${{ inputs.spacedock-username }}
40+
password: ${{ inputs.spacedock-password }}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Setup CKAN
2+
description: Installs CKAN and sets up a KSP installation
3+
4+
inputs:
5+
ckan-version:
6+
description: >
7+
CKAN tag to install. set to an empty string to always install the most recent version.
8+
See https://github.com/KSP-CKAN/CKAN/tags for a list of available tags
9+
default: ''
10+
11+
ckan-repo:
12+
description: HOST/OWNER/REPO of the CKAN github repository to pull from. Defaults to the mainline version
13+
default: 'https://github.com/KSP-CKAN/CKAN'
14+
15+
ckan-compatible-versions:
16+
description: KSP versions to mark as compatible. newline-separated.
17+
default: |
18+
1.12
19+
1.11
20+
1.10
21+
1.9
22+
1.8
23+
24+
ckan-filters:
25+
description: CKAN filters to enable. newline-separated
26+
default: |
27+
.dds
28+
.png
29+
.bmp
30+
.mu
31+
.mbm
32+
.jpg
33+
.wav
34+
35+
runs:
36+
using: composite
37+
steps:
38+
- name: Set KSP_ROOT
39+
if: ${{ !env.KSP_ROOT }}
40+
shell: bash
41+
run: echo 'KSP_ROOT=${{ '/tmp/ksp' }}' >> "$GITHUB_ENV"
42+
43+
- name: Install CKAN
44+
shell: bash
45+
run: |
46+
gh release download ${{ inputs.ckan-version }} --repo ${{ inputs.ckan-repo }} --pattern 'ckan*.deb' -O ckan.deb
47+
${{ env.ACT && 'sudo apt update --quiet' }}
48+
sudo apt install --quiet ./ckan.deb ${{ runner.debug && '--verbose-versions' }}
49+
ckan version
50+
env:
51+
GH_TOKEN: ${{ github.token }}
52+
53+
- name: Setup CKAN Instance
54+
shell: bash
55+
run: |
56+
${{ runner.debug && 'echo "$PATH"' }}
57+
ckan instance fake --set-default KSP ${{ env.KSP_ROOT }} 1.12.5 --game KSP --MakingHistory 1.9.1 --BreakingGround 1.7.1 ${{ runner.debug && '--verbose' }}
58+
ckan update
59+
60+
- name: Setup CKAN Compatible Versions
61+
shell: bash
62+
if: inputs.ckan-compatible-versions != ''
63+
run: |
64+
for version in $VERSIONS; do
65+
ckan compat add "$version" ${{ runner.debug && '--verbose' }}
66+
done
67+
env:
68+
VERSIONS: ${{ inputs.ckan-compatible-versions }}
69+
70+
- name: Setup CKAN Filter
71+
shell: bash
72+
if: inputs.ckan-filters != ''
73+
run: |
74+
for filter in $FILTERS; do
75+
ckan filter add "$filter" ${{ runner.debug && '--verbose' }}
76+
done
77+
env:
78+
FILTERS: ${{ inputs.ckan-filters }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: build
2+
description: Build and assemble a KSP mod that uses csproj file.
3+
4+
on:
5+
push:
6+
branches: [ $default-branch ]
7+
paths:
8+
- '**/*.cs'
9+
pull_request:
10+
paths:
11+
- '**/*.cs'
12+
workflow_dispatch:
13+
workflow_call:
14+
15+
jobs:
16+
build:
17+
steps:
18+
- name: Checkout Mod Repo
19+
uses: actions/checkout@v4
20+
with:
21+
submodules: true
22+
23+
# Install CKAN and set up an instance. If CKAN is not needed, remove this step
24+
- uses: KSPModdingLibs/KSPBuildTools/.github/actions/setup-ckan@main
25+
26+
# Install any CKAN dependencies not in the msbuild file. If there are none, remove this step
27+
- uses: KSPModdingLibs/KSPBuildTools/.github/actions/install-dependencies@main
28+
with:
29+
# Any additional CKAN identifiers not listed in the csproj can be listed here. space-separated
30+
dependency-identifiers: ""
31+
32+
# Compile the mod.
33+
- uses: KSPModdingLibs/KSPBuildTools/.github/actions/compile@main
34+
with:
35+
ksp-zip-url: https://github.com/KSPModdingLibs/KSPLibs/raw/main/KSP-1.12.5.zip
36+
ksp-zip-password: ${{ secrets.ksp-zip-password }}
37+
38+
# Assemble the mod into a release package and upload it as an artifact
39+
- uses: KSPModdingLibs/KSPBuildTools/.github/actions/assemble-release@main
40+
with:
41+
artifacts: "GameData LICENSE* README* CHANGELOG*"
42+
output-file-name: ${{ github.event.repository.name }}-${{ inputs.build-configuration }}

.github/workflow-templates/build.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)