GitHub Actions steps, written in C#.

The whole Actions toolkit, typed, in a run block. No project, no JavaScript, no bash.

.github/workflows/hello.yml
name: Helloon: pushjobs:  hello:    runs-on: ubuntu-latest    steps:      - uses: actions/setup-dotnet@v6        with:          dotnet-version: 11.0.x      - shell: dotnet run --file {0}        run: |          #:sdk ActionsToolkit.Sdk@11.0.0          var actor = GitHubApi.Context.Actor;          Core.Info($"Hello from C#, {actor}!");
#:sdk ActionsToolkit.Sdk brings in

See a workflow run, start to finish.

Three real workflows: the YAML, the trigger, and what the C# step leaves behind on GitHub.

.github/workflows/pr-size.yml
12 linesRuns on pull requests with read access, with .NET 11Collapse 12 linesname: PR size checkon: pull_requestpermissions: pull-requests: readjobs: check: runs-on: ubuntu-latest steps: - uses: actions/setup-dotnet@v6 with: dotnet-version: 11.0.x
- name: Review PR size # No project, no build step: dotnet runs this C# as is. shell: dotnet run --file {0} env: # GitHubApi calls the REST API with this token. GITHUB_TOKEN: ${{ github.token }} run: | #:sdk ActionsToolkit.Sdk@11.0.0 // The event payload, already parsed and typed. var (owner, repo, number) = GitHubApi.Context.Issue; var files = await GitHubApi.CreateClient() .Repos[owner][repo].Pulls[(int)number].Files .GetAsync() ?? []; var changed = files.Sum(file => file.Changes ?? 0); await Core.Summary .AddMarkdownHeading($"{files.Count} files, {changed} lines changed") .AddNewLine() .AddMarkdownList(files .OrderByDescending(file => file.Changes) .Take(5) .Select(file => $"`{file.Filename}` {file.Changes} lines")) .WriteAsync(); if (changed > 500) { // Shows up as a warning annotation on the PR. Core.Warning($"This PR changes {changed} lines. Consider splitting it up."); }
  1. Workflow committed to main

    pr-size.yml · a3f9c21

  2. Pull request #42 opened

    feat: invoice export · on: pull_request

  3. Job check · 2 steps

    1. Set up .NET 11
    2. Review PR size C#Fetches the PR's changed files, totals the lines, writes a summary, and warns over 500.
  4. Review PR size example run
    This PR changes 734 lines. Consider splitting it up.
    Job summary

    12 files, 734 lines changed

    • src/Billing/Invoice.cs 318 lines
    • src/Billing/TaxRules.cs 201 lines
    • tests/InvoiceTests.cs 96 lines

See it run in your own repo.

Three steps, nothing to install locally. GitHub shows you the file before anything is committed.

  1. Create the workflow

    Opens GitHub's editor with .github/workflows/hello.yml filled in. You need write access to the repository.

  2. Commit it

    Choose Commit changes in GitHub's editor. The push trigger starts the first run.

  3. Open the run

    Open the latest Hello from C# run. Its job summary shows your heading, and the step log greets you by name.

    Open workflow runs

    Available after you enter a repository in step 1.

The file GitHub opens for you
.github/workflows/hello.yml
name: Hello from C#on: [push, workflow_dispatch] # every push, or run it by handpermissions:  contents: readjobs:  hello:    runs-on: ubuntu-latest    steps:      - uses: actions/setup-dotnet@v6        with:          dotnet-version: 11.0.x      - name: Run inline C#        # GitHub saves run: as a file ({0}); dotnet runs it.        shell: dotnet run --file {0}        run: |          #:sdk ActionsToolkit.Sdk@11.0.0          var context = GitHubApi.Context;          var (owner, repo) = context.Repo;          // Writes to the step log.          Core.Info($"Hello from C#, {context.Actor}!");          // Renders on the run's summary page.          await Core.Summary              .AddMarkdownHeading("Hello from C#")              .AddNewLine()              .AddRawMarkdown(                  $"Run #{context.RunNumber} of {owner}/{repo}.")              .WriteAsync();
  1. Least privilege Reading the repository is all this needs. Grant more only when a step calls an API that needs it.
  2. .NET 11 SDK File-based apps and #:sdk need .NET 11 or later; setup-dotnet installs it.
  3. A pinned toolkit Restores the SDK from NuGet and brings every module in by name. Always pin an exact version.

Pass values between C# steps.

Each step runs in its own process, so nothing in memory carries over. Values move through step outputs.

.github/workflows/handoff.yml
12 linesRuns on push with read access, with .NET 11Collapse 12 linesname: Handoffon: pushpermissions: contents: readjobs: handoff: runs-on: ubuntu-latest steps: - uses: actions/setup-dotnet@v6 with: dotnet-version: 11.0.x
- name: Set an output id: first # later steps read its outputs by this id shell: dotnet run --file {0} run: | #:sdk ActionsToolkit.Sdk@11.0.0 await Core.SetOutputAsync("message", "Hello from step one"); - name: Read it as an input shell: dotnet run --file {0} env: INPUT_MESSAGE: ${{ steps.first.outputs.message }} run: | #:sdk ActionsToolkit.Sdk@11.0.0 var message = Core.GetInput("message", required: true); Core.Info($"Step two received: {message}");
  1. Step one sets an output. Core.SetOutputAsync writes it to the runner, so it outlives the process.
  2. YAML passes it forward. Step one's message output becomes step two's INPUT_MESSAGE input.
  3. Step two reads it. Core.GetInput("message") picks it up like any action input.
Read it as an inputexample log
Step two received: Hello from step one

Real jobs, in a page of C#.

When a step outgrows its run block, move the C# into a file in .github/scripts unchanged and run it with dotnet run --file. Same directives and modules, plus editor support and #:include for shared helpers.

.github/scripts/test-report.cs
#:sdk ActionsToolkit.Sdk@11.0.0using System.Xml.Linq;using ActionsToolkit.Core;using ActionsToolkit.Exec;// Run the tests, but report before failing the step.await Exec.RunAsync(    "dotnet",    ["test", "--logger", "trx", "--results-directory", "results"],    new ExecOptions { IgnoreReturnCode = true });XNamespace trx = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010";var tests = Directory.GetFiles("results", "*.trx")    .SelectMany(file => XDocument.Load(file).Descendants(trx + "UnitTestResult"))    .ToList();var failures = tests    .Where(test => test.Attribute("outcome")?.Value is "Failed")    .ToList();// Each failure becomes an error annotation on the run page.foreach (var test in failures){    var name = test.Attribute("testName")?.Value;    var message = test.Descendants(trx + "Message").FirstOrDefault()?.Value;    Core.Error(message ?? "Test failed", new AnnotationProperties { Title = name });}var commit = GitHubApi.Context.Sha?[..7];await Core.Summary    .AddMarkdownHeading($"{tests.Count - failures.Count} of {tests.Count} tests passed at {commit}")    .AddNewLine()    .AddMarkdownList(failures.Select(test => $"`{test.Attribute("testName")?.Value}`"))    .WriteAsync();if (failures.Count > 0){    Core.SetFailed($"{failures.Count} tests failed.");}

Turn test failures into annotations on the run page and a pass/fail summary.

ExecCore

.github/workflows/test-report.yml
name: Test reporton: [push, pull_request]permissions:  contents: readjobs:  test:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v7      - uses: actions/setup-dotnet@v6        with:          dotnet-version: 11.0.x      - run: dotnet run --file .github/scripts/test-report.cs

Needs contents: read.

Every toolkit module, with tested samples (opens in a new tab)