Skip to content

Commit 68cdf64

Browse files
authored
Merge pull request #218 from sunnamed434/dotnet-global-tool
Add .NET Global Tool, might be not stable yet, bug fixes
2 parents add691a + 14f487f commit 68cdf64

20 files changed

+331
-64
lines changed

.deepsource.toml

-4
This file was deleted.

.github/actions/nuget-pack/action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
description: 'Path to .nuspec'
66
required: true
77
nuget_push:
8-
description: 'Push to Nuget?'
8+
description: 'Push to NuGet?'
99
required: false
1010
default: false
1111
nuget_key:

.github/actions/project-build/action.yaml

+40-23
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ inputs:
77
target_framework:
88
description: 'The target framework to build on'
99
required: true
10+
use_runtime:
11+
description: 'Include runtime flag? Set to true for self-contained builds, false (default) for global tools.'
12+
required: false
13+
default: true
1014
runtime_version:
11-
description: 'Build runtime version default linux-x64'
15+
description: 'Build runtime version (default linux-x64) if using a runtime flag'
1216
required: false
1317
default: 'linux-x64'
1418
nuget_push:
15-
description: 'Push to Nuget on release?'
19+
description: 'Push to NuGet on release?'
1620
required: false
1721
default: false
1822
nuget_key:
@@ -34,35 +38,46 @@ runs:
3438
# Generate semver compatible version from current tag and commit hash
3539
- name: Create version
3640
id: get-version
37-
run: echo "version=$(git describe --tags `git rev-list --tags --max-count=1`)+$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
41+
run: echo "version=$(git describe --tags $(git rev-list --tags --max-count=1))+$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
3842
shell: bash
3943

4044
- name: Check Prerelease
4145
id: check-prerelease
42-
run: "if ${{ contains(steps.get-version.outputs.version, '-') }}; then
43-
echo is_prerelease=true >> $GITHUB_OUTPUT;
44-
else
45-
echo is_prerelease=false >> $GITHUB_OUTPUT;
46-
fi"
46+
run: |
47+
if [[ "${{ steps.get-version.outputs.version }}" == *"-"* ]]; then
48+
echo "is_prerelease=true" >> $GITHUB_OUTPUT
49+
else
50+
echo "is_prerelease=false" >> $GITHUB_OUTPUT
51+
fi
52+
shell: bash
53+
54+
# Determine whether to include the --runtime flag.
55+
- name: Set runtime flag
56+
id: set-runtime-flag
57+
run: |
58+
if [ "${{ inputs.use_runtime }}" = "true" ]; then
59+
echo "runtime=--runtime ${{ inputs.runtime_version }}" >> $GITHUB_OUTPUT
60+
else
61+
echo "runtime=" >> $GITHUB_OUTPUT
62+
fi
4763
shell: bash
4864

4965
# Commands that are used multiple times.
50-
# Placed in one place to make sure that the arguments would always be the same
5166
- name: Common commands
5267
id: common-commands
5368
run: |
54-
echo "dotnet-restore=dotnet restore \$PROJECT_PATH --runtime ${{ inputs.runtime_version }} -p:Configuration=Release -p:TargetFramework=${{ inputs.target_framework }}" >> $GITHUB_OUTPUT
55-
echo "dotnet-build=dotnet build \$PROJECT_PATH --configuration Release --no-restore --runtime ${{ inputs.runtime_version }} -p:TargetFramework=${{ inputs.target_framework }} -p:BitMonoVersion=${{ steps.get-version.outputs.version }}" >> $GITHUB_OUTPUT
56-
echo "dotnet-test=dotnet test \$PROJECT_PATH --configuration Release --no-restore --no-build --runtime ${{ inputs.runtime_version }} -p:TargetFramework=${{ inputs.target_framework }}" >> $GITHUB_OUTPUT
69+
echo "dotnet-restore=dotnet restore \$PROJECT_PATH ${{ steps.set-runtime-flag.outputs.runtime }} -p:Configuration=Release -p:TargetFramework=${{ inputs.target_framework }}" >> $GITHUB_OUTPUT
70+
echo "dotnet-build=dotnet build \$PROJECT_PATH --configuration Release --no-restore ${{ steps.set-runtime-flag.outputs.runtime }} -p:TargetFramework=${{ inputs.target_framework }} -p:BitMonoVersion=${{ steps.get-version.outputs.version }}" >> $GITHUB_OUTPUT
71+
echo "dotnet-test=dotnet test \$PROJECT_PATH --configuration Release --no-restore --no-build ${{ steps.set-runtime-flag.outputs.runtime }} -p:TargetFramework=${{ inputs.target_framework }}" >> $GITHUB_OUTPUT
5772
shell: bash
5873

