|
| 1 | +--- |
| 2 | +name: cabal-build |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: main |
| 6 | + pull_request: |
| 7 | + branches: main |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: ${{ matrix.os }} / ghc ${{ matrix.ghc-version }} |
| 15 | + runs-on: ${{ matrix.os }}-latest |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + os: [ubuntu] |
| 20 | + ghc-version: |
| 21 | + - 9.8 |
| 22 | + - 9.6 |
| 23 | + - 9.4 |
| 24 | + |
| 25 | + include: |
| 26 | + - os: windows |
| 27 | + ghc-version: 9.6 |
| 28 | + |
| 29 | + - os: macos |
| 30 | + ghc-version: 9.6 |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v3 |
| 34 | + |
| 35 | + - name: Set up GHC ${{ matrix.ghc-version }} |
| 36 | + uses: haskell-actions/setup@v2 |
| 37 | + id: setup |
| 38 | + with: |
| 39 | + ghc-version: ${{ matrix.ghc-version }} |
| 40 | + # Defaults, added for clarity: |
| 41 | + cabal-version: latest |
| 42 | + cabal-update: true |
| 43 | + |
| 44 | + - name: Configure the build |
| 45 | + run: | |
| 46 | + cabal configure --enable-tests --enable-benchmarks --disable-documentation |
| 47 | + cabal build --dry-run |
| 48 | + # The last step generates dist-newstyle/cache/plan.json for the cache key. |
| 49 | +
|
| 50 | + - name: Restore cached dependencies |
| 51 | + uses: actions/cache/restore@v3 |
| 52 | + id: cache |
| 53 | + env: |
| 54 | + key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }} |
| 55 | + |
| 56 | + with: |
| 57 | + path: ${{ steps.setup.outputs.cabal-store }} |
| 58 | + key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }} |
| 59 | + restore-keys: ${{ env.key }}- |
| 60 | + |
| 61 | + - name: Install dependencies |
| 62 | + run: cabal build all --only-dependencies |
| 63 | + |
| 64 | + # Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail. |
| 65 | + - name: Save cached dependencies |
| 66 | + uses: actions/cache/save@v3 |
| 67 | + # Caches are immutable, trying to save with the same key would error. |
| 68 | + if: ${{ steps.cache.outputs.cache-primary-key != steps.cache.outputs.cache-matched-key }} |
| 69 | + with: |
| 70 | + path: ${{ steps.setup.outputs.cabal-store }} |
| 71 | + key: ${{ steps.cache.outputs.cache-primary-key }} |
| 72 | + |
| 73 | + - name: Build |
| 74 | + run: cabal build all |
| 75 | + |
| 76 | + - name: Run tests |
| 77 | + run: cabal test all |
| 78 | + |
| 79 | + - name: Check cabal file |
| 80 | + run: cabal check |
| 81 | + continue-on-error: true |
| 82 | + |
| 83 | + - name: Build documentation |
| 84 | + run: cabal haddock all |
| 85 | +... |
0 commit comments