Skip to content

Commit

Permalink
Merge pull request #4 from SpaceWarpDev/dev
Browse files Browse the repository at this point in the history
1.8.0.1
  • Loading branch information
jan-bures committed Jan 15, 2024
2 parents 9d33b62 + bc4e17b commit 4d7b19a
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 24 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish template release

on:
release:
types: [ "published" ]

jobs:
publish:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download NuGet
id: download-nuget
run: sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

- name: Install jq
uses: dcarbone/install-jq-action@v2.1.0

- name: Build template
id: build-template
run: pwsh -NoProfile -ExecutionPolicy Bypass -File "BuildPackage.ps1"

- name: Extract current version
id: get-version
run: |
filepath=$(ls -1 dist/SpaceWarp.Template.*.nupkg | head -n 1)
filename=$(basename $filepath)
echo "Release filename is $filename"
echo "release_filename=$filename" >> $GITHUB_ENV
echo "release_path=$filepath" >> $GITHUB_ENV
echo "upload_url=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].upload_url' | tr -d \")" >> $GITHUB_ENV
wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.[0].body' > ./changelog.md
- name: Upload zip to release
uses: shogo82148/actions-upload-release-asset@v1.7.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.upload_url }}
asset_path: ${{ env.release_path }}
asset_name: ${{ env.release_filename }}
asset_content_type: application/octet-stream

- name: Upload create-project.bat to release
uses: shogo82148/actions-upload-release-asset@v1.7.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.upload_url }}
asset_path: "create-project.bat"
asset_name: ${{ env.release_filename }}
asset_content_type: application/octet-stream

- name: Publish to nuget.org
run: dotnet nuget push ${{ env.release_path }} --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
9 changes: 7 additions & 2 deletions BuildPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ Get-ChildItem -Path "$BuildFolderPath/templates" -Directory | ForEach-Object {
}