59-
# Install dependencies (this needs to be a separate step from build for caching)
74+
# Install dependencies (separate step for caching)
6075
- name: Install dependencies
6176
run: |
6277
${{ steps.common-commands.outputs.dotnet-restore }}
6378
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$GITHUB_WORKSPACE/tests" '${{ steps.common-commands.outputs.dotnet-restore }}'
6479
env:
65-
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
80+
PROJECT_PATH: ${{ inputs.project_path }}
6681
shell: bash
6782

6883
# Build project
@@ -71,27 +86,29 @@ runs:
7186
${{ steps.common-commands.outputs.dotnet-build }}
7287
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$GITHUB_WORKSPACE/tests" '${{ steps.common-commands.outputs.dotnet-build }}'
7388
env:
74-
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
89+
PROJECT_PATH: ${{ inputs.project_path }}
7590
shell: bash
7691

7792
# Test project
7893
- name: Test
7994
run: |
8095
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$GITHUB_WORKSPACE/tests" '${{ steps.common-commands.outputs.dotnet-test }}'
8196
env:
82-
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
97+
PROJECT_PATH: ${{ inputs.project_path }}
8398
shell: bash
8499

85-
# Push to GitHub packages on each commit and release
100+
# Push to GitHub packages on each commit and release (Nightly)
86101
- name: Push to NuGet (Nightly)
87-
run: if ${{ inputs.nuget_push == 'true' && (github.event_name == 'push' || (github.event_name == 'create' && github.event.ref_type == 'tag')) }}; then
88-
dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.github_token }} --skip-duplicate --source https://nuget.pkg.github.com/sunnamed434/index.json;
102+
run: |
103+
if [ "${{ inputs.nuget_push }}" = "true" ] && ( [ "${{ github.event_name }}" = "push" ] || ( [ "${{ github.event_name }}" = "create" ] && [ "${{ github.event.ref_type }}" = "tag" ] ) ); then
104+
dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.github_token }} --skip-duplicate --source https://nuget.pkg.github.com/sunnamed434/index.json;
89105
fi
90106
shell: bash
91107

92-
# Push to NuGet on each tag, but only if the tag is not a pre-release version
108+
# Push to NuGet on each tag, but only if not a pre-release version (Release)
93109
- name: Push to NuGet (Release)
94-
run: if ${{ inputs.nuget_push == 'true' && github.event_name == 'create' && github.event.ref_type == 'tag' && steps.check-prerelease.outputs.is_prerelease == 'false' }}; then
95-
dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.nuget_key }} --skip-duplicate --source https://api.nuget.org/v3/index.json;
110+
run: |
111+
if [ "${{ inputs.nuget_push }}" = "true" ] && [ "${{ github.event_name }}" = "create" ] && [ "${{ github.event.ref_type }}" = "tag" ] && [ "${{ steps.check-prerelease.outputs.is_prerelease }}" = "false" ]; then
112+
dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.nuget_key }} --skip-duplicate --source https://api.nuget.org/v3/index.json;
96113
fi
97-
shell: bash
114+
shell: bash
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: BitMono.GlobalTool
2+
3+
on:
4+
create:
5+
tags:
6+
- "*"
7+
push:
8+
branches: [ main ]
9+
paths:
10+
- '.github/workflows/BitMono.GlobalTool.yaml'
11+
- 'src/BitMono.GlobalTool/**'
12+
- 'src/props/**'
13+
pull_request:
14+
branches: [ main ]
15+
paths:
16+
- '.github/workflows/BitMono.GlobalTool.yaml'
17+
- 'src/BitMono.GlobalTool/**'
18+
- 'src/props/**'
19+
20+
jobs:
21+
build:
22+
name: "BitMono.GlobalTool Build"
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- uses: actions/setup-dotnet@v4
31+
name: Setup .NET
32+
with:
33+
dotnet-version: 9.x
34+
35+
- uses: ./.github/actions/project-build
36+
id: project-build
37+
with:
38+
project_path: src/BitMono.GlobalTool
39+
github_token: ${{ secrets.PAT }}
40+
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
41+
nuget_push: true
42+
use_runtime: false # Because this is a dotnet tool.

BitMono.sln

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitMono.Obfuscation.TestCas
6161
EndProject
6262
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "test\Sandbox\Sandbox.csproj", "{C5BD413C-89AF-4480-870D-985AE6C44A38}"
6363
EndProject
64+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "src\BitMono.GlobalTool", "src\BitMono.GlobalTool\BitMono.GlobalTool.csproj", "{EFBBB7CA-39C7-42A7-A965-7A2F172B1707}"
65+
EndProject
6466
Global
6567
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6668
Debug|Any CPU = Debug|Any CPU
@@ -139,6 +141,10 @@ Global
139141
{C5BD413C-89AF-4480-870D-985AE6C44A38}.Debug|Any CPU.Build.0 = Debug|Any CPU
140142
{C5BD413C-89AF-4480-870D-985AE6C44A38}.Release|Any CPU.ActiveCfg = Release|Any CPU
141143
{C5BD413C-89AF-4480-870D-985AE6C44A38}.Release|Any CPU.Build.0 = Release|Any CPU
144+
{EFBBB7CA-39C7-42A7-A965-7A2F172B1707}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
145+
{EFBBB7CA-39C7-42A7-A965-7A2F172B1707}.Debug|Any CPU.Build.0 = Debug|Any CPU
146+
{EFBBB7CA-39C7-42A7-A965-7A2F172B1707}.Release|Any CPU.ActiveCfg = Release|Any CPU
147+
{EFBBB7CA-39C7-42A7-A965-7A2F172B1707}.Release|Any CPU.Build.0 = Release|Any CPU
142148
EndGlobalSection
143149
GlobalSection(SolutionProperties) = preSolution
144150
HideSolutionNode = FALSE
@@ -164,6 +170,7 @@ Global
164170
{49E6076C-FEC8-4411-B7AE-4DB6112370C1} = {1EF50257-AFD3-48A3-9E22-03BDC25550A7}
165171
{E73C9803-971F-4F7D-A21B-9097C2EC1A80} = {A431DCB4-6EF9-4BEF-8902-FA704D62624E}
166172
{C5BD413C-89AF-4480-870D-985AE6C44A38} = {1EF50257-AFD3-48A3-9E22-03BDC25550A7}
173+
{EFBBB7CA-39C7-42A7-A965-7A2F172B1707} = {D87066C4-1144-4BD8-96E9-9F4676001397}
167174
EndGlobalSection
168175
GlobalSection(ExtensibilityGlobals) = postSolution
169176
SolutionGuid = {7DA0BB43-C1D4-4688-BE43-A9ED2D6F78EE}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ To download the latest release of BitMono, follow these steps:
106106
- **Targeting Mono or Unity Engine Runtime**: If your target file is built for .NET Framework and runs on Mono or Unity, use the .NET Framework version:
107107
`BitMono-v0.25.3+e64e54d3-CLI-net462-win-x64.zip`
108108

109-
> **Note:** Be sure to select the correct version of BitMono that matches your Target Framework. Using the wrong version could result in compatibility issues.
109+
> **Note:** Be sure to select the correct version of BitMono that matches your Target Framework. Using the wrong version could result in compatibility issues, however, if that works ok anyway or if you know what you're doing, you can ignore it.
110110
111111
### Pre-Require
112112

src/BitMono.API/Configuration/JsonConfigurationAccessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class JsonConfigurationAccessor : IConfigurationAccessor
55
protected JsonConfigurationAccessor(string file)
66
{
77
Configuration = new ConfigurationBuilder()
8-
.AddJsonFile(file, true, true)
8+
.AddJsonFile(file, false, true)
99
.Build();
1010
}
1111

src/BitMono.CLI/BitMono.CLI.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;net462;netstandard2.1;netstandard2.0;</TargetFrameworks>
66
<ApplicationIcon>BitMonoLogo.ico</ApplicationIcon>
7-
<SolutionDir>$([System.IO.Path]::GetFullPath($(MSBuildProjectDirectory)/../../))</SolutionDir>
87
</PropertyGroup>
98

109
<Import Project="$(MSBuildThisFileDirectory)..\..\props\SharedProjectProps.props"/>

src/BitMono.CLI/Modules/ObfuscationNeeds.cs

+12
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,17 @@ internal class ObfuscationNeeds
77
public string FileBaseDirectory { get; set; }
88
public string ReferencesDirectoryName { get; set; }
99
public string OutputPath { get; set; }
10+
public ObfuscationNeedsWay Way { get; set; }
1011
#pragma warning restore CS8618
12+
}
13+
14+
/// <summary>
15+
/// The way <see cref="ObfuscationNeeds"/> was created.
16+
/// </summary>
17+
public enum ObfuscationNeedsWay
18+
{
19+
Unknown,
20+
Readline,
21+
Options,
22+
Other,
1123
}

