CI: Cabal: upd (#113)

- update the Cabal repo before build
- chache the results
  - the hack for GitHub expressions was invented
- name the steps
- add SDist check
- Cabal build checks now required

Added the info to the: https://markkarpov.com/post/github-actions-for-haskell-ci.html

I'd maybe wished to switch to `haskell-ci`, but currently it lacks caching for example, idk if it has any monorepo support.
This commit is contained in:
Anton Latukha 2021-01-12 20:16:50 +02:00 committed by GitHub
parent 012713dae9
commit 851bb2e390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 47 deletions

View File

@ -8,13 +8,14 @@ on:
schedule: schedule:
- cron: "45 02 * * *" - cron: "45 02 * * *"
env:
cabalConfig: --enable-tests --disable-optimization --enable-deterministic
jobs: jobs:
build10: build10:
name: "GHC" name: "GHC"
runs-on: ubuntu-latest runs-on: ubuntu-latest
continue-on-error: true
strategy: strategy:
matrix: matrix:
packageRoot: [ hnix-store-core, hnix-store-remote ] packageRoot: [ hnix-store-core, hnix-store-remote ]
@ -23,30 +24,56 @@ jobs:
run: run:
working-directory: "./${{ matrix.packageRoot }}" working-directory: "./${{ matrix.packageRoot }}"
steps: steps:
- uses: actions/checkout@v2
- name: "Cache of ~/.cabal/packages, ~/.cabal/store and dist-newstyle" - name: "Git checkout"
uses: actions/checkout@v2
with:
submodules: recursive
- name: "Haskell env setup"
id: HaskEnvSetup
uses: haskell/actions/setup@v1
with:
ghc-version: ${{ matrix.ghc }}
- name: "Repository update"
run: cabal v2-update
- name: "Install additional system packages"
run: sudo apt install libsodium-dev && cabal v2-install tasty-discover
# Still required for Remote
- name: "Install Nix"
uses: cachix/install-nix-action@v12
if: matrix.packageRoot == 'hnix-store-remote'
# Remote: Enabling testsuite, because it requires networking in the default Nix environment.
- name: "Project-specific Cabal configuration"
if: matrix.packageRoot == 'hnix-store-remote'
run: echo "cabalConfig=$cabalConfig -f io-testsuite" >> $GITHUB_ENV
# NOTE: Freeze is for the caching
- name: "Configuration freeze"
run: cabal v2-freeze $cabalConfig
- name: "Copy freeze file to the root dir"
run: cp -a cabal.project.freeze ../cabal.project.freeze
- name: "Configuring GitHub cache"
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: | path: |
~/.cabal/packages ${{ steps.HaskEnvSetup.outputs.cabal-store }}
~/.cabal/store
dist-newstyle dist-newstyle
key: "${{ runner.os }}-Cabal-${{ matrix.ghc }}" key: ${{ matrix.packageRoot }}-${{ runner.os }}-Cabal-${{ matrix.ghc }}-${{ hashFiles( 'cabal.project.freeze' ) }}
- uses: haskell/actions/setup@v1 restore-keys: ${{ matrix.packageRoot }}-${{ runner.os }}-Cabal-${{ matrix.ghc }}-
with:
ghc-version: ${{ matrix.ghc }} - name: "Build"
- name: "Install additional system packages" run: cabal v2-build $cabalConfig
run: sudo apt install libsodium-dev
- run: cabal v2-install tasty-discover - name: "Tests"
- name: "Install Nix" run: cabal v2-test $cabalConfig
# Still required for Store-remote test suite run
uses: cachix/install-nix-action@v12 - name: "Source distribution file"
if: matrix.packageRoot == 'hnix-store-remote' if: ${{ matrix.ghc == '8.10' }}
- run: cabal v2-configure --disable-optimization --enable-tests --enable-deterministic run: cabal v2-sdist
if: matrix.packageRoot == 'hnix-store-core'
- run: |
cabal v2-configure --disable-optimization --enable-tests --enable-deterministic \
-f io-testsuite # Enable the Store-remote test suite
if: matrix.packageRoot == 'hnix-store-remote'
- run: cabal v2-build
- run: cabal v2-test

View File

@ -5,6 +5,9 @@ on:
# created: a draft is saved, or a release or pre-release is published without previously being saved as a draft # created: a draft is saved, or a release or pre-release is published without previously being saved as a draft
types: [ created ] types: [ created ]
env:
cabalConfig: --enable-tests --disable-optimization --enable-deterministic
jobs: jobs:
build10: build10:
@ -20,32 +23,52 @@ jobs:
run: run:
working-directory: "./${{ matrix.packageRoot }}" working-directory: "./${{ matrix.packageRoot }}"
steps: steps:
- uses: actions/checkout@v2
- name: "Git checkout"
uses: actions/checkout@v2
with: with:
submodules: recursive submodules: recursive
- name: Cache of ~/.cabal/packages, ~/.cabal/store and dist-newstyle
- name: "Haskell env setup"
id: HaskEnvSetup
uses: haskell/actions/setup@v1
with:
ghc-version: ${{ matrix.ghc }}
- name: "Repository update"
run: cabal v2-update
- name: "Install additional system packages"
run: sudo apt install libsodium-dev && cabal v2-install tasty-discover
# Still required for Remote
- name: "Install Nix"
uses: cachix/install-nix-action@v12
if: matrix.packageRoot == 'hnix-store-remote'
# Remote: Enabling testsuite, because it requires networking in the default Nix environment.
- name: "Project-specific Cabal configuration"
if: matrix.packageRoot == 'hnix-store-remote'
run: echo "cabalConfig=$cabalConfig -f io-testsuite" >> $GITHUB_ENV
# NOTE: Freeze is for the caching
- name: "Configuration freeze"
run: cabal v2-freeze $cabalConfig
- name: "Copy freeze file to the root dir"
run: cp -a cabal.project.freeze ../cabal.project.freeze
- name: "Configuring GitHub cache"
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: | path: |
~/.cabal/packages ${{ steps.HaskEnvSetup.outputs.cabal-store }}
~/.cabal/store
dist-newstyle dist-newstyle
key: ${{ runner.os }}-Cabal-${{ matrix.ghc }} key: ${{ matrix.packageRoot }}-${{ runner.os }}-Cabal-${{ matrix.ghc }}-${{ hashFiles( 'cabal.project.freeze' ) }}
- uses: haskell/actions/setup@v1 restore-keys: ${{ matrix.packageRoot }}-${{ runner.os }}-Cabal-${{ matrix.ghc }}-
with:
ghc-version: ${{ matrix.ghc }} - name: "Build"
- name: "Install additional system packages" run: cabal v2-build $cabalConfig
run: sudo apt install libsodium-dev
- run: cabal v2-install tasty-discover - name: "Tests"
- name: "Install Nix" run: cabal v2-test $cabalConfig
# Still required for Store-remote test suite run
uses: cachix/install-nix-action@v12
if: matrix.packageRoot == 'hnix-store-remote'
- run: cabal v2-configure --disable-optimization --enable-tests --enable-deterministic
if: matrix.packageRoot == 'hnix-store-core'
- run: |
cabal v2-configure --disable-optimization --enable-tests --enable-deterministic \
-f io-testsuite # Enable the Store-remote test suite
if: matrix.packageRoot == 'hnix-store-remote'
- run: cabal v2-build
- run: cabal v2-test