Maxime Mangel

EasyBuild: build scripts and releases in F#

On this page
  1. The packages
  2. A build project
  3. Typed paths
  4. Helpers for the tools
  5. From commit to package
  6. Commit
  7. Prepare the release
  8. Pack
  9. Publish
  10. Links

EasyBuild is a set of F# tools I maintain for building and releasing .NET and Fable projects.

You write the build as an F# console project, with typed paths and helpers for the tools it calls. The version number and the changelog come from your commit messages.

The packages

PackageKindWhat it does
EasyBuild.FileSystemProviderType providersTyped paths to the files and folders of your project
EasyBuild.ToolsLibraryF# helpers for dotnet, Fable, npm, Vite, Git and other CLI tools
EasyBuild.CommitLinter.NET toolChecks that commit messages follow Conventional Commits (feat: ..., fix: ...)
EasyBuild.CommitParserLibraryParses commit messages for the other tools, with clear error messages
EasyBuild.ShipIt.NET toolComputes versions, writes changelogs and opens the release pull request
EasyBuild.PackageReleaseNotes.TasksMSBuild tasksSets the package version and release notes from CHANGELOG.md

A build project

Most EasyBuild repositories build with a console application in a build/ folder, started by a small script:

build.sh
#!/bin/sh -x

dotnet tool restore
dotnet run --project build/EasyBuild.fsproj -- $@

./build.sh test runs the test command of that project, and ./build.sh release the release command.

Typed paths

EasyBuild.FileSystemProvider is a type provider: it reads the folders of your project at compile time and turns them into a type. A path that does not exist is a compile error:

build/Workspace.fs
[<Literal>]
let root = __SOURCE_DIRECTORY__ + "/../"

type Workspace = RelativeFileSystem<root>

type VirtualWorkspace =
    VirtualFileSystem<
        root,
        """
src
    bin/
demo
    dist/
"""
     >

Workspace reads the folders on disk. VirtualWorkspace describes folders that are not tracked in the repository, like build output.

Helpers for the tools

EasyBuild.Tools wraps the CLI tools a build calls. This is part of the release command of EasyBuild.ShipIt's own build:

build/Commands/Release.fs
if Directory.Exists VirtualWorkspace.src.bin.``.`` then
    Directory.Delete(VirtualWorkspace.src.bin.``.``, true)

let nupkgPath = DotNet.pack Workspace.src.``.``

DotNet.nugetPush nupkgPath

DotNet.nugetPush reads the API key from the NUGET_KEY environment variable when you do not pass one.

From commit to package

In the EasyBuild.ShipIt repository, a change goes through these steps:

  1. Commit

    A Git hook, installed with Husky.Net, runs CommitLinter on each commit message:

    Terminal
    dotnet husky add commit-msg -c 'dotnet commit-linter "$1"'
    
  2. Prepare the release

    On each push to main, CI runs the tests, then ShipIt computes the next version, writes the CHANGELOG.md entry and opens a release pull request.

  3. Pack

    When that pull request is merged, CI runs ./build.sh release: the tests, then dotnet pack. PackageReleaseNotes.Tasks reads the latest entry of CHANGELOG.md and sets Version, PackageVersion and PackageReleaseNotes. When the changelog is not next to the project file, point to it:

    src/EasyBuild.ShipIt.fsproj
    <PropertyGroup>
        <ChangelogFile>$(MSBuildThisFileDirectory)../CHANGELOG.md</ChangelogFile>
    </PropertyGroup>
    
  4. Publish

    The build pushes the package to NuGet. The workflow gets a temporary API key through NuGet Trusted Publishing and passes it as NUGET_KEY.

You can use each package on its own. FileSystemProvider is useful in any F# script that handles paths, and PackageReleaseNotes.Tasks works with a changelog you write yourself.

More on EasyBuild

Want your build in typed F#?

I can move your build to a typed F# project and automate your releases.

Write to me