Skip to content

Commit

Permalink
chore: output handling
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 8, 2025
1 parent 109561e commit e9783c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ jobs:
if [[ "${{ needs.update-packagejson2.outputs.branch-name }}" == "" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson3 should be empty. "
if [[ "${{ needs.update-packagejson3.outputs.branch-name }}" == "" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
env:
HEAD_REF: ${{ github.head_ref }}

cleanup:
if: ${{ needs.update-packagejson.outputs.is-branch-created == 'true' }}
needs: [update-packagejson]
needs: [update-packagejson, update-packagejson3]
uses: ./.github/workflows/clean-packagejson-branch.yaml
with:
branch: ${{ needs.update-packagejson.outputs.branch-name }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ on:
type: boolean
default: true
outputs:
sha:
description: "Git commit sha after package.json has changed."
value: ${{ jobs.update-packagejson.outputs.sha }}
branch-name:
description: Git branch name created.
value: ${{ jobs.update-packagejson.outputs.branch-name }}
is-branch-created:
description: Indicate is Git branch created or not.
value: ${{ jobs.update-packagejson.outputs.is-branch-created }}
sha:
description: "Git commit sha after package.json has changed."
value: ${{ jobs.update-packagejson.outputs.sha }}

jobs:
validate:
Expand Down Expand Up @@ -103,6 +103,6 @@ jobs:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # auto generated token
branch: ${{ inputs.dry-run && steps.update.outputs.branch-name || inputs.ref }}
branch: ${{ steps.update.outputs.branch-name }}
tags: false
force: ${{ inputs.dry-run }}
35 changes: 7 additions & 28 deletions src/Actions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,9 @@ public void CreateDummy(string basePath)
/// </summary>
/// <returns></returns>
[Command("debug")]
public async Task Debug()
public void Debug(string[] foo)
{
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)}";
Console.WriteLine($"--foo {string.Join(",", foo)}");
}

/// <summary>
Expand Down Expand Up @@ -212,19 +201,6 @@ private async Task GitCommitAsync(bool dryRun, string tag, string email = "41898
GitHubOutput("is-branch-created", isBranchCreated);
}


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

/// <summary>
Expand Down Expand Up @@ -270,14 +246,17 @@ private void WriteVerbose(string value)
}
}

private static void GitHubOutput(string key, string value, [CallerMemberName]string? callerMemberName = null)
private void GitHubOutput(string key, string value, [CallerMemberName]string? callerMemberName = null)
{
var input = $"{key}={value}";
var output = Environment.GetEnvironmentVariable("GITHUB_OUTPUT", EnvironmentVariableTarget.Process) ?? Path.Combine(Directory.GetCurrentDirectory(), $"GitHubOutputs/{callerMemberName}");
if (!Directory.Exists(Path.GetDirectoryName(output)))
{
Directory.CreateDirectory(Path.GetDirectoryName(output)!);
}
File.AppendAllLines(output, [$"{key}={value}"]);

WriteLog($"GitHub Output: {input}");
File.AppendAllLines(output, [input]);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/Actions/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"commandName": "Project",
"commandLineArgs": "create-dummy --base-path dummy/"
},
// debug
"debug(multiline)": {
"commandName": "Project",
"commandLineArgs": "debug --foo foo,bar,piyo"
},
// WSL
"WSL": {
"commandName": "WSL2"
Expand Down

0 comments on commit e9783c8

Please sign in to comment.