Write-Host "Packing NuGet package"
$nugetOutput = & nuget pack "./Package.nuspec" -NoDefaultExcludes -OutputDirectory "$DistFolderPath" `
-Properties "NoWarn=NU5110,NU5111;buildDir=`"$BuildFolderPath`"" 2>&1
if ($IsWindows) {
$nugetCommand = "nuget"
} else {
$nugetCommand = "mono /usr/local/bin/nuget.exe"
}
$nugetOutput = & $nugetCommand pack "./Package.nuspec" -NoDefaultExcludes -OutputDirectory "$DistFolderPath" `
-Properties "NoWarn=NU5110,NU5111;buildDir=$BuildFolderPath" 2>&1
$nugetOutput | ForEach-Object {
if ($_ -match "SpaceWarp\.Template\.[0-9\.]+\.nupkg") {
$nugetFileName = $matches[0]
Expand Down
2 changes: 1 addition & 1 deletion Package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>SpaceWarp.Template</id>
<version>1.7.0.2</version>
<version>1.8.0.1</version>
<authors>munix</authors>
<title>SpaceWarp Mod Template</title>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
56 changes: 42 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project serves as a SpaceWarp mod project template for the .NET CLI and Vis

### Optional

- **Visual Studio 2022** - Visual Studio 2022 is the required version if you want to use the template with it
- **Visual Studio 2022** - Visual Studio 2022 is the required version if you want to use the template with VS
- **JetBrains Rider** - The template can also be used with JetBrains Rider (tested with version 2023.3)
- **Unity 2022.3.5f1** - Needed to build projects based on the **General mod project with UI** template

Expand All @@ -19,7 +19,15 @@ For .NET 7+ SDK, you can use the commands as they are written below.
You can see the SDK version currently in use and all SDK versions
installed by running `dotnet --info`.

### A. NuGet.org
### A. create-project.bat script

The easiest way to install the template is to use the **create-project.bat** script. You can download the latest version
from **[GitHub releases](https://github.com/SpaceWarpDev/SpaceWarp.Template/releases)**.

When you run the script, it will check whether the template is installed and if not, it will install it for you.
Similarly, it will also check for template updates and offer to install the update if a new version is available.

### B. NuGet.org

1. Run the following command in `cmd` or `powershell` to install all templates:
```console
Expand All @@ -30,7 +38,7 @@ installed by running `dotnet --info`.
dotnet new install SpaceWarp.Template::<version>
```

### B. Manual
### C. Manual

1. Download the .nupkg file from **[GitHub releases](https://github.com/jan-bures/SpaceWarp.Template/releases)**
2. Run the following command in `cmd` or `powershell` in the directory with the downloaded file after
Expand All @@ -48,13 +56,16 @@ of the template which supports SpaceWarp 0.4.0.

## Updating

To update the template to the latest version in .NET 7 SDK, run the following command:
If you are using the `create-project.bat` script, it will automatically check for updates and offer to install them
when a new version is available. _This feature is available since version 1.8.0.1 of the script._

To update the template to the latest version manually, run the following command:

```console
dotnet new update
dotnet new install SpaceWarp.Template
```

## Template types
## Available templates

The template contains various different types of projects:

Expand Down Expand Up @@ -104,7 +115,7 @@ This is the recommended template for modders who want to create a library mod wh

There are multiple options how to generate a project using this template:

### A. Project generator
### A. Project generator (strongly recommended)

1. Download the latest version of **create-project.bat** from
**[GitHub releases](https://github.com/SpaceWarpDev/SpaceWarp.Template/releases)**
Expand All @@ -126,20 +137,20 @@ There are multiple options how to generate a project using this template:
![Step 5](https://i.imgur.com/g5mkGSp.png)
6. Open the project directory, go to the `scripts` folder and run `setup.bat`. This will guide you through the process
of finishing the project setup.
7. Rebuild the solution once for all references to be resolved
7. Rebuild the solution for all references to be resolved
![Step 8](https://i.imgur.com/MeBZBbD.png)

### C. Manually with .NET CLI

1. Open `cmd` or `powershell` in the folder where you want your project created
2. Replace the information in the following command with your own and run it:
```console
dotnet new <project-type> -n MyAwesomeModName -A "munix" -M "My Awesome Mod Name" -D "This is the description of my awesome mod." -S "https://github.com/munix/MyAwesomeModName" -V "1.0.0" -C "https://raw.githubusercontent.com/munix/MyAwesomeModName/main/src/MyAwesomeModName/MyAwesomeModName.csproj"
dotnet new <project-type> -n MyAwesomeModName -A "munix" -M "My Awesome Mod Name" -D "This is the description of my awesome mod." -S "https://github.com/munix/MyAwesomeModName" -V "1.0.0" -C "https://raw.githubusercontent.com/munix/MyAwesomeModName/main/plugin_template/swinfo.json"
```
Typing `dotnet new <project-type> --help` will show you the possible parameters. You can find more information
about all project parameters in the **[Project parameters](#project-parameters)** section.

Replace `<project-type>` with one of the three project types listed in the **[Template types](#template-types)**
Replace `<project-type>` with one of the project types listed in the **[Template types](#template-types)**
section.
3. Open the project directory, go to the `scripts` folder and run `setup.bat`. This will guide you through the process
of finishing the project setup.
Expand Down Expand Up @@ -179,6 +190,7 @@ all asset bundles into the `Assets/AssetBundles` folder, and should automaticall
**Note:** You will need to repeat this process everytime you make changes to the UI files in Unity.

### Adding a new project to the solution

When you add a new project to the solution, make sure to reference it from the main plugin project so that it gets
included into the build.

Expand All @@ -201,6 +213,23 @@ the following:

This workflow is triggered whenever you create and publish a **new release**.

#### SpaceDock integration

Included in the **release.yml** workflow is also a step which automatically uploads the new version of your mod to **SpaceDock**, but
it requires some additional setup:
1. You mod needs to already have at least one release on SpaceDock.
2. Open the `release.yml` file and uncomment the `Add Mask` and `Update mod on SpaceDock` steps.
3. At the top of the `release.yml` file, update the `SPACEDOCK_MOD_ID` variable to the ID of your mod on SpaceDock.
You can find it in the URL of your mod, for example, if your mod's URL is `https://spacedock.info/mod/1234/MyMod`,
then the ID is `1234`.
4. Go to your repository on GitHub, open the **Settings** tab, and under **Security**, open **Secrets and variables**
-> **Actions**. There, create two new repository secrets with the following names and values:
- `SPACEDOCK_USER` - your SpaceDock username
- `SPACEDOCK_PASSWORD` - your SpaceDock password
This step is necessary so that your SpaceDock credentials can be used to upload the mod without being publicly
visible in your repository.

If you do not want to use any of these workflows, you can simply delete the corresponding files.

