Skip to content

sorki/github-actions-dhall

 
 

Repository files navigation

github-actions-dhall

Use Dhall to generate YAML for Github Actions for building Haskell projects.

Fork based on https://github.com/vmchale/github-actions-dhall focusing mainly on haskell-ci.dhall.

github-actions-dhall is self-hosting.

Usage

Copy ci.sh and one of the ci.dhall from examples into your .github/workflows/ directory. example-defaultCi3/ci.dhall and example-defaultCi/ci.dhall are good starting points. Run ci.sh to generate ci.yaml by defaults - you might want to install dhall-yaml before or else the script will try to cabal install it.

Example

Haskell

Store the following in ci.dhall (or use the one provided in this repository):

let haskellCi = https://raw.githubusercontent.com/sorki/github-actions-dhall/main/haskell-ci.dhall

in    haskellCi.generalCi
        haskellCi.defaultCabalSteps
          haskellCi.DhallMatrix::{
            { ghc =
              [ haskellCi.GHC.GHC982
              , haskellCi.GHC.GHC966
              , haskellCi.GHC.GHC948
              ]
            , cabal =
              [ haskellCi.Cabal.Cabal312
              , haskellCi.Cabal.Cabal310
              ]
            , os =
              [ haskellCi.OS.Ubuntu
              , haskellCi.OS.MacOS
              ]
            }
    : haskellCi.CI.Type

Then, generate YAML with dhall-to-yaml-ng --generated-comment --file example-readme/ci.dhall, see also ci.sh

# Code generated by dhall-to-yaml.  DO NOT EDIT.
jobs:
  build:
    name: "GHC ${{ matrix.ghc }}, Cabal ${{ matrix.cabal }}, OS ${{ matrix.os }}"
    "runs-on": "${{ matrix.os }}"
    steps:
    - uses: "actions/checkout@v4"
      with:
        submodules: recursive
    - id: "setup-haskell-cabal"
      uses: "haskell-actions/setup@v2"
      with:
        "cabal-version": "${{ matrix.cabal }}"
        "ghc-version": "${{ matrix.ghc }}"
    - name: Update Hackage repository
      run: cabal update
    - name: cabal.project.local.ci
      run: |
        if [ -e cabal.project.local.ci ]; then
          cp cabal.project.local.ci cabal.project.local
        fi
    - name: freeze
      run: "cabal freeze --enable-tests --enable-benchmarks"
    - uses: "actions/cache@v4"
      with:
        key: "${{ matrix.os }}-${{ matrix.ghc }}-${{ matrix.cabal}}-${{ hashFiles('cabal.project.freeze') }}"
        path: |
          ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
          dist-newstyle
    - name: Install dependencies
      run: "cabal build all --enable-tests --enable-benchmarks --only-dependencies"
    - name: build all
      run: "cabal build all --enable-tests --enable-benchmarks"
    - name: test all
      run: "cabal test all --enable-tests"
    - name: haddock all
      run: cabal haddock all
    strategy:
      matrix:
        cabal:
        - '3.12'
        - '3.10'
        ghc:
        - '9.8.2'
        - '9.6.6'
        - '9.4.8'
        os:
        - "ubuntu-latest"
        - "macos-latest"
name: Haskell CI
'on':
  pull_request: {}
  push: {}

GHC Versions

If the last released GHC version is for example GHC981, it is aliased to latestGHC. The next major release (in our case GHC963) is aliased to defaultGHC. The defaultGHC3 is then a list of defaultGHC and two major releases before it - for our example that is [ defaultGHC, GHC.GHC947, GHC.GHC928 ].

This represents a reasonable maintenance policy of supporting three major releases, not including the latestGHC which is typically in flux until most of the ecosystem ports to it.

Variants

defaultCi

This is a simple build using defaultGHC, latestCabal, Ubuntu (which corresponds to ubuntu-latest) and no matrix. See example-defaultCi/ci.dhall

defaultCi3

This is a matrix build using defaultGHC3. See example-defaultCi3/ci.dhall

Customization

cabal.project.local.ci

If you want to set specific flags or options like -Werror only on CI and not in the local dev environment, you can add cabal.project.local.ci file which is copied to cabal.project.local during workflow run.

Example contents:

flags: +someflag

package somepackage:
  ghc-options:
    -Wunused-packages
    -Wall

Projects that use github-actions-dhall

Development

GHC and Cabal versions

Typically synchronized with an upstream haskell-actions/setup from their versions.json

Prior art

About

Dhall helpers for GitHub Actions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dhall 95.4%
  • Haskell 3.2%
  • Shell 1.4%