githubEdit

Github Workflows

The DecSm.Atom.Module.GithubWorkflows module provides deep integration with GitHub Actions, enabling you to define, generate, and interact with GitHub workflows directly from your DecSm.Atom build definitions. This module streamlines the process of creating CI/CD pipelines on GitHub Actions, offering C#-based abstractions for common workflow patterns.

Features

  • Workflow Generation: Define GitHub Actions workflows (including Dependabot) in C# and generate the corresponding YAML files.

  • GitHub Environment Access: Easily access GitHub Actions environment variables and context information.

  • Artifact and Publish Path Integration: Automatically adjusts artifact and publish directories to align with GitHub Actions conventions.

  • GitHub Token Management: Simplifies the injection of the GITHUB_TOKEN for API interactions.

  • Release Management Helpers: Provides utilities for uploading artifacts to GitHub Releases.

  • Custom Runner Configuration: Define custom runner images or use matrix strategies for job execution.

  • Step Summary Reporting: Integrates build outcome reporting directly into GitHub Actions step summaries.

  • Expression Building: A fluent API for constructing GitHub Actions expressions (e.g., if conditions, with inputs).

Getting Started

To use the GitHub Workflows module, implement the IGithubWorkflows interface in your build definition. This will configure the necessary services for GitHub Actions integration.

Implementation

Add the IGithubWorkflows interface to your Build.cs file:

using DecSm.Atom.Build.Definition;
using DecSm.Atom.Module.GithubWorkflows;

namespace Atom;

[BuildDefinition]
internal partial class Build : IGithubWorkflows
{
    // Your build targets and other definitions
}

Defining Workflows

You can define GitHub Actions workflows using the WorkflowDefinition class and its associated options.

Example: Basic CI Workflow

When you run your build with this definition, a ci.yml file will be generated in your .github/workflows directory.

Dependabot Workflows

The module provides helpers for generating Dependabot configuration files.

This will generate a dependabot.yml file with default NuGet update settings. You can customize it using Github.DependabotWorkflow(DependabotOptions options).

GitHub Environment Variables

The Github.Variables static class provides strongly-typed access to common GitHub Actions environment variables.

GitHub Token and Release Management

The IGithubHelper and IGithubReleaseHelper interfaces provide functionality for interacting with GitHub.

Injecting GitHub Token

Implement IGithubHelper to make the GITHUB_TOKEN available:

You can then use this.GithubToken in your build logic to authenticate with the GitHub API. For workflow generation, use the WithGithubTokenInjection() extension:

Uploading to GitHub Releases

Implement IGithubReleaseHelper to upload artifacts to GitHub Releases:

Custom Runner Configuration

You can specify custom runners or use a matrix strategy for your workflow jobs.

You can also specify a custom Docker image for your runner using GithubSnapshotImageOption:

GitHub Actions Expressions

The module provides a fluent API to construct GitHub Actions expressions, which are useful for if conditions, with inputs, and other dynamic parts of your workflow.

This will generate an if condition for the ConditionalStep job that checks if the GITHUB_REF_NAME is "main" AND the GITHUB_EVENT_NAME is "push".

Last updated

Was this helpful?