CI: Run "Run failed tests"-step only if "Run tests"-step failed #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & test in nix-shell | |
on: | |
push: | |
pull_request: | |
jobs: | |
build_test: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-22.04, ubuntu-20.04, macos-13, macos-14] | |
ghc: [ghc865Binary, ghc884, ghc810] | |
cc: [gcc8, gcc14, clang_12, clang_18] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Install Nix | |
uses: cachix/install-nix-action@v25 | |
with: | |
install_url: https://releases.nixos.org/nix/nix-2.20.5/install | |
# NOTE: We avoid using arm64 builds of GHC (because they're mostly broken for early GHC versions) by specifying 'system = x86_64-darwin' for macOS runners | |
extra_nix_config: | | |
substituters = https://cache.nixos.org https://cache.iog.io | |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= | |
system-features = benchmark big-parallel kvm nixos-test | |
${{ startsWith(matrix.os, 'macos') && 'system = x86_64-darwin' || '' }} | |
- name: Cache cabal files | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cabal/packages | |
~/.cabal/store | |
dist-newstyle | |
key: ${{ runner.os }}-${{ matrix.os }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze') }}--${{ matrix.ghc }} | |
restore-keys: ${{ runner.os }}-${{ matrix.os }}- | |
# Make nix-shell use specific Bash version. | |
# Cf. https://nixos.org/manual/nix/stable/command-ref/nix-shell#environment-variables. | |
- name: Set shell Bash | |
run: echo "NIX_BUILD_SHELL=$(nix-build -A bash .github/workflows/bash.nix)/bin/bash" >> $GITHUB_ENV | |
- name: Test nix-shell # test that the Nix shell actually works | |
run: nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run 'echo $PATH; ls -l $(which ghc); ls -l $(which cabal); ghc --version; cabal --version; type cabal' | |
- name: Export GHC version env var | |
run: echo "GHC_VERSION=$(nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run 'ghc --numeric-version')" >> $GITHUB_ENV | |
- name: Run 'cabal update' | |
run: nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run 'cabal update' | |
- name: Build library | |
run: nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run 'cabal build lib:packman' | |
- name: Build tests | |
run: nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run 'cabal build --enable-tests' | |
# NOTE: Ignores failures caused by https://github.com/jberthold/packman/issues/18. | |
# It's not very useful to have failing CI on the master branch, since it makes us miss newly introduced bugs. Therefore, we ignore this known error, while failing in case of other errors in the same test suite or failure of other test suites. | |
# The condition in human-readable terms is: (all_tests_succeeded || testmthread_logs_contain_issue18_error_string) && other_test_suites_did_not_fail | |
# The condition "other_test_suites_did_not_fail" is tested by asserting that no log files exist that fit the "*-test-fail.log" pattern while excluding the log file of the "testmthread" test suite (testmthread-test-fail.log). | |
# TODO: Revert this change once that issue is fixed. | |
- name: Run tests | |
id: run_tests | |
run: | | |
mkdir ci-logs | |
nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run '(cabal test --test-log="$(pwd)/ci-logs/\$test-suite-test-\$result.log" || grep "testmthread: Contains an unsupported closure type (whose implementation is missing)" ci-logs/testmthread-test-fail.log) && (! find ci-logs ! -name testmthread-test-fail.log -name "*-test-fail.log"|grep .)' | |
- name: Print output of failed tests | |
if: ${{ failure() && steps.run_tests.conclusion == 'failure' }} | |
run: nix-shell --argstr ghcVersion ${{ matrix.ghc }} --argstr ccVersion ${{ matrix.cc }} --run 'tail -v -n +1 ci-logs/*-test-fail.log' |