GitHub.Actions.Core 9.0.0

dotnet add package GitHub.Actions.Core --version 9.0.0                
NuGet\Install-Package GitHub.Actions.Core -Version 9.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GitHub.Actions.Core" Version="9.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GitHub.Actions.Core --version 9.0.0                
#r "nuget: GitHub.Actions.Core, 9.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GitHub.Actions.Core as a Cake Addin
#addin nuget:?package=GitHub.Actions.Core&version=9.0.0

// Install GitHub.Actions.Core as a Cake Tool
#tool nuget:?package=GitHub.Actions.Core&version=9.0.0                

GitHub.Actions.Core package

To install the GitHub.Actions.Core NuGet package:

<PackageReference Include="GitHub.Actions.Core" Version="[Version]" />

Or use the dotnet add package .NET CLI command:

dotnet add package GitHub.Actions.Core

Get the ICoreService instance

To use the ICoreService in your .NET project, register the services with an IServiceCollection instance by calling AddGitHubActionsCore and then your consuming code can require the ICoreService via constructor dependency injection.

using Microsoft.Extensions.DependencyInjection;
using Actions.Core;
using Actions.Core.Extensions;

using var provider = new ServiceCollection()
    .AddGitHubActionsCore()
    .BuildServiceProvider();

var core = provider.GetRequiredService<ICoreService>();

GitHub.Actions.Core

This was modified, but borrowed from the core/README.md.

Core functions for setting results, logging, registering secrets and exporting variables across actions

Using declarations

global using Actions.Core;
Inputs/Outputs

Action inputs can be read with GetInput which returns a string or GetBoolInput which parses a bool based on the yaml 1.2 specification. If required is false, the input should have a default value in action.yml.

Outputs can be set with SetOutputAsync which makes them available to be mapped into inputs of other actions to ensure they are decoupled.

var myInput = core.GetInput("inputName", new InputOptions(true));
var myBoolInput = core.GetBoolInput("boolInputName", new InputOptions(true));
var myMultilineInput = core.GetMultilineInput("multilineInputName", new InputOptions(true));
await core.SetOutputAsync("outputKey", "outputVal");
Exporting variables

Since each step runs in a separate process, you can use ExportVariableAsync to add it to this step and future steps environment blocks.

await core.ExportVariableAsync("envVar", "Val");
Setting a secret

Setting a secret registers the secret with the runner to ensure it is masked in logs.

core.SetSecret("myPassword");
PATH manipulation

To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use AddPathAsync. The runner will prepend the path given to the jobs PATH.

await core.AddPathAsync("/path/to/mytool");
Exit codes

You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.

using var provider = new ServiceCollection()
    .AddGitHubActions()
    .BuildServiceProvider();

var core = provider.GetRequiredService<ICoreService>();

try 
{
    // Do stuff
}
catch (Exception ex)
{
  // SetFailed logs the message and sets a failing exit code
  core.SetFailed($"Action failed with error {ex}"");
}
Logging

Finally, this library provides some utilities for logging. Note that debug logging is hidden from the logs by default. This behavior can be toggled by enabling the Step Debug Logs.

using var provider = new ServiceCollection()
    .AddGitHubActions()
    .BuildServiceProvider();

var core = provider.GetRequiredService<ICoreService>();

var myInput = core.GetInput("input");
try
{
    core.Debug("Inside try block");
    
    if (!myInput)
    {
        core.Warning("myInput was not set");
    }
    
    if (core.IsDebug)
    {
        // curl -v https://github.com
    }
    else
    {
        // curl https://github.com
    }
    
    // Do stuff
    core.Info("Output to the actions build log");
    
    core.Notice("This is a message that will also emit an annotation");
}
catch (Exception ex)
{
    core.Error($"Error {ex}, action may still succeed though");
}

This library can also wrap chunks of output in foldable groups.

using var provider = new ServiceCollection()
    .AddGitHubActions()
    .BuildServiceProvider();

var core = provider.GetRequiredService<ICoreService>();

// Manually wrap output
core.StartGroup("Do some function");
SomeFunction();
core.EndGroup();

// Wrap an asynchronous function call
var result = await core.GroupAsync("Do something async", async () =>
{
    var response = await MakeHttpRequestAsync();
    return response
});
Styling output

Colored output is supported in the Action logs via standard ANSI escape codes. 3/4 bit, 8 bit and 24 bit colors are all supported.

Foreground colors:

// 3/4 bit
core.Info("\u001b[35mThis foreground will be magenta");

// 8 bit
core.Info("\u001b[38;5;6mThis foreground will be cyan");

// 24 bit
core.Info("\u001b[38;2;255;0;0mThis foreground will be bright red");

Background colors:

// 3/4 bit
core.Info("\u001b[43mThis background will be yellow");

// 8 bit
core.Info("\u001b[48;5;6mThis background will be cyan");

// 24 bit
core.Info("\u001b[48;2;255;0;0mThis background will be bright red");

Special styles:

core.Info("\u001b[1mBold text");
core.Info("\u001b[3mItalic text");
core.Info("\u001b[4mUnderlined text");

ANSI escape codes can be combined with one another:

core.Info("\u001b[31;46mRed foreground with a cyan background and \u001b[1mbold text at the end");

[!NOTE] Escape codes reset at the start of each line.

core.Info("\u001b[35mThis foreground will be magenta");
core.Info("This foreground will reset to the default");
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0 93 12/20/2024
8.1.1 5,827 9/20/2024
8.1.0 3,917 8/3/2024
8.0.16 4,556 6/11/2024
8.0.15 2,588 5/7/2024
8.0.14 140 4/30/2024
8.0.13 1,552 4/8/2024
8.0.12 220 3/6/2024
8.0.11 269 2/2/2024
8.0.10 135 1/31/2024
8.0.9 133 1/29/2024
8.0.8 119 1/27/2024
8.0.7 116 1/25/2024
8.0.4 139 1/23/2024
8.0.3 6,399 11/26/2023
8.0.2 147 11/26/2023
8.0.1 158 11/22/2023
8.0.0 159 11/18/2023
8.0.0-rc.1.23419.4 275 9/14/2023
0.0.2 2,002 12/7/2022
0.0.1 346 12/1/2022