src/BitMono.CLI/Modules/OptionsObfuscationNeedsFactory.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public OptionsObfuscationNeedsFactory(string[] args,
4343
FileName = filePath,
4444
FileBaseDirectory = fileBaseDirectory,
4545
ReferencesDirectoryName = fileBaseDirectory,
46-
OutputPath = fileBaseDirectory
46+
OutputPath = fileBaseDirectory,
47+
Way = ObfuscationNeedsWay.Options
4748
};
4849
}
4950
else
@@ -57,7 +58,8 @@ public OptionsObfuscationNeedsFactory(string[] args,
5758
: Path.Combine(fileBaseDirectory, _obfuscationSettings.ReferencesDirectoryName),
5859
OutputPath = options.Output?.IsNullOrEmpty() == false
5960
? options.Output
60-
: Path.Combine(fileBaseDirectory, _obfuscationSettings.OutputDirectoryName)
61+
: Path.Combine(fileBaseDirectory, _obfuscationSettings.OutputDirectoryName),
62+
Way = ObfuscationNeedsWay.Options
6163
};
6264
}
6365

src/BitMono.CLI/Modules/ReadlineObfuscationNeedsFactory.cs

+16-18
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,29 @@ public ReadlineObfuscationNeedsFactory(string[] args, ObfuscationSettings obfusc
1616
public ObfuscationNeeds Create(CancellationToken cancellationToken)
1717
{
1818
var fileName = GetFileName(_args);
19-
var specifyingFile = true;
20-
while (specifyingFile)
19+
while (true)
2120
{
2221
try
2322
{
24-
_logger.Information("Please, specify file or drag-and-drop in BitMono CLI");
25-
2623
cancellationToken.ThrowIfCancellationRequested();
2724

25+
_logger.Information("Please, specify file or drag-and-drop in BitMono CLI");
26+
2827
fileName = PathFormatterUtility.Format(Console.ReadLine());
29-
if (string.IsNullOrWhiteSpace(fileName) == false)
28+
cancellationToken.ThrowIfCancellationRequested();
29+
if (!string.IsNullOrWhiteSpace(fileName))
3030
{
3131
if (File.Exists(fileName))
3232
{
33-
specifyingFile = false;
3433
_logger.Information("File successfully specified: {0}", fileName);
34+
break;
3535
}
36-
else
37-
{
38-
_logger.Warning("File cannot be found, please, try again!");
39-
}
36+
37+
_logger.Warning("File cannot be found, please, try again!");
4038
}
4139
else
4240
{
41+
cancellationToken.ThrowIfCancellationRequested();
4342
_logger.Warning("Unable to specify empty null or whitespace file, please, try again!");
4443
}
4544
}
@@ -65,10 +64,9 @@ public ObfuscationNeeds Create(CancellationToken cancellationToken)
6564
{
6665
outputDirectoryName = Path.Combine(fileBaseDirectory, _obfuscationSettings.OutputDirectoryName);
6766
dependenciesDirectoryName = Path.Combine(fileBaseDirectory, _obfuscationSettings.ReferencesDirectoryName);
68-
if (Directory.Exists(dependenciesDirectoryName) == false)
67+
if (!Directory.Exists(dependenciesDirectoryName))
6968
{
70-
var specifyingDependencies = true;
71-
while (specifyingDependencies)
69+
while (true)
7270
{
7371
try
7472
{
@@ -78,20 +76,19 @@ public ObfuscationNeeds Create(CancellationToken cancellationToken)
7876
{
7977
_logger.Information("Dependencies (libs) successfully found automatically: {0}!",
8078
dependenciesDirectoryName);
81-
specifyingDependencies = false;
8279
break;
8380
}
8481

8582
_logger.Information("Please, specify dependencies (libs) path: ");
8683
var newDependenciesDirectoryName = PathFormatterUtility.Format(Console.ReadLine());
87-
if (string.IsNullOrWhiteSpace(newDependenciesDirectoryName) == false)
84+
if (!string.IsNullOrWhiteSpace(newDependenciesDirectoryName))
8885
{
8986
if (Directory.Exists(newDependenciesDirectoryName))
9087
{
9188
dependenciesDirectoryName = newDependenciesDirectoryName;
9289
_logger.Information("Dependencies (libs) successfully specified: {0}!",
9390
newDependenciesDirectoryName);
94-
specifyingDependencies = false;
91+
break;
9592
}
9693
else
9794
{
@@ -127,14 +124,15 @@ public ObfuscationNeeds Create(CancellationToken cancellationToken)
127124
FileName = fileName,
128125
FileBaseDirectory = fileBaseDirectory,
129126
ReferencesDirectoryName = dependenciesDirectoryName,
130-
OutputPath = outputDirectoryName
127+
OutputPath = outputDirectoryName,
128+
Way = ObfuscationNeedsWay.Readline
131129
};
132130
}
133131

134132
private string GetFileName(string[] args)
135133
{
136134
string? file = null;
137-
if (args.IsEmpty() == false)
135+
if (!args.IsEmpty())
138136
{
139137
file = PathFormatterUtility.Format(args[0]);
140138
}

0 commit comments

Comments
 (0)