summaryrefslogtreecommitdiff
path: root/deps/discord-haskell/.github/workflows/main.yml
blob: 0d5aa651bafc4d90b9f28089be85d74b399d4c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: CI

# when the workflow will run
on:
  push:
    branches: [ master ]
  pull_request:

  # Allows manually starting this workflow from the Actions tab
  workflow_dispatch:

jobs:
  # To dynamically create a build matrix, we generate a JSON output from one job
  # and use fromJson in the next job to construct the matrix.
  # This dynamic approach means we don't have to update the CI file when we
  # change supported GHC versions.
  #
  # Only the Cabal build job will use the generated matrix, since Stack has a
  # pinned GHC version in the stack.yaml file.
  generate-matrix:
    name: Generate GHC build matrix for Cabal
    runs-on: ubuntu-latest
    outputs:
      ghc-matrix: ${{ steps.set-ghc-matrix.outputs.versions }}
    steps:
      - uses: actions/checkout@v2

      - name: Parse the cabal tested-with stanza
        id: parse
        run: |
          echo "tested-with-versions=$(runghc .github/workflows/parseVersions.hs)" >> $GITHUB_OUTPUT

      - name: Set the GHC matrix for the next job
        id: set-ghc-matrix
        # We use single quotes here, since the output from the previous step
        # will not have escaped double quotes, and it's just easier to use single
        # quotes on the outside than try to escape the inner double quotes.
        run: echo 'versions={"ghc-version":${{ steps.parse.outputs.tested-with-versions }}}' >> $GITHUB_OUTPUT

  build-cabal:
    name: Cabal Build Check
    needs: generate-matrix
    runs-on: ubuntu-latest
    strategy:
      # Whether to stop other jobs in the matrix if one fails. This is undesirable
      # since we want to check e.g. it compiles on 8.10.7 regardless of the status
      # of 9.X.
      fail-fast: false
      # Feed the json from the previous job.
      matrix: ${{ fromJson(needs.generate-matrix.outputs.ghc-matrix) }}
    steps:
      - uses: actions/checkout@v2

      # Although the GitHub Action Runner comes with pre-installed Cabal and GHC,
      # we'll only use Cabal out of the box since that is independent of
      # the GHC version. For GHC, we'll use the Haskell setup action to install
      # the correct version needed for the build.
      - uses: haskell/actions/setup@v2
        id: setup-haskell
        with:
          # We install a global GHC
          ghc-version: ${{ matrix.ghc-version }}

      - name: "Cabal: Update cabal package database, generate build plan"
        run: |
          cabal update
          cabal build --dry-run

      - name: "Cabal: Cache Dependencies"
        id: cache
        uses: actions/cache@v2
        with:
          # Include the build plan file generated by cabal configure, but allow
          # restoring without its hash as long as the GHC version is the same.
          key: cabal-${{ runner.os }}-${{ matrix.ghc-version }}-${{ hashFiles('**/plan.json') }}
          restore-keys: |
            cabal-${{ runner.os }}-${{ matrix.ghc-version }}
          path: |
            ${{ steps.setup-haskell.outputs.cabal-store }}
            dist-newstyle

      - name: "Cabal: Build"
        run: cabal build

  build-stack:
    name: Stack Build Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      # Since the GitHub Action Runner comes with a pre-installed Stack, we'll
      # use that instead of installing our own through the Haskell setup action,
      # since all we need to test the stack build is Stack itself.

      - name: "Stack: Cache ~/.stack"
        id: cache-stack
        uses: actions/cache@v2
        with:
          path: ~/.stack
          key: stack-${{ runner.os }}-${{ hashFiles('stack.yaml') }}
          restore-keys: |
            stack-${{ runner.os }}

      - name: "Print GHC version resolved from stack.yaml"
        run: |
          stack ghc -- --version
          stack path --compiler-exe

      - name: "Stack: Build"
        run: stack build