GitHub.Actions.Octokit 8.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package GitHub.Actions.Octokit --version 8.0.2                
NuGet\Install-Package GitHub.Actions.Octokit -Version 8.0.2                
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.Octokit" Version="8.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GitHub.Actions.Octokit --version 8.0.2                
#r "nuget: GitHub.Actions.Octokit, 8.0.2"                
#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.Octokit as a Cake Addin
#addin nuget:?package=GitHub.Actions.Octokit&version=8.0.2

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

GitHub Actions Workflow .NET SDK

build-and-test code analysis publish nuget NuGet

The .NET equivalent of the official GitHub actions/toolkit @actions/core project.

Blog

🔗 Hello from the GitHub Actions: Core .NET SDK

Usage

Installing the NuGet package 📦

Welcome to the [Actions.Core] .NET SDK. This SDK is used to create GitHub Actions in .NET. The SDK is a thin wrapper around the .NET implementation of the GitHub Actions a select few packages from the @actions/toolkit.

Warning: This package is not an official Microsoft or GitHub product. It is a community-driven project. However, I do choose to use the Actions.Octokit[.*] namespace for the package. I'm not trying to mislead anyone, but I do want to make it clear that this is not an official product.

You'll need to install the GitHub Actions Workflow .NET SDK NuGet package to use the .NET APIs. The package is available on NuGet.org. The following is the command to install the package:

Adding package references

Either add the package reference to your project file:

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

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 AddGitHubActions 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()
    .AddGitHubActions()
    .BuildServiceProvider();

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

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 net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
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
8.1.1 1,530 9/20/2024
8.1.0 2,974 8/3/2024
8.0.16 3,272 6/11/2024
8.0.15 684 5/7/2024
8.0.14 153 4/30/2024
8.0.13 1,544 4/8/2024
8.0.12 209 3/6/2024
8.0.11 270 2/2/2024
8.0.10 135 1/31/2024
8.0.9 132 1/29/2024
8.0.8 111 1/27/2024
8.0.7 116 1/25/2024
8.0.4 141 1/23/2024
8.0.3 6,157 11/26/2023
8.0.2 133 11/26/2023
8.0.1 163 11/22/2023
8.0.0 143 11/18/2023
8.0.0-rc.1.23419.4 269 9/14/2023
1.0.4-rc.1 90 9/14/2023
1.0.3-rc.1 73 9/14/2023
1.0.2-rc.1 90 9/14/2023
1.0.1-rc.1 76 9/13/2023
1.0.0-rc.1 77 9/13/2023