Skip to content

second try: haskell.yml #53

second try: haskell.yml

second try: haskell.yml #53

Workflow file for this run

name: Haskell Stack CI
on:
push:
branches: [ "main", "feature/**", "refactor/**" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Setup Haskell Stack
uses: haskell-actions/setup@v2
with:
ghc-version: '9.4.8'
enable-stack: true
stack-version: 'latest'
stack-no-global: true
# Split caching into separate steps for better control
- name: Cache Stack work files
uses: actions/cache@v3
with:
path: .stack-work
key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml', 'package.yaml', 'stack.yaml.lock') }}
restore-keys: |
${{ runner.os }}-stack-work-
- name: Cache Stack global package db
uses: actions/cache@v3
with:
path: ~/.stack/programs
key: ${{ runner.os }}-stack-programs-${{ hashFiles('stack.yaml') }}
restore-keys: |
${{ runner.os }}-stack-programs-
- name: Cache Stack pantry files
uses: actions/cache@v3
with:
path: ~/.stack/pantry
key: ${{ runner.os }}-stack-pantry-${{ hashFiles('stack.yaml') }}
restore-keys: |
${{ runner.os }}-stack-pantry-
- name: Prepare Stack
run: |
stack --version
stack update
- name: Install dependencies
run: |
stack setup
stack build --only-dependencies --test --bench --no-run-benchmarks
- name: Build
run: |
stack build --test --bench --no-run-benchmarks --pedantic
# --pedantic turns warnings into errors
- name: Run tests
run: |
stack test --coverage
stack hpc report . # Generate coverage report
- name: Install and run HLint
run: |
stack install hlint
stack exec -- hlint .
- name: Check formatting
run: |
stack install ormolu
stack exec -- ormolu --mode check $(find . -name '*.hs')
- name: Build documentation
run: |
stack haddock --no-haddock-deps
# Optional: deploy docs to GitHub Pages
- name: Run benchmarks
if: github.event_name == 'pull_request' # Only on PRs to save time
run: stack bench
# Add artifact upload for test results and docs
- name: Upload test results
if: always() # Run even if previous steps failed
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
.stack-work/dist/**/test-reports/
.stack-work/dist/**/hpc/
.stack-work/dist/**/doc/
# Add warning comment on PR if tests fail
- name: Comment on PR
if: github.event_name == 'pull_request' && failure()
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ CI checks failed. Please check the logs.'
})
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true # Cancel previous runs if new commit is pushed