|
| 1 | +# |
| 2 | +# Set up a workflow for building Cabal |
| 3 | +# |
| 4 | +# The only required input is the ghc version to build with (`ghc`). The other inputs are |
| 5 | +# generally for special purposes: |
| 6 | +# |
| 7 | +# - an additional ghc version for testing, used by the old-versions tests (`extra-ghc`) |
| 8 | +# - the `cabal.project` variant to use (`validate`) |
| 9 | +# - `allow-newer` and `constraints` lines, for manual jobs |
| 10 | +# - whether to build a static executable (for Alpine) (`static`) |
| 11 | +# - shell (override on Windows because the default is the wrong version) (`shell`) |
| 12 | +# - whether to use the cache (`with_cache`) |
| 13 | +# |
| 14 | +# There is only one output: the path to the installed (main) ghc. |
| 15 | +# |
| 16 | +# This is automatically done by the `validate-build` action, which takes the same |
| 17 | +# parameters. It should be done directly for jobs that test the built `cabal`. |
| 18 | +# |
| 19 | + |
| 20 | +name: Cabal setup |
| 21 | +description: Set up a workflow for Cabal |
| 22 | + |
| 23 | +inputs: |
| 24 | + ghc: |
| 25 | + description: ghc version to use |
| 26 | + required: true |
| 27 | + extra-ghc: |
| 28 | + description: additional ghc for tests |
| 29 | + required: false |
| 30 | + default: '' |
| 31 | + project: |
| 32 | + description: which cabal.project to use |
| 33 | + required: false |
| 34 | + default: 'validate' |
| 35 | + allow-newer: |
| 36 | + description: allow-newer line |
| 37 | + required: false |
| 38 | + default: '' |
| 39 | + constraints: |
| 40 | + description: constraints line |
| 41 | + required: false |
| 42 | + default: '' |
| 43 | + static: |
| 44 | + description: whether to build statically |
| 45 | + required: false |
| 46 | + default: 'false' |
| 47 | + shell: |
| 48 | + description: shell to use |
| 49 | + required: false |
| 50 | + default: 'bash' |
| 51 | + with_cache: |
| 52 | + description: whether to instantiate cache |
| 53 | + required: false |
| 54 | + default: 'true' |
| 55 | + |
| 56 | +outputs: |
| 57 | + ghc-exe: |
| 58 | + description: Path to ghc installed by setup-haskell |
| 59 | + value: ${{ steps.setup-haskell.outputs.ghc-exe }} |
| 60 | + |
| 61 | +runs: |
| 62 | + using: composite |
| 63 | + steps: |
| 64 | + - name: Make sure ghc is specified |
| 65 | + if: inputs.ghc == '' |
| 66 | + shell: ${{ inputs.shell }} |
| 67 | + run: exit 1 |
| 68 | + |
| 69 | + - name: Work around existence of XDG directories (haskell-actions/setup#62) |
| 70 | + if: runner.os == 'macOS' |
| 71 | + shell: ${{ inputs.shell }} |
| 72 | + run: | |
| 73 | + rm -rf ~/.config/cabal |
| 74 | + rm -rf ~/.cache/cabal |
| 75 | +
|
| 76 | + - name: "WIN: Setup TMP environment variable" |
| 77 | + if: runner.os == 'Windows' |
| 78 | + shell: ${{ inputs.shell }} |
| 79 | + run: | |
| 80 | + echo "TMP=${{ runner.temp }}" >> "$GITHUB_ENV" |
| 81 | +
|
| 82 | + # See https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#hackage-revisions |
| 83 | + - name: Add manually supplied allow-newer |
| 84 | + if: inputs.allow-newer != '' |
| 85 | + shell: ${{ inputs.shell }} |
| 86 | + run: | |
| 87 | + echo "allow-newer: ${{ inputs.allow-newer }}" >> cabal.${{ inputs.project }}.project |
| 88 | +
|
| 89 | + - name: Add manually supplied constraints |
| 90 | + if: inputs.constraints != '' |
| 91 | + shell: ${{ inputs.shell }} |
| 92 | + run: | |
| 93 | + echo "constraints: ${{ inputs.constraints }}" >> cabal.${{ inputs.project }}.project |
| 94 | +
|
| 95 | + - name: Enable statically linked executables |
| 96 | + if: inputs.static == 'true' |
| 97 | + shell: ${{ inputs.shell }} |
| 98 | + run: | |
| 99 | + echo 'executable-static: true' >> cabal.${{ inputs.project }}.project |
| 100 | +
|
| 101 | + # must happen before the main setup so the correct ghc is default |
| 102 | + - name: Install extra ghc for tests |
| 103 | + if: inputs.extra-ghc != '' |
| 104 | + uses: haskell-actions/setup@v2 |
| 105 | + with: |
| 106 | + ghc-version: ${{ inputs.extra-ghc }} |
| 107 | + cabal-version: '3.12.1.0' # see https://github.com/haskell/cabal/pull/10251 |
| 108 | + |
| 109 | + - uses: haskell-actions/setup@v2 |
| 110 | + id: setup-haskell |
| 111 | + with: |
| 112 | + ghc-version: ${{ inputs.ghc }} |
| 113 | + cabal-version: '3.12.1.0' |
| 114 | + # do we use this? |
| 115 | + ghcup-release-channel: https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.8.yaml |
| 116 | + |
| 117 | + # See the following link for a breakdown of the following step |
| 118 | + # https://github.com/haskell/actions/issues/7#issuecomment-745697160 |
| 119 | + - uses: actions/cache@v4 |
| 120 | + if: inputs.with_cache != 'false' |
| 121 | + with: |
| 122 | + # cabal-validate uses a special build dir |
| 123 | + path: | |
| 124 | + ${{ steps.setup-haskell.outputs.cabal-store }} |
| 125 | + dist-* |
| 126 | + key: ${{ runner.os }}-${{ inputs.ghc }}-${{ github.sha }} |
| 127 | + restore-keys: ${{ runner.os }}-${{ inputs.ghc }}- |
| 128 | + |
| 129 | + # Needed by cabal-testsuite/PackageTests/Configure/setup.test.hs |
| 130 | + - name: "MAC: Install Autotools" |
| 131 | + if: runner.os == 'macOS' |
| 132 | + shell: ${{ inputs.shell }} |
| 133 | + run: | |
| 134 | + brew install automake |
| 135 | +
|
| 136 | + # Needed by cabal-testsuite/PackageTests/Configure/setup.test.hs |
| 137 | + - name: "WIN: Install Autotools" |
| 138 | + if: runner.os == 'Windows' |
| 139 | + shell: ${{ inputs.shell }} |
| 140 | + run: | |
| 141 | + /usr/bin/pacman --noconfirm -S autotools |
| 142 | +
|
| 143 | + - name: Set validate inputs |
| 144 | + shell: ${{ inputs.shell }} |
| 145 | + run: | |
| 146 | + FLAGS="$COMMON_FLAGS" |
| 147 | + if [[ "${{ inputs.ghc }}" == "$GHC_FOR_SOLVER_BENCHMARKS" ]]; then |
| 148 | + FLAGS="$FLAGS --solver-benchmarks" |
| 149 | + fi |
| 150 | + if [[ "${{ inputs.ghc }}" == "$GHC_FOR_COMPLETE_HACKAGE_TESTS" ]]; then |
| 151 | + FLAGS="$FLAGS --complete-hackage-tests" |
| 152 | + fi |
| 153 | + echo "FLAGS=$FLAGS" >> "$GITHUB_ENV" |
| 154 | +
|
| 155 | + - name: Canonicalize architecture |
| 156 | + shell: ${{ inputs.shell }} |
| 157 | + run: | |
| 158 | + case ${{ runner.arch }} in |
| 159 | + X86) arch=i386 ;; |
| 160 | + X64) arch=x86_64 ;; |
| 161 | + ARM64) arch=aarch64 ;; |
| 162 | + *) echo "Unsupported architecture, please fix cabal-setup/action.yml" 2>/dev/null; exit 1 ;; |
| 163 | + esac |
| 164 | + echo "CABAL_ARCH=$arch" >> "$GITHUB_ENV" |
0 commit comments