Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xoascf committed Sep 24, 2023
1 parent ccb4cec commit 315db19
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 188 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI
on:
push:
branches: [master]
paths-ignore: ["**.adoc"]
pull_request:
paths-ignore: ["**.adoc"]
workflow_dispatch:
jobs:
build:
permissions: write-all
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux-x64, win-x64]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: Build console app
run: dotnet publish OTRMod.CLI/OTRMod.CLI.csproj -r ${{ matrix.os }} -f net6.0 -c Release -p:PublishSingleFile=true -p:DebugType=None -p:DebugSymbols=false --no-self-contained

- name: Set output path
run: |
echo "EXE_NAME=OTRMod.CLI${{ contains(matrix.os, 'win') && '.exe' || '' }}" >> $GITHUB_ENV
echo "EXE_PATH=OTRMod.CLI/bin/Release/net6.0/${{ matrix.os }}/publish" >> $GITHUB_ENV
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: OTRMod.CLI-${{ matrix.os }}
path: ${{ env.EXE_PATH }}/${{ env.EXE_NAME }}

- name: Upload release
if: github.event_name == 'push' && startsWith(github.event.head_commit.message, 'Release v')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
OWNER: ${{ github.event.repository.owner.login }}
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
curl -Ls https://gist.githubusercontent.com/xoascf/525b58c632818bfaf705f373ce6be8a5/raw | sh -s \
$OWNER \
$REPOSITORY_NAME \
"$(echo "$COMMIT_MESSAGE" | cut -d " " -f2)" \
$GITHUB_TOKEN \
$EXE_PATH/$EXE_NAME \
$EXE_NAME \
application/octet-stream
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
global using System.IO;
global using MemStream = System.IO.MemoryStream;
global using Con = System.Console;
global using static OTRMod.Console.Helper;
global using static OTRMod.CLI.Helper;
58 changes: 42 additions & 16 deletions OTRMod.Console/Helper.cs → OTRMod.CLI/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
/* Licensed under the Open Software License version 3.0 */

#if NETCOREAPP1_0_OR_GREATER
using System.Runtime;
#endif
using System.Text.RegularExpressions;

namespace OTRMod.Console;
namespace OTRMod.CLI;

internal static class Helper {
internal static void Exit(int code) {
Con.Write("Goodbye!"); Environment.Exit(code);
Con.WriteLine("Exiting...");
Environment.Exit(code);
}

#if NETCOREAPP1_0_OR_GREATER
internal static void CompactAndCollect() {
GCSettings.LargeObjectHeapCompactionMode =
GCLargeObjectHeapCompactionMode.CompactOnce;
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect();
}
#endif

internal static string ReadPath
(string name, string fallback = "", bool checkIfExists = true) {
internal static string ReadPath(string name, string fallback = "", bool checkIfExists = true) {
string? path;
do {
if (!string.IsNullOrWhiteSpace(fallback))
name += $" (default: {fallback})";

Con.Write($"{name}: ");
path = Con.ReadLine();
if (string.IsNullOrWhiteSpace(path)) path = fallback;
if (string.IsNullOrWhiteSpace(path))
path = fallback;

} while (string.IsNullOrWhiteSpace(path));

if (path.StartsWith("\"") && path.EndsWith("\""))
Expand All @@ -49,23 +55,27 @@ internal static bool AnsweredYesTo(string question) {
|| res.StartsWith("y", StringComparison.OrdinalIgnoreCase);
}

internal static string? GetArg(this string[] args, string argMain, string argAlt) {
int argIndex = Array.IndexOf(args, argMain);
if (argIndex == -1) argIndex = Array.IndexOf(args, argAlt);
internal static string? GetIfExists(this string[] array, int index) {
return array.Length > index ? array[index] : null;
}

int nextPos = argIndex + 1;
if (argIndex != -1 && args.Length > nextPos)
return args[nextPos];
internal static int GetArgIndex(this string[] args, string argMain, char argAlt) {
int argIndex = Array.IndexOf(args, $"--{argMain}");

return null;
return argIndex == -1 ? Array.IndexOf(args, $"-{argAlt}") : argIndex;
}

internal static string? GetArg(this string[] args, string argMain, char argAlt) {
int argIndex = args.GetArgIndex(argMain, argAlt);

return argIndex != -1 ? args.GetIfExists(argIndex + 1) : null;
}

internal static char[] GetInvalidChars() {
return new char[] { '<', '>', '|', ':', '*', '?' };
}

internal static readonly string
InvalidCharsPattern = $"[{Regex.Escape(new string(GetInvalidChars()))}]";
internal static readonly string InvalidCharsPattern = $"[{Regex.Escape(new string(GetInvalidChars()))}]";

internal static string EncodePath(string path) {
return Regex.Replace(path, InvalidCharsPattern, m => {
Expand All @@ -87,4 +97,20 @@ internal static string DecodePath(string path) {
return m.Value;
});
}

internal static void Save(this Stream s, string path) {
string? dir = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(dir))
Directory.CreateDirectory(dir);

using FileStream fs = new(path, FileMode.OpenOrCreate);
_ = s.Seek(0, SeekOrigin.Begin);
s.CopyTo(fs);
fs.Flush();
fs.Close();
}

internal static void Warn(string issue, int line, string file) {
Con.WriteLine($"::warning file={file},line={line}::{issue}");
}
}
File renamed without changes.
Loading

0 comments on commit 315db19

Please sign in to comment.