Skip to content

Commit

Permalink
Nix to the CI rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
sergv committed Dec 15, 2024
1 parent c4dc738 commit ad6ecb0
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 38 deletions.
74 changes: 36 additions & 38 deletions .github/workflows/haskell-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,61 +87,59 @@ jobs:
cabal test --project-file "$project_file" --constraint "atomic-counter +no-cmm" --test-show-details=direct all
cabal bench --project-file "$project_file" --constraint "atomic-counter +no-cmm" --benchmark-options='--stdev 100 --timeout 100' all
i386:
runs-on: ubuntu-latest
container:
image: i386/ubuntu:bionic
nix-build:
name: Nix build ${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
ghc:
- "8.6"
- "8.8"
- "8.10"
- "9.0"
- "9.2"
- "9.4"
- "9.6"

arch:
- "x86_64-linux"
- "i686-linux"
steps:
- name: Install
run: |
apt-get update -y
apt-get install -y autoconf build-essential zlib1g-dev libgmp-dev curl libncurses5 libtinfo5 libncurses5-dev libtinfo-dev
- uses: actions/checkout@v4

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 BOOTSTRAP_HASKELL_INSTALL_NO_STACK=1 sh
- uses: cachix/install-nix-action@v16

source ~/.ghcup/env
ghcup install ghc --set ${{ matrix.ghc }}
ghcup install cabal latest
- name: GHC version
run: nix develop '.#devShells.${{ matrix.arch }}.ci-shell' --command ghc --version

# This version must stay old enough to remain compatible with the container image.
- uses: actions/checkout@v1
- name: Build atomic-counter with nix
run: nix build -L

- name: Build atomic-counter nix shell
run: nix build -L '.#devShells.${{ matrix.arch }}.ci-shell'

- name: Cabal version
run: |
source ~/.ghcup/env
cabal --version
- name: Unpack
run: |
source ~/.ghcup/env
cabal update
proj_dir="$(pwd)"
nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \
cabal update
nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \
cabal sdist --ignore-project --output-directory ..
cabal sdist --ignore-project --output-directory ..
cd ..
cabal get atomic-counter-*.tar.gz -d default
nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \
cabal get atomic-counter-*.tar.gz -d default
- name: Build & Test default
run: |
source ~/.ghcup/env
cabal update
project_file="$(pwd)/cabal.project.ci"
proj_dir="$(pwd)"
project_file="${proj_dir}/cabal.project.ci"
cd ../default/atomic-counter-*/
cabal build --project-file "$project_file" all
cabal test --project-file "$project_file" --test-show-details=direct all
cabal bench --project-file "$project_file" --benchmark-options='--stdev 100 --timeout 100' all
nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \
cabal build --project-file "$project_file" all
nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \
cabal test --project-file "$project_file" --test-show-details=direct all
nix develop -L "${proj_dir}#devShells.${{ matrix.arch }}.ci-shell" --command \
cabal bench --project-file "$project_file" --benchmark-options='--stdev 100 --timeout 100' all
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
description = "atomic-counter";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-24.11";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
let
overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = hfinal: hprev:
prev.haskell.packageOverrides hfinal hprev // {
atomic-counter = hfinal.callCabal2nix "atomic-counter" ./. { };
};
};
atomic-counter = final.haskell.lib.compose.justStaticExecutables final.haskellPackages.atomic-counter;
};
perSystem = system:
let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
hspkgs = pkgs.haskellPackages;
in
{
devShells = rec {
ci-shell = hspkgs.shellFor {
withHoogle = false;
packages = p: [ p.atomic-counter ];
buildInputs = [
hspkgs.cabal-install
];
};
};
packages = rec {
default = atomic-counter;
atomic-counter = pkgs.atomic-counter;
};
};
in
{ inherit overlay; } // flake-utils.lib.eachSystem ["x86_64-linux" "i686-linux"] perSystem;
}

0 comments on commit ad6ecb0

Please sign in to comment.