GitHubActionsDotNet is a new tool we’ve built to create GitHub Actions with .NET. As we manage more and more repositories and projects, we need a way to automate and create Actions quickly. This project achieves that, and is a stepping stone we are using to automate and govern our repositories and projects. It works by using the models created in a previous project, and serializing, (the process of converting a data object to text), the object into text – in this case yaml!
How to use
To use, add this NuGet Package to your .NET project. It’s .NET Standard 2.0 and supports back to .NET Framework, and forward to .NET 6. In just a few lines of C#, you can create your own GitHub Actions yaml file. For example, a simple script to build and release:
After calling the
Serialize method, it produces this YAML:
We’ve created a number of “helpers”, that create templates for individual steps in an attempt to simplify this process. At the same time, it’s possible to dynamically create nearly any task, and there are lots of examples in the tests. For example, we have an “inception” test, that recreates the action that is used to build and publish this project to NuGet.
We think this will be useful for a variety of different projects. For example, two projects I’m using it in include:
- AzurePipelinesToGitHubActions: A project to convert Azure Pipelines YAML to GitHub Actions YAML
- Dependabot-Configuration-Builder: A project to automate the creation of dependabot configuration files. (Yes! this has dependabot models too!)
- RepoAutomation: A project to create the repo, with everything setup, including .NET projects, actions, dependabot, branch policies, and versioning.