HaskellのGithub Actionsについて[2024年版]

Haskell

Haskell の Github Actions について

2024/02/18 現在、Github Actions でサジェストされる haskell の組み込みセットアップはactions/setup-haskell@v1になりますが、これは 2020 年 12 月時点で開発が終了してアーカイブされているようです。そのため代わりにhaskell-actions/setup@v2を使用するように変更しました。

サマリー

.github/workflows/haskell.ymlstepsを下記のように変更

steps:
  - uses: actions/checkout@v3
  # - uses: actions/setup-haskell@v1
  - uses: haskell-actions/setup@v2

yml 全体

name: Haskell CI

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-haskell@v1
        with:
          ghc-version: "8.10.3"
          cabal-version: "3.2"

      - name: Cache
        uses: actions/cache@v3
        env:
          cache-name: cache-cabal
        with:
          path: ~/.cabal
          key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
          restore-keys: |
            ${{ runner.os }}-build-${{ env.cache-name }}-
            ${{ runner.os }}-build-
            ${{ runner.os }}-

      - name: Install dependencies
        run: |
          cabal update
          cabal build --only-dependencies --enable-tests --enable-benchmarks
      - name: Build
        run: cabal build --enable-tests --enable-benchmarks all
      - name: Run tests
        run: cabal test all

問題

ローカル端末で作成した Haskell Project の CI を Github Actions で組もうとしたところ、以下のエラーが起きました

Run cabal update
Downloading the latest package list from hackage.haskell.org
Package list of hackage.haskell.org is up to date.
The index-state is set to 2024-02-17T12:14:05Z.
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] trying: some-project-0.1.0.0 (user goal)
[__1] next goal: base (dependency of some-project)
[__1] rejecting: base-4.14.1.0/installed-4.14.1.0 (conflict: some-project =>
base^>=4.17.2.1)
[__1] skipping: base-4.19.0.0, base-4.18.2.0, base-4.18.1.0, base-4.18.0.0
(has the same characteristics that caused the previous version to fail:
excluded by constraint '^>=4.17.2.1' from 'some-project')
[__1] rejecting: base-4.17.2.1, base-4.17.2.0, base-4.17.1.0, base-4.17.0.0,
base-4.16.4.0, base-4.16.3.0, base-4.16.2.0, base-4.16.1.0, base-4.16.0.0,
base-4.15.1.0, base-4.15.0.0, base-4.14.3.0, base-4.14.2.0, base-4.14.1.0,
base-4.14.0.0, base-4.13.0.0, base-4.12.0.0, base-4.11.1.0, base-4.11.0.0,
base-4.10.1.0, base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0,
base-4.8.1.0, base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0,
base-4.6.0.1, base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0,
base-4.4.0.0, base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1,
base-4.2.0.0, base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1
(constraint from non-upgradeable package requires installed instance)
[__1] fail (backjumping, conflict set: base, some-project)

手元の実行環境

$ cabal --version
cabal-install version 3.10.2.0
compiled using version 3.10.2.1 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.8

cabal,ghc のバージョンが CI 端末と手元で合っていないことが原因で fail していたため、その調整を試みたのですが、actions/setup-haskell@v1では ghc==9.4.8 に対応していないようです。
代わりにhaskell-actions/setup@v2を使用してみます。

steps:
  - uses: actions/checkout@v3
  # - uses: actions/setup-haskell@v1
  - uses: haskell-actions/setup@v2

haskell ci action success

無事動きました。

コメント

タイトルとURLをコピーしました