Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 103 additions & 12 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Haskell-CI

permissions:
contents: read
pull-requests: write

on:
push:
branches:
Expand All @@ -16,30 +20,117 @@ concurrency:

jobs:
linux:
name: Haskell-CI - Linux - ${{ matrix.ghc-version }}
name: Haskell-CI - ${{ matrix.ghc-version }} - ${{ matrix.ref }}

strategy:
matrix:
ghc-version: [latest, 9.12, "9.10", 9.8, 9.6]
os: [ubuntu-24.04]
ghc-version: ["9.12", "9.10", "9.8", "9.6"]
ref: ["${{ github.head_ref }}"]
# This gives us one run for `master` with ghc version 9.12.
# We use this run to give us "up to date" coverage data that
# we can compare to.
include:
- ghc-version: "9.12"
ref: master
fail-fast: false

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

env:
coverage: ${{ github.event.pull_request && (matrix.ghc-version == '9.12') }}

steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.ref }}

- uses: haskell-actions/setup@v2
with:
ghc-version: ${{matrix.ghc-version}}
- uses: actions/cache/restore@v4

- uses: actions/cache@v4
with:
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
path: ~/.cabal/store
restore-keys: ${{ matrix.os }}-${{ matrix.ghc-version }}-
key: ${{ matrix.ghc-version }}-${{ matrix.ref }}
path: |
~/.cabal/store
dist-newstyle
.hpc
restore-keys: ${{ matrix.ghc-version }}-

- if: ${{ env.coverage == 'true' }}
run: |
cat <<EOF >>cabal.project.local
program-options
ghc-options: -fhpc
EOF

- run: cabal build all
- run: cabal test all
- run: cabal haddock all
- uses: actions/cache/save@v4

# To get the right version of `generate-coverage-comment.sh`. I.e. the
# one in this PR. This is important in order to get the same
# coverage-counting logic on the PR as on master.
- uses: actions/checkout@v4
if: ${{ env.coverage == 'true' }}
with:
ref: ${{ github.head_ref }}
sparse-checkout:
scripts
clean: false

- if: ${{ env.coverage == 'true' }}
run: ./scripts/generate-coverage-comment.sh constrained.tix | tee coverage-report-${{matrix.ref}}.md

- name: Upload coverage report
if: ${{ env.coverage == 'true' }}
uses: actions/upload-artifact@v4
with:
name: constrained-${{matrix.ref}}-coverage
path: coverage-report-${{matrix.ref}}.md
if-no-files-found: error
compression-level: 0
retention-days: 1

report:
name: Generate coverage comment

if: github.event.pull_request

needs: linux

runs-on: ubuntu-latest

steps:
- name: Download coverage report
uses: actions/download-artifact@v4
with:
pattern: 'constrained-${{github.head_ref}}-coverage'
merge-multiple: true

- name: Download coverage report from `master`
uses: actions/download-artifact@v4
with:
pattern: 'constrained-master-coverage'
merge-multiple: true

- run: |
cat coverage-report-${{github.head_ref}}.md > coverage-report.md
echo "# On master" >> coverage-report.md
cat coverage-report-master.md >> coverage-report.md
cat coverage-report.md

- name: Find Comment
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: "expressions used"

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
key: ${{ matrix.os }}-${{ matrix.ghc-version }}-${{ github.sha }}
path: ~/.cabal/store
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: coverage-report.md
edit-mode: replace
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ cabal.project.local~
.HTF/
.ghc.environment.*
*.*.sw*
*.tix
4 changes: 4 additions & 0 deletions scripts/generate-coverage-comment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "# Coverage report"
hpc report "$1" | awk '{sub(/^[ \t]*/, "&- "); sub(/^ /, ""); print}'