Skip to content

Commit

Permalink
Merge pull request #30 from VRLabs/feature/custom-json-fields
Browse files Browse the repository at this point in the history
Add json fields option and updated to .net 9
  • Loading branch information
jellejurre authored Dec 4, 2024
2 parents 7ad85dd + b59bcb4 commit 7b8ad42
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 65 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.x.x'
dotnet-version: '9.x.x'

- name: Restore dependencies
run: dotnet restore
Expand All @@ -46,7 +46,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set version from branch name
id: set_version
Expand All @@ -63,9 +63,9 @@ jobs:
echo "image_name=$lowercase" >> $GITHUB_OUTPUT
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.x.x'
dotnet-version: '9.x.x'

- name: Restore dependencies
run: dotnet restore
Expand All @@ -79,7 +79,7 @@ jobs:
mv bin/Release/publish/VRLabs.VRCTools.Packaging.Console bin/Release/publish/VRCPackagingTool${1##*.}
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: VRCPackagingTool-${{ matrix.RUNTIME }}
path: bin/Release/publish/
Expand All @@ -89,7 +89,7 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set version from branch name
id: set_version
Expand All @@ -110,7 +110,7 @@ jobs:
sed -i "s/<Version>.*<\/Version>/<Version>${{ steps.set_version.outputs.version }}<\/Version>/" VRLabs.VRCTools.Packaging.Console/VRLabs.VRCTools.Packaging.Console.csproj
- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -119,7 +119,7 @@ jobs:
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
file: ./VRLabs.VRCTools.Packaging.Console/Dockerfile
Expand All @@ -135,7 +135,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set version from branch name
id: set_version
Expand All @@ -151,9 +151,10 @@ jobs:
echo "image_name=$lowercase" >> $GITHUB_OUTPUT
- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: bin/Release/publish
pattern: VRCPackagingTool-*

- name: Zip each artifact
run: |
Expand All @@ -174,4 +175,4 @@ jobs:
files: |
bin/Release/publish/VRCPackagingTool-linux-x64.zip
bin/Release/publish/VRCPackagingTool-win-x64.zip
bin/Release/publish/VRCPackagingTool-osx-x64.zip
bin/Release/publish/VRCPackagingTool-osx-x64.zip
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Only generating the `vcc` package:
VRCPackagingTool.exe "packageAssetsPath" "outputDirectorypath" --releaseUrl "vccReleaseUrl" --nounity
```

With custom json fields in the `package.json`,useful for custom vcc clients that may use additional fields (for example [ALCOM's](https://vrc-get.anatawa12.com/alcom/) custom changelog url field):

```
VRCPackagingTool.exe "packageAssetsPath" "outputDirectorypath" --releaseUrl "vccReleaseUrl" --unityReleaseUrl "unityReleaseUrl" --customJsonFields "changelogUrl=https://link.to.changelog" "anotherField=anotherValue"
```

You can use the `--help` or `-h` flag to get a list of all the available options.

```
Expand All @@ -49,16 +55,15 @@ Arguments:
<output> Output directory path
Options:
--releaseUrl <releaseUrl> Url of the release []
--unityReleaseUrl <unityReleaseUrl> Url of the release of the unitypackage []
--releaseVersion <releaseVersion> Version to use for the release, if not specified it will be taken from the package.json []
--novcc don't build the vcc zip file [default: False]
--nounity don't build the unitypackage [default: False]
--action is it running on github actions? [default: False]
--version Show version information
-?, -h, --help Show help and usage information
--releaseUrl <releaseUrl> Url of the release []
--unityReleaseUrl <unityReleaseUrl> Url of the release of the unitypackage []
--releaseVersion <releaseVersion> Version to use for the release, if not specified it will be taken from the package.json []
--novcc don't build the vcc zip file [default: False]
--nounity don't build the unitypackage [default: False]
--action is it running on github actions? [default: False]
--customJsonFields <customJsonFields> custom json fields to add to the package.json []
--version Show version information
-?, -h, --help Show help and usage information
```


Expand All @@ -75,7 +80,7 @@ The tool can use some additional fields in the `package.json` for the packaging

(Fields marked with * are required for the UnityPackage generation)

And it adds some additional fields to the `package.json`:
And it adds some additional fields to the `package.json` (on top of the one passed via the `--customJsonFields` option):

| Field | Description |
|-------------------|--------------------------------------------------------------------|
Expand Down
4 changes: 2 additions & 2 deletions VRLabs.VRCTools.Packaging.Console/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
WORKDIR /src
COPY ["VRLabs.VRCTools.Packaging.Console/VRLabs.VRCTools.Packaging.Console.csproj", "VRLabs.VRCTools.Packaging.Console/"]
RUN dotnet restore "VRLabs.VRCTools.Packaging.Console/VRLabs.VRCTools.Packaging.Console.csproj"
Expand All @@ -9,6 +9,6 @@ RUN dotnet build "VRLabs.VRCTools.Packaging.Console.csproj" -c Release -o /app/b
FROM build AS publish
RUN dotnet publish "VRLabs.VRCTools.Packaging.Console.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS final
FROM mcr.microsoft.com/dotnet/runtime:9.0-alpine AS final
COPY --from=publish /app/publish /app
ENTRYPOINT ["dotnet", "/app/VRLabs.VRCTools.Packaging.Console.dll"]
62 changes: 62 additions & 0 deletions VRLabs.VRCTools.Packaging.Console/PackagingOptionsBinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.CommandLine;
using System.CommandLine.Binding;

namespace VRLabs.VRCTools.Packaging.Console;

public class PackagingOptionsBinder : BinderBase<PackagingOptions>
{
private readonly Argument<string> _workingDirectoryArg;
private readonly Argument<string> _outputDirectoryArg;
private readonly Option<string?> _releaseUrlOpt;
private readonly Option<string?> _unityReleaseUrlOpt;
private readonly Option<string?> _versionOpt;
private readonly Option<bool> _noVccOpt;
private readonly Option<bool> _noUnityOpt;
private readonly Option<bool> _actionOpt;
private readonly Option<string[]> _customFieldsOpt;

public PackagingOptionsBinder(Argument<string> workingDirectoryArg, Argument<string> outputDirectoryArg, Option<string?> releaseUrlOpt,
Option<string?> unityReleaseUrlOpt, Option<string?> versionOpt, Option<bool> noVccOpt, Option<bool> noUnityOpt, Option<bool> actionOpt,
Option<string[]> customFieldsOpt)
{
_workingDirectoryArg = workingDirectoryArg;
_outputDirectoryArg = outputDirectoryArg;
_releaseUrlOpt = releaseUrlOpt;
_unityReleaseUrlOpt = unityReleaseUrlOpt;
_versionOpt = versionOpt;
_noVccOpt = noVccOpt;
_noUnityOpt = noUnityOpt;
_actionOpt = actionOpt;
_customFieldsOpt = customFieldsOpt;
}

protected override PackagingOptions GetBoundValue(BindingContext bindingContext) =>
new()
{
WorkingDirectory = bindingContext.ParseResult.GetValueForArgument(_workingDirectoryArg),
OutputDirectory = bindingContext.ParseResult.GetValueForArgument(_outputDirectoryArg),
ReleaseUrl = bindingContext.ParseResult.GetValueForOption(_releaseUrlOpt),
UnityPackageUrl = bindingContext.ParseResult.GetValueForOption(_unityReleaseUrlOpt),
Version = bindingContext.ParseResult.GetValueForOption(_versionOpt),
SkipVcc = bindingContext.ParseResult.GetValueForOption(_noVccOpt),
SkipUnityPackage = bindingContext.ParseResult.GetValueForOption(_noUnityOpt),
IsRunningOnGithubActions = bindingContext.ParseResult.GetValueForOption(_actionOpt),
CustomFields = GetDictionaryField(bindingContext.ParseResult.GetValueForOption(_customFieldsOpt))
};

private Dictionary<string, string> GetDictionaryField(string[]? values)
{
var dictionary = new Dictionary<string, string>();

foreach (var kvp in values ?? [])
{
var split = kvp.Split('=');
if (split.Length >= 2)
{
dictionary.Add(split[0], string.Join("=", split[1..]));
}
}

return dictionary;
}
}
12 changes: 7 additions & 5 deletions VRLabs.VRCTools.Packaging.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.CommandLine;
using Serilog;
using VRLabs.VRCTools.Packaging;
using VRLabs.VRCTools.Packaging.Console;

Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
Expand All @@ -14,6 +15,7 @@
var noVccOpt = new Option<bool>(name: "--novcc", getDefaultValue: () => false, description: "don't build the vcc zip file");
var noUnityOpt = new Option<bool>(name: "--nounity", getDefaultValue: () => false, description: "don't build the unitypackage");
var actionOpt = new Option<bool>(name: "--action", getDefaultValue: () => false, description: "is it running on github actions?");
var customFieldsOpt = new Option<string[]>(name: "--customJsonFields", getDefaultValue: () => [], description: "custom json fields to add to the package.json"){AllowMultipleArgumentsPerToken = true};

var command = new RootCommand("Packs the assets inside a folder in a Unity Project based on an info file")
{
Expand All @@ -24,15 +26,15 @@
versionOpt,
noVccOpt,
noUnityOpt,
actionOpt
actionOpt,
customFieldsOpt
};

command.SetHandler(async (source, output, releaseUrl, unityReleaseUrl, version, noVcc, noUnity, action) =>
command.SetHandler(async (packagingOptions) =>
{
try
{
Environment.SetEnvironmentVariable("RUNNING_ON_GITHUB_ACTIONS", action ? "true" : "false");
var result = await Packager.CreatePackage(source, output, releaseUrl, unityReleaseUrl, version, noVcc, noUnity);
var result = await Packager.CreatePackage(packagingOptions);
if (!result)
{
Log.Error("Failed to create package");
Expand All @@ -45,6 +47,6 @@
Environment.Exit(1);
}

}, pathArg, outputArg, releaseUrlOpt, unityReleaseUrlOpt, versionOpt, noVccOpt, noUnityOpt, actionOpt);
}, new PackagingOptionsBinder(pathArg, outputArg, releaseUrlOpt, unityReleaseUrlOpt, versionOpt, noVccOpt, noUnityOpt, actionOpt, customFieldsOpt));

command.Invoke(args);
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>1.1.999</Version>
<Version>1.2.999</Version>
<IsPackable>false</IsPackable>
<Title>VRC Packaging Tool</Title>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Company>VRLabs</Company>
<Authors>VRLabs</Authors>
<Description>Tool to package assets both in UnityPackage and VRChat's vcc format</Description>
<LangVersion>13</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,8 +23,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 7b8ad42

Please sign in to comment.