Skip to content

feat: replace Bash to C# Batch #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 74 commits into from
Feb 18, 2025
Merged

feat: replace Bash to C# Batch #96

merged 74 commits into from
Feb 18, 2025

Conversation

guitarrapc
Copy link
Contributor

@guitarrapc guitarrapc commented Dec 11, 2024

tl;dr;

Cysharp Actions were previously written in Bash. While Bash is a GitHub Actions-friendly way to write lightweight logic, it became too complicated for us. This PR rewrites the Bash script using C# with Zx. We believe this change fits to us.

Bash

Bash has many benefits as it is a powerful shell:

  • Easy to call processes and handle exit codes.
  • Simple syntax for single line command execution.
  • Bash has plenty of syntax for handling files and processes.

Bash also has its difficulties due to its flexibility:

  • Everyone has their own style of coding for loops, branching, string interpolation, setting variables, naming variables, and file handling.
  • Loop inputs should use while read -r item; do ...; done <<< "${line_separated_string}" for better handling. I just need a simple split by end-of-line and loop through it.
  • Requires regex match like "foo.nupkg" == *.nupkg. I just need to match the file extension.
  • It is better to split action steps for more readability and debuggability. I prefer not to split steps if possible.

C# & Zx

To move from Bash to C#, we use Zx by ProcessX and ConsoleAppFramework. Change to C# make us easy to write unit tests.

ConsoleAppFramework offers the following:

  • Separate batch commands which are equivalent to bash steps. Also, it can consolidate multiple steps into a single command.
  • Parameter binding from GitHub Actions like foo-command --parameter value1 --array "ele1 ele2 ele3" --boolean-true, to typed C# method parameters public void FooCommand(string parameter, string[] array, bool booleanTrue)

Zx offers the following:

  • Process calling using await string like await $"gh release upload {tag} {file}". This syntax drastically reduces how the process is called.
  • Removes argument string escaping by setting Env.useShell = false.

C# also has difficulties due to Language specific.

  • Need understand C# to update Actions.

Note

Workflow Updates:

Configuration File Updates:

  • .editorconfig: Reorganized file types and added new diagnostic rules for C# standards and analyzer rulesets.

@guitarrapc guitarrapc force-pushed the feature/actions branch 2 times, most recently from faa03e5 to 9962877 Compare December 11, 2024 14:03
@github-actions github-actions bot force-pushed the feature/actions branch 2 times, most recently from c4fb3e8 to f2294c9 Compare December 17, 2024 03:11
@guitarrapc guitarrapc force-pushed the feature/actions branch 3 times, most recently from 0e7834c to 66d8d72 Compare December 17, 2024 10:26
@guitarrapc guitarrapc force-pushed the feature/actions branch 2 times, most recently from 85be070 to 02ca8ab Compare December 18, 2024 07:51
@guitarrapc guitarrapc force-pushed the feature/actions branch 2 times, most recently from 07e03ee to 3b16c1b Compare January 7, 2025 09:37
@guitarrapc guitarrapc force-pushed the feature/actions branch 2 times, most recently from 2428bfe to 4c8f56d Compare January 7, 2025 10:33
@guitarrapc guitarrapc force-pushed the feature/actions branch 4 times, most recently from d5b0c1d to e469a10 Compare January 7, 2025 11:07
@guitarrapc guitarrapc merged commit 9c59077 into main Feb 18, 2025
@guitarrapc guitarrapc deleted the feature/actions branch February 18, 2025 03:56
guitarrapc added a commit that referenced this pull request Feb 19, 2025
guitarrapc added a commit that referenced this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant