Skip to content

Commit

Permalink
use nix
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Dec 12, 2023
1 parent a090d5a commit c084594
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 267 deletions.
148 changes: 0 additions & 148 deletions .github/bin/haddocks.sh

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/cabal.project.local.github-pages

This file was deleted.

137 changes: 29 additions & 108 deletions .github/workflows/github-page.yml
Original file line number Diff line number Diff line change
@@ -1,141 +1,62 @@
name: "Haddock documentation"

on:
pull_request: # REMOVEME
pull_request: # removeme
push:
branches:
- main

jobs:
build:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest

defaults:
run:
shell: bash

strategy:
fail-fast: false
matrix:
ghc: ["9.2.7"]
cabal: ["3.10.1.0"]
os: [ubuntu-latest]

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2023-12-12"

concurrency:
group: >
a+${{ github.event_name }}
b+${{ github.workflow_ref }}
c+${{ github.job }}
d+${{ matrix.ghc }}
e+${{ matrix.cabal }}
f+${{ matrix.os }}
g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }}
cancel-in-progress: true

steps:
- name: Concurrency group
run: >
echo
a+${{ github.event_name }}
b+${{ github.workflow_ref }}
c+${{ github.job }}
d+${{ matrix.ghc }}
e+${{ matrix.cabal }}
f+${{ matrix.os }}
g+${{ (startsWith(github.ref, 'refs/heads/gh-readonly-queue/') && github.run_id) || github.event.pull_request.number || github.ref }}
- name: Install Haskell
uses: input-output-hk/actions/haskell@latest
id: setup-haskell
- name: Install Nix
uses: cachix/install-nix-action@v18
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- name: Install system dependencies
uses: input-output-hk/actions/base@latest
with:
use-sodium-vrf: true # default is true
# Use last stable nixos channel and the same nix as in channel:
install_url: https://releases.nixos.org/nix/nix-2.11.1/install
nix_path: nixpkgs=channel:nixos-22.11
github_access_token: ${{ secrets.GITHUB_TOKEN }}
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
experimental-features = nix-command flakes
allow-import-from-derivation = true
substituters = https://cache.nixos.org https://cache.iog.io
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
- uses: actions/checkout@v3

- name: Cabal update
run: cabal update

- name: Disable all tests
- name: Fetch nix cache and update cabal indices
run: |
cat > cabal.project.local <<EOF
tests: False
EOF
nix develop .\#haddockShell --command \
cabal update
- name: Build dry run
run: cabal build all --dry-run --minimize-conflict-set

- name: Dry run
- name: Build whole project
run: |
cabal build all --dry-run
mkdir ./haddocks
DRY_RUN=1 ./.github/bin/haddocks.sh ./haddocks true
# For users who fork cardano-cli and want to define a writable cache, then can set up their own
# S3 bucket then define in their forked repository settings the following secrets:
#
# CACHE_AWS_ACCESS_KEY_ID
# CACHE_AWS_SECRET_ACCESS_KEY
# CACHE_URI
# CACHE_AWS_REGION
- name: Cabal cache over S3
uses: action-works/cabal-cache-s3@v1
env:
AWS_ACCESS_KEY_ID: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
with:
region: ${{ vars.CACHE_AWS_REGION }}
dist-dir: dist-newstyle
store-path: ${{ steps.setup-haskell.outputs.cabal-store }}
threads: ${{ vars.CACHE_THREADS }}
archive-uri: ${{ vars.CACHE_URI }}/${{ env.CABAL_CACHE_VERSION }}/${{ runner.os }}/${{ matrix.cabal }}/${{ matrix.ghc }}
skip: "${{ vars.CACHE_URI == '' }}"
nix develop .\#haddockShell --command \
cabal build all
# It's important to ensure that people who fork this repository can not only successfully build in
# CI by default, but also have meaning cabal store caching.
#
# Because syncing with S3 requires credentials, we cannot rely on S3 for this. For this reason a
# https fallback is used. The https server mirrors the content of the S3 bucket. The https cabal
# store archive is read-only for security reasons.
#
# Users who fork this repository who want to have a writable cabal store archive are encouraged
# to set up their own S3 bucket.
- name: Cabal cache over HTTPS
uses: action-works/cabal-cache-s3@v1
with:
dist-dir: dist-newstyle
store-path: ${{ steps.setup-haskell.outputs.cabal-store }}
threads: 16
archive-uri: https://iohk.cache.haskellworks.io/${{ env.CABAL_CACHE_VERSION }}/${{ runner.os }}/${{ matrix.cabal }}/${{ matrix.ghc }}
skip: "${{ vars.CACHE_URI != '' }}"
enable-save: false

- name: Install dependencies
run: cabal build all

- name: Build Haddock documentation 🔧
run: ./.github/bin/haddocks.sh ./haddocks true
- name: Build documentation
run: |
nix develop .\#haddockShell --command \
cabal haddock-project --local --output=./haddocks --internal --foreign-libraries --executables
- name: View HTML files
- name: Compress haddocks
run: |
find "dist-newstyle/build" -name '*.html' | xargs grep html
tar -czf haddocks.tgz -C haddocks .
- name: Upload documentation
- name: Upload haddocks artifact
uses: actions/upload-artifact@v2
if: ${{ always() }}
continue-on-error: true
with:
name: haddocks-${{ matrix.os }}-${{ matrix.ghc }}
path: ./haddocks
name: haddocks
path: ./haddocks.tgz

- name: Deploy documentation to gh-pages 🚀
# if: github.ref == 'refs/heads/main' # FIXME
Expand Down
15 changes: 12 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

# see flake `variants` below for alternative compilers
defaultCompiler = "ghc928";
haddockShellCompiler = "ghc963";
# We use cabalProject' to ensure we don't build the plan for
# all systems.
cabalProject = nixpkgs.haskell-nix.cabalProject' ({config, ...}: {
Expand Down Expand Up @@ -154,7 +155,7 @@
# This ensure hydra send a status for the required job (even if no change other than commit hash)
revision = nixpkgs.writeText "revision" (inputs.self.rev or "dirty");
};
};
} // { haddockShell = devShells.haddockShell; };
legacyPackages = rec {
inherit cabalProject nixpkgs;
# also provide hydraJobs through legacyPackages to allow building without system prefix:
Expand All @@ -163,12 +164,20 @@
cardano-cli = cabalProject.hsPkgs.cardano-cli.components.exes.cardano-cli;
};
devShells = let
profillingShell = p: {
profilingShell = p: {
# `nix develop .#profiling` (or `.#ghc927.profiling): a shell with profiling enabled
profiling = (p.appendModule {modules = [{enableLibraryProfiling = true;}];}).shell;
};
in
profillingShell cabalProject;
profilingShell cabalProject
# Add GHC 9.6 shell for haddocks
//
{ haddockShell = let
p = cabalProject.appendModule {compiler-nix-name = haddockShellCompiler;};
in
p.shell // (profilingShell p);
};

# formatter used by nix fmt
formatter = nixpkgs.alejandra;
}
Expand Down

0 comments on commit c084594

Please sign in to comment.