From b3221a1b62cd8d5dc1af8536c56690f8e95e1dc0 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 8 Jan 2025 15:13:14 +0900
Subject: [PATCH] chore: escape string
---
src/Actions/Program.cs | 65 ++++++++++++++++++++--
src/Actions/Properties/launchSettings.json | 17 ++++++
2 files changed, 76 insertions(+), 6 deletions(-)
diff --git a/src/Actions/Program.cs b/src/Actions/Program.cs
index 32aa8acf..7bc956f0 100644
--- a/src/Actions/Program.cs
+++ b/src/Actions/Program.cs
@@ -3,6 +3,7 @@
using Actions.Contexts;
using Actions.Utils;
using Cysharp.Diagnostics;
+using System.Diagnostics;
using System.Runtime.CompilerServices;
var app = ConsoleApp.Create();
@@ -144,6 +145,27 @@ public void CreateDummy(string basePath)
WriteLog($"Completed ...");
}
+ ///
+ /// debug command
+ ///
+ ///
+ [Command("debug")]
+ public async Task Debug()
+ {
+ var str = "git commit -a -m \"feat: Update package.json to 1.0.0\n\nCommit by [GitHub Actions](https://github.com/Actions/actions/runs/11350100787)\"";
+ var (command, argument) = ParseCommand(str);
+ var startInfo = new ProcessStartInfo(command, argument!);
+ using var process = Process.Start(startInfo);
+ process!.WaitForExit();
+ await foreach (var item in ProcessX.StartAsync(str))
+ {
+ Console.WriteLine(item);
+ }
+
+ //// Zx run with `shell + "\"" + command + "\""`, there fore we need double escape for innner quote.
+ //var result = await $"{EscapeCommand(str)}";
+ }
+
///
/// Git Commit
///
@@ -161,24 +183,25 @@ private async Task GitCommitAsync(bool dryRun, string tag, string email = "41898
try
{
var result = await "git diff --exit-code";
- WriteLog("There is no git diff.");
+ WriteLog("There is no git diff, skipping commit");
}
catch (ProcessErrorException)
{
WriteLog("Detected git diff.");
if (dryRun)
{
- WriteLog("Dryrun Mode detected, creating branch switch to.");
- await $"git switch -c test-release/{tag}";
+ WriteLog("Dryrun Mode detected, creating branch and switch.");
branchName = $"test-release/{tag}";
isBranchCreated = "true";
+ await $"git switch -c {branchName}";
}
- var commitMessage = $"Update package.json to {tag}\n\nCommit by [GitHub Actions]({GitHubContext.GetWorkflowRunUrl(GitHubContext.Current)})";
- WriteLog("Committing change.");
+ var commitMessage = $"feat: Update package.json to {tag}\n\nCommit by [GitHub Actions]({GitHubContext.GetWorkflowRunUrl(GitHubContext.Current)})";
+ WriteLog("Committing change. Running following.");
+ WriteLog($"git commit -a -m \"{commitMessage}\"");
await $"git config --local user.email \"{email}\"";
await $"git config --local user.name \"{user}\"";
- await $"git commit -a -m \"{commitMessage}\"";
+ await $"git commit -a -m \"{EscapeCommandArgString(commitMessage)}\"";
commited = "1";
}
@@ -190,8 +213,38 @@ private async Task GitCommitAsync(bool dryRun, string tag, string email = "41898
}
+ private static (string fileName, string? arguments) ParseCommand(string command)
+ {
+ int num = command.IndexOf(' ');
+ if (num == -1)
+ {
+ return (command, null);
+ }
+ string item = command.Substring(0, num);
+ string item2 = command.Substring(num + 1, command.Length - (num + 1));
+ return (item, item2);
+ }
+
#pragma warning restore CA1822 // Mark members as static
+ ///
+ /// Escape command by adding \" on each side if needed.
+ /// ex. who will be...
+ /// * Windows: who
+ /// * Linux/macOS: \"who\"
+ ///
+ ///
+ ///
+ private static string EscapeCommandArgString(string command)
+ {
+ // Windows don't need escape (Windows escape is differ from Linux/macOS)
+ if (OperatingSystem.IsWindows())
+ return command;
+
+ // Bash need escape
+ return "\"" + command + "\"";
+ }
+
private static string OutputFormat(string key, string value, OutputFormatType format) => format switch
{
OutputFormatType.Console => value,
diff --git a/src/Actions/Properties/launchSettings.json b/src/Actions/Properties/launchSettings.json
index 1bc11615..a24eae66 100644
--- a/src/Actions/Properties/launchSettings.json
+++ b/src/Actions/Properties/launchSettings.json
@@ -70,6 +70,23 @@
"create-dummy (init)": {
"commandName": "Project",
"commandLineArgs": "create-dummy --base-path dummy/"
+ },
+ // WSL
+ "WSL": {
+ "commandName": "WSL2"
+ },
+ "WSL (update-version)": {
+ "commandName": "WSL2",
+ "distributionName": "",
+ "commandLineArgs": "\"{OutDir}/Actions.dll\" update-version --version 1.0.0 --paths ./dummy/package.json,./dummy/plugin.cfg,./dummy/Directory.Build.props",
+ "environmentVariables": {
+ "GITHUB_CONTEXT": "{\"server_url\":\"https://github.com\", \"run_id\":\"11350100787\", \"repository\":\"Actions\", \"repository_owner\":\"Cysharp\", \"event_name\": \"pull_request\"}"
+ }
+ },
+ "WSL (debug)": {
+ "commandName": "WSL2",
+ "distributionName": "",
+ "commandLineArgs": "\"{OutDir}/Actions.dll\" debug"
}
}
}