### swinfo.json
Expand All @@ -209,8 +238,8 @@ The properties in your .csproj file are automatically read from the `swinfo.json
`plugin_info` folder. This file is used by SpaceWarp mod to display information about your mod and check for updates
of your mod.

**This also applies to version information - you only need to update the version number of your mod in the `swinfo.json` file,
and it will be automatically parsed from there for all uses.**
**This also applies to version information - you only need to update the version number of your mod in the `swinfo.json`
file, and it will be automatically parsed from there for all uses.**

Here is a list of properties in the `swinfo.json` file and their corresponding .csproj properties:

Expand Down Expand Up @@ -245,5 +274,4 @@ They apply to all project types and you can find an overview of all of them and
&ast;The **License URL** parameter only applies to the **spacewarpmod-library** project type.

None of the parameters other than **Project name** are required. If you don't provide any, the template will generate a
project with the listed
default values and you'll be able to fill them in later in your .csproj file.
project with the listed default values and you'll be able to fill them in later in your .csproj file.
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
echo Running BuildPackage PowerShell script...

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "BuildPackage.ps1"
pwsh -NoProfile -ExecutionPolicy Bypass -File "BuildPackage.ps1"
61 changes: 61 additions & 0 deletions create-project.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
@echo off

echo Checking if SpaceWarp.Template is installed...
for /f "tokens=*" %%i in ('dotnet new --list ^| findstr /i "SpaceWarp"') do set template=%%i

if not defined template (
echo SpaceWarp.Template is not installed.
choice /c yn /m "Do you want to install it?"
echo.
if errorlevel 2 goto end
echo Installing SpaceWarp.Template...
dotnet new install SpaceWarp.Template
goto update
) else (
echo SpaceWarp.Template is installed.
)

echo Checking for updates...
for /f "tokens=*" %%i in ('dotnet new update --check-only ^| findstr /i "SpaceWarp.Template"') do set update=%%i

if defined update (
echo Updates are available for SpaceWarp.Template.
choice /c yn /m "Do you want to update it?"
echo.
if errorlevel 2 goto skipupdate
echo Updating SpaceWarp.Template...
dotnet new install SpaceWarp.Template
goto update
) else (
echo No updates are available for SpaceWarp.Template.
goto skipupdate
)

:update

cls

(
echo @echo off
echo echo Updating the create-project.bat script...
echo timeout /t 1 /nobreak ^>nul
echo curl -s -L -o create-project-temp.bat https://raw.githubusercontent.com/SpaceWarpDev/SpaceWarp.Template/main/create-project.bat
echo if %%errorlevel%% neq 0 ^(
echo echo Failed to download the script.
echo pause
echo ^) else ^(
echo echo The script has been updated to the latest version.
echo echo Restarting the script...
echo move /y create-project-temp.bat create-project.bat ^> NUL
echo cls
echo start "" create-project.bat ^> NUL
echo del /f /q update-create-project.bat ^> NUL
echo ^)
) > update-create-project.bat

echo Starting the update script...
start "" update-create-project.bat
exit /b

:skipupdate

cls

echo This script will create a new SpaceWarp mod project.
echo.
echo Choose the template you want to use:
Expand Down
4 changes: 2 additions & 2 deletions replacements.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SpaceWarpTemplateName=

SpaceWarpSpecVersion=2.0

SpaceWarpMinVersion=1.7.0
SpaceWarpNugetVersion=1.7.0
SpaceWarpMinVersion=1.8.0
SpaceWarpNugetVersion=1.8.0

KspMinVersion=0.2.0
KspNugetVersion=0.2.0
29 changes: 26 additions & 3 deletions src/common/.github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Upload release

env:
SPACEDOCK_MOD_ID: fill_in_your_mod_id_here

on:
release:
types: [ "published" ]
Expand All @@ -11,23 +14,29 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true

- name: Download NuGet
id: download-nuget
run: |
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
run: sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

- name: Install jq
uses: dcarbone/install-jq-action@v2.1.0

- name: Build the solution
run: dotnet build "SpaceWarpTemplateName.sln" -c Release

- name: Extract current version
id: get-version
run: |
version=$(jq -r '.version' plugin_template/swinfo.json)
echo "Version is $version"
dotnet build "SpaceWarpTemplateName.sln" -c Release
echo "version=$version" >> $GITHUB_ENV
echo "release_filename=SpaceWarpTemplateName-$version.zip" >> $GITHUB_ENV
echo "zip=$(ls -1 dist/SpaceWarpTemplateName-*.zip | head -n 1)" >> $GITHUB_ENV
echo "upload_url=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].upload_url' | tr -d \")" >> $GITHUB_ENV
wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.[0].body' > ./changelog.md
- name: Upload zip to release
uses: shogo82148/actions-upload-release-asset@v1.7.2
Expand All @@ -38,3 +47,17 @@ jobs:
asset_path: ${{ env.zip }}
asset_name: ${{ env.release_filename }}
asset_content_type: application/zip

# - name: Add Mask
# run: echo "::add-mask::${{ secrets.SPACEDOCK_PASSWORD }}"
#
# - name: Update mod on SpaceDock
# uses: KSP2Community/spacedock-upload@v1.0.0
# with:
# username: ${{ secrets.SPACEDOCK_USER }}
# password: ${{ secrets.SPACEDOCK_PASSWORD }}
# game_id: 22407
# mod_id: ${{ env.SPACEDOCK_MOD_ID }}
# version: ${{ env.version }}
# zipball: ${{ env.zip }}
# changelog: ./changelog.md
Loading

0 comments on commit 4d7b19a

Please sign in to comment.