Skip to content
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

Add GITHUB_OUTPUT support #233

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inputs:
required: false
default: 'true'
output:
description: 'Output Type - console (default), file or both.'
description: 'Output Type - console (default), file or both. Also supports github output.'
required: false
default: 'console'
thresholds:
Expand Down
2 changes: 1 addition & 1 deletion src/CodeCoverageSummary/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CommandLineOptions

public bool Indicators => IndicatorsString.Equals("true", StringComparison.OrdinalIgnoreCase);

[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both. Also supports github output", Default = "console")]
public string Output { get; set; }

[Option(longName: "thresholds", Required = false, HelpText = "Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action.", Default = "50 75")]
Expand Down
18 changes: 18 additions & 0 deletions src/CodeCoverageSummary/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ private static int Main(string[] args)
Console.WriteLine(output);
File.WriteAllText($"code-coverage-results.{fileExt}", output);
}
else if (o.Output.Equals("github", StringComparison.OrdinalIgnoreCase))
{
var envFile = Environment.GetEnvironmentVariable("GITHUB_OUTPUT");
if (string.IsNullOrWhiteSpace(envFile))
{
Console.WriteLine("Error: GITHUB_OUTPUT environment variable not set.");
return -2; // error
}

using var writer = new StreamWriter(envFile, append: true, Encoding.UTF8);

writer.WriteLine("badge=" + badgeUrl);
writer.WriteLine("line_rate=" + (summary.LineRate * 100).ToString("0.00"));
writer.WriteLine("branch_rate=" + (summary.BranchRate * 100).ToString("0.00"));
writer.WriteLine("complexity=" + summary.Complexity.ToString("0.00"));
writer.WriteLine("health=" + GenerateHealthIndicator(summary.LineRate));
writer.Flush();
}
else
{
Console.WriteLine("Error: Unknown output type.");
Expand Down