From 433bc486426b948a1c9cdfe76f3a14e89ee4e4f5 Mon Sep 17 00:00:00 2001 From: Mayowa Pitan Date: Sat, 28 Nov 2026 02:38:04 +0100 Subject: [PATCH 1/2] Update to GHC 9.14.1 --- .github/workflows/ci.yml | 6 +- .github/workflows/push-image.yml | 8 +- Dockerfile | 165 ++++---------- README.md | 69 +++++- bin/run | 4 +- rootfs/opt/haskell/cabal.project | 19 ++ rootfs/opt/haskell/cabal.project.freeze | 215 ++++++++++++++++++ rootfs/opt/haskell/challenge.cabal | 39 ++++ rootfs/opt/haskell/smoke/PackagesSpec.hs | 93 ++++++++ rootfs/opt/haskell/smoke/run.sh | 15 ++ .../opt/haskell/src/CodewarsDependencies.hs | 1 + {workspace => rootfs/workspace}/test/Main.hs | 0 {workspace => rootfs/workspace}/test/Spec.hs | 0 workspace/Setup.hs | 2 - workspace/package.yaml | 34 --- workspace/src/Example.hs | 3 - workspace/stack.yaml | 8 - workspace/test/ExampleSpec.hs | 13 -- 18 files changed, 492 insertions(+), 202 deletions(-) create mode 100644 rootfs/opt/haskell/cabal.project create mode 100644 rootfs/opt/haskell/cabal.project.freeze create mode 100644 rootfs/opt/haskell/challenge.cabal create mode 100644 rootfs/opt/haskell/smoke/PackagesSpec.hs create mode 100644 rootfs/opt/haskell/smoke/run.sh create mode 100644 rootfs/opt/haskell/src/CodewarsDependencies.hs rename {workspace => rootfs/workspace}/test/Main.hs (100%) rename {workspace => rootfs/workspace}/test/Spec.hs (100%) delete mode 100644 workspace/Setup.hs delete mode 100644 workspace/package.yaml delete mode 100644 workspace/src/Example.hs delete mode 100644 workspace/stack.yaml delete mode 100644 workspace/test/ExampleSpec.hs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb34c79..56121f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,11 @@ jobs: runs-on: ubuntu-latest if: ${{ github.repository == 'codewars/haskell' }} steps: - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v2 + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 - name: Build image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . push: false diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 7c911d3..b94ef6a 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -15,20 +15,20 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: codewars password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push image - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v6 with: context: . push: true diff --git a/Dockerfile b/Dockerfile index d5dd1ec..05b8ce7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,127 +1,46 @@ -FROM debian:buster-slim -# Based on https://github.com/haskell/docker-haskell/blob/12cd297d7ccc2e97fe5e94548ae502b0cbb6735f/9.2/slim-buster/Dockerfile +# GHC 9.14.1, Cabal 3.16.1.0, Stack 3.11.1; Linux amd64 and arm64. +# https://github.com/haskell/docker-haskell/tree/870b06856b1f4dfc09cd710ab9c680060d25e202/9.14/slim-bookworm +FROM haskell:9.14.1-slim-bookworm@sha256:0ab6a64546d7cddfe30cea87eb1aeb9155f468c8aaf53a9b2d4d77c597a429ec ENV LANG=C.UTF-8 - -# common haskell + stack dependencies -RUN set -ex; \ - apt-get update; \ - apt-get install -y --no-install-recommends \ - ca-certificates \ - curl \ - dpkg-dev \ - git \ - gcc \ - gnupg \ - g++ \ - libc6-dev \ - libffi-dev \ - libgmp-dev \ - libnuma-dev \ - libtinfo-dev \ - make \ - netbase \ - xz-utils \ - zlib1g-dev \ - # for regex-pcre - libpcre3 \ - libpcre3-dev \ - pkg-config \ - ; \ - rm -rf /var/lib/apt/lists/*; - -ENV STACK=2.9.3 STACK_RELEASE_KEY=C5705533DA4F78D8664B5DC0575159689BEFB442 -RUN set -eux; \ - cd /tmp; \ - STACK_URL="https://github.com/commercialhaskell/stack/releases/download/v${STACK}/stack-${STACK}-linux-x86_64.tar.gz"; \ - # sha256 from https://github.com/commercialhaskell/stack/releases/download/v${STACK}/stack-${STACK}-linux-x86_64.tar.gz.sha256 - STACK_SHA256='938f689dc45e2693ab1ca3ea215790b3786dfd531dcf6c0bf40842c24e579ae9'; \ - curl -sSL "$STACK_URL" -o stack.tar.gz; \ - echo "$STACK_SHA256 stack.tar.gz" | sha256sum --strict --check; \ - \ - curl -sSL "$STACK_URL.asc" -o stack.tar.gz.asc; \ - GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ - gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$STACK_RELEASE_KEY"; \ - gpg --batch --verify stack.tar.gz.asc stack.tar.gz; \ - gpgconf --kill all; \ - \ - tar -xf stack.tar.gz -C /usr/local/bin --strip-components=1 "stack-$STACK-linux-x86_64/stack"; \ - stack config set system-ghc --global true; \ - stack config set install-ghc --global false; \ - \ - rm -rf /tmp/*; \ - \ - stack --version; - -ENV CABAL_INSTALL=3.8.1.0 CABAL_INSTALL_RELEASE_KEY=E9EC5616017C3EE26B33468CCE1ED8AE0B011D8C -RUN set -eux; \ - cd /tmp; \ - CABAL_INSTALL_TAR="cabal-install-$CABAL_INSTALL-x86_64-linux-deb10.tar.xz"; \ - CABAL_INSTALL_URL="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/$CABAL_INSTALL_TAR"; \ - CABAL_INSTALL_SHA256SUMS_URL="https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/SHA256SUMS"; \ - # sha256 from https://downloads.haskell.org/~cabal/cabal-install-$CABAL_INSTALL/SHA256SUMS - CABAL_INSTALL_SHA256='c71a1a46fd42d235bb86be968660815c24950e5da2d1ff4640da025ab520424b'; \ - curl -fSL "$CABAL_INSTALL_URL" -o cabal-install.tar.gz; \ - echo "$CABAL_INSTALL_SHA256 cabal-install.tar.gz" | sha256sum --strict --check; \ - \ - curl -sSLO "$CABAL_INSTALL_SHA256SUMS_URL"; \ - curl -sSLO "$CABAL_INSTALL_SHA256SUMS_URL.sig"; \ - GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ - gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$CABAL_INSTALL_RELEASE_KEY"; \ - gpg --batch --verify SHA256SUMS.sig SHA256SUMS; \ - # confirm we are verifying SHA256SUMS that matches the release + sha256 - grep "$CABAL_INSTALL_SHA256 $CABAL_INSTALL_TAR" SHA256SUMS; \ - gpgconf --kill all; \ - \ - tar -xf cabal-install.tar.gz -C /usr/local/bin; \ - \ - rm -rf /tmp/*; \ - \ - cabal --version; - -ENV GHC=9.2.5 GHC_RELEASE_KEY=88B57FCF7DB53B4DB3BFA4B1588764FBE22D19C4 -RUN set -eux; \ - cd /tmp; \ - GHC_URL="https://downloads.haskell.org/~ghc/$GHC/ghc-$GHC-x86_64-deb10-linux.tar.xz"; \ - # sha256 from https://downloads.haskell.org/~ghc/$GHC/SHA256SUMS - GHC_SHA256='89f2df47d86a45593d6ba3fd3a44b627d100588cd59be257570dbe3f92b17c48'; \ - curl -sSL "$GHC_URL" -o ghc.tar.xz; \ - echo "$GHC_SHA256 ghc.tar.xz" | sha256sum --strict --check; \ - \ - GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \ - curl -sSL "$GHC_URL.sig" -o ghc.tar.xz.sig; \ - gpg --batch --keyserver keyserver.ubuntu.com --receive-keys "$GHC_RELEASE_KEY"; \ - gpg --batch --verify ghc.tar.xz.sig ghc.tar.xz; \ - gpgconf --kill all; \ - \ - tar xf ghc.tar.xz; \ - cd "ghc-$GHC"; \ - ./configure --prefix "/opt/ghc/$GHC"; \ - make install; \ - # remove profiling support to save space - find "/opt/ghc/$GHC/" \( -name "*_p.a" -o -name "*.p_hi" \) -type f -delete; \ - # remove some docs - rm -rf "/opt/ghc/$GHC/share/"; \ - \ - rm -rf /tmp/*; \ - \ - "/opt/ghc/$GHC/bin/ghc" --version; - -ENV PATH=/opt/ghc/${GHC}/bin:$PATH - -RUN set -ex; \ - useradd --create-home codewarrior; \ - mkdir -p /workspace; \ - chown codewarrior: /workspace; - +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + libpcre3-dev=2:8.39-15 libsqlite3-dev=3.40.1-2+deb12u2 pkg-config=1.8.1-1 \ + && rm -rf /var/lib/apt/lists/* \ + && useradd --create-home --uid 1000 codewarrior \ + && mkdir -p /workspace /opt/haskell /opt/cabal \ + && chown codewarrior:codewarrior /workspace /opt/haskell /opt/cabal + +WORKDIR /opt/haskell USER codewarrior -ENV USER=codewarrior HOME=/home/codewarrior -ENV PATH=/home/codewarrior/.cabal/bin:/home/codewarrior/.local/bin:$PATH - -COPY --chown=codewarrior:codewarrior workspace/ /workspace/ +ENV USER=codewarrior HOME=/home/codewarrior CABAL_DIR=/opt/cabal +ENV PATH=/opt/cabal/bin:/opt/ghc/9.14.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +# These are the existing public Codewars APIs, verified before extraction. +RUN curl -fsSL https://codeload.github.com/codewars/hspec-formatters-codewars/tar.gz/refs/tags/v0.3.0 -o formatter.tar.gz \ + && echo 'c7572cf25789bf5b153195813fbbb3b9509ba693bccfb1db521ee09364f8b173 formatter.tar.gz' | sha256sum -c - \ + && tar xzf formatter.tar.gz \ + && curl -fsSL https://codeload.github.com/codewars/hspec-codewars/tar.gz/refs/tags/v0.1.0 -o helpers.tar.gz \ + && echo '3c29ea2a255aef452e95655dbfbba2c168b2c44afbdad5b76729de3c0061d77b helpers.tar.gz' | sha256sum -c - \ + && tar xzf helpers.tar.gz \ + && rm formatter.tar.gz helpers.tar.gz + +# A mirror may be selected for constrained networks; Cabal still verifies Hackage signatures. +ARG HACKAGE_URL=https://hackage.haskell.org/ +RUN cabal user-config init \ + && sed -i "s|url: http://hackage.haskell.org/|url: ${HACKAGE_URL}|" /opt/cabal/config \ + && cabal update + +COPY --chown=codewarrior:codewarrior rootfs/opt/haskell/challenge.cabal rootfs/opt/haskell/cabal.project rootfs/opt/haskell/cabal.project.freeze ./ +COPY --chown=codewarrior:codewarrior rootfs/opt/haskell/src/ src/ +RUN cabal build all --enable-tests \ + && cp .ghc.environment.* environment \ + && mkdir -p /opt/cabal/bin \ + && find /opt/cabal/store -type f -path '*/bin/hspec-discover' -exec cp '{}' /opt/cabal/bin/hspec-discover ';' + +# Direct ghc/runghc calls use the prebuilt package set without a runtime resolver. +ENV GHC_ENVIRONMENT=/opt/haskell/environment +COPY --chown=codewarrior:codewarrior rootfs/workspace/ /workspace/ +COPY --chown=codewarrior:codewarrior rootfs/opt/haskell/smoke/ smoke/ +RUN sh /opt/haskell/smoke/run.sh WORKDIR /workspace -RUN stack build -# Sanity check -RUN set -ex; \ - stack ghc -- -O -isrc:test --make -o tests -outputdir /tmp test/Main.hs && ./tests; \ - rm src/Example.hs test/ExampleSpec.hs tests /tmp/*; diff --git a/README.md b/README.md index 117f6ab..1b4be1f 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,73 @@ # haskell -Container image for Haskell +Container image for Haskell on Codewars: GHC 9.14.1 with Cabal 3.16.1.0, for Linux amd64 and arm64. -## Usage +The GHC 9.2.5 image is still available from the [`9.2.5` tag](https://github.com/codewars/haskell/tree/9.2.5). + +## Packages + +Kata code can import the packages listed in [`rootfs/opt/haskell/challenge.cabal`](rootfs/opt/haskell/challenge.cabal) and their dependencies. +Every version is pinned by [`rootfs/opt/haskell/cabal.project.freeze`](rootfs/opt/haskell/cabal.project.freeze). + +| package | version | +| --- | --- | +| base | 4.22.0.0 | +| attoparsec | 0.14.4 | +| fakedata | 1.0.5 | +| haskell-src-exts | 1.24.0 | +| heaps | 0.4.1 | +| hspec | 2.11.18 | +| hspec-attoparsec | 0.1.0.2 | +| hspec-codewars | 0.1.0 | +| hspec-contrib | 0.5.2 | +| hspec-formatters-codewars | 0.3.0 | +| hspec-megaparsec | 2.2.1 | +| HUnit-approx | 1.1.1.1 | +| infinite-list | 0.1.3 | +| lens | 5.3.6 | +| megaparsec | 9.8.3 | +| mtl | 2.3.1 | +| parsec | 3.1.18.0 | +| persistent | 2.18.1.0 | +| persistent-sqlite | 2.13.3.1 | +| persistent-template | 2.12.0.0 | +| primes | 0.2.1.0 | +| random | 1.3.1 | +| regex-pcre | 0.95.0.1 | +| regex-posix | 0.96.0.2 | +| regex-tdfa | 1.3.2.7 | +| split | 0.2.5.1 | +| text | 2.1.3 | +| transformers | 0.6.1.2 | +| vector | 0.13.2.0 | + +The packages are built once into a GHC environment file (`GHC_ENVIRONMENT=/opt/haskell/environment`), so `ghc` and `runghc` use them without Stack or Cabal at run time. + +## Compiling + +Code is compiled with `-XGHC2021`. The test command is: ```bash -W=/workspace -# Create container -COMPILE="stack ghc -- -O -j2 +RTS -A128m -n2m -RTS --make -v0 -outputdir /tmp -isrc:test test/Main.hs -o tests" -C=$(docker container create --rm -w $W $IMAGE sh -c "$COMPILE && exec ./tests") +ghc -XGHC2021 -O -j2 +RTS -A128m -n2m -RTS --make -v0 -outputdir /tmp -isrc:test test/Main.hs -o tests && ./tests +``` + +The solution goes in `src/`, and the test module (its name must end with `Spec`) goes in `test/`. +`test/Main.hs` and `test/Spec.hs` are provided by the image and use [hspec-formatters-codewars](https://github.com/codewars/hspec-formatters-codewars). -# Copy files from the examples directory -docker container cp ./examples/passing/. $C:$W +Code without tests runs with `runghc -XGHC2021 Main.hs`. + +## Usage -# Start -docker container start --attach $C +```bash +bin/run passing ``` +This copies `examples/passing` into a container and runs the test command above. Set `IMAGE` to test a different image. + ## Building ```bash docker build -t ghcr.io/codewars/haskell:latest . ``` + +The build runs `rootfs/opt/haskell/smoke/run.sh`, which compiles and runs a test that uses each package. diff --git a/bin/run b/bin/run index 9b7a026..e8613c5 100755 --- a/bin/run +++ b/bin/run @@ -7,8 +7,8 @@ fi W=/workspace -# Create container -COMPILE="stack ghc -- -O -j2 +RTS -A128m -n2m -RTS --make -v0 -outputdir /tmp -isrc:test test/Main.hs -o tests" +# Create container. This is the command Codewars runs for GHC 9.14.1. +COMPILE="ghc -XGHC2021 -O -j2 +RTS -A128m -n2m -RTS --make -v0 -outputdir /tmp -isrc:test test/Main.hs -o tests" C=$(docker container create --rm -w $W $IMAGE sh -c "$COMPILE && exec ./tests") # Copy files from the examples directory diff --git a/rootfs/opt/haskell/cabal.project b/rootfs/opt/haskell/cabal.project new file mode 100644 index 0000000..97832fb --- /dev/null +++ b/rootfs/opt/haskell/cabal.project @@ -0,0 +1,19 @@ +packages: . hspec-codewars-0.1.0 hspec-formatters-codewars-0.3.0 +index-state: 2026-10-28T00:00:00Z +write-ghc-environment-files: always +optimization: 1 +jobs: 4 + +-- GHC 9.14.1 provides template-haskell 2.24.0.0. Persistent's +-- published upper bound is stale; keep this exception limited and pinned. +-- https://github.com/yesodweb/persistent/issues/1619 +-- Must pass the Template Haskell + SQLite smoke test before release. +-- string-random's containers < 0.8 bound is also stale: GHC 9.14.1 ships +-- containers 0.8, and without this the solver falls back to fakedata 0.6.1, +-- which does not compile on 9.14. fakedata 1.0.5 builds and passes the smoke test. +allow-newer: persistent:template-haskell, string-random:containers +constraints: + fakedata == 1.0.5, + persistent == 2.18.1.0, + template-haskell == 2.24.0.0, + haskell-src-exts == 1.24.0 diff --git a/rootfs/opt/haskell/cabal.project.freeze b/rootfs/opt/haskell/cabal.project.freeze new file mode 100644 index 0000000..856ef2c --- /dev/null +++ b/rootfs/opt/haskell/cabal.project.freeze @@ -0,0 +1,215 @@ +active-repositories: hackage.haskell.org:merge +constraints: any.HUnit ==1.6.2.0, + any.HUnit-approx ==1.1.1.1, + any.OneTuple ==0.4.3, + OneTuple +base-ge-4-15 +base-ge-4-16, + any.QuickCheck ==2.18.0.0, + QuickCheck -old-random +templatehaskell, + any.StateVar ==1.2.2, + any.adjunctions ==4.4.4, + any.aeson ==2.2.5.1, + aeson +ordered-keymap, + any.ansi-terminal ==1.1.5, + ansi-terminal -example, + any.ansi-terminal-types ==1.1.3, + any.array ==0.5.8.0, + any.assoc ==1.1.1, + assoc -tagged, + any.async ==2.2.6, + async -bench -debug-auto-label, + any.attoparsec ==0.14.4, + attoparsec -developer, + any.attoparsec-aeson ==2.2.2.0, + any.auto-update ==0.2.8, + any.base ==4.22.0.0, + any.base-orphans ==0.9.4, + any.base64-bytestring ==1.2.1.0, + any.bifunctors ==5.6.3, + bifunctors +tagged, + any.binary ==0.8.9.3, + any.bitvec ==1.1.6.0, + bitvec +simd, + any.blaze-builder ==0.4.4.1, + any.blaze-html ==0.9.2.0, + any.blaze-markup ==0.8.3.0, + any.bytestring ==0.12.2.0, + any.call-stack ==0.4.0, + any.case-insensitive ==1.2.1.0, + any.character-ps ==0.1, + any.colour ==2.3.7, + any.comonad ==5.0.10, + comonad +containers +distributive +indexed-traversable, + any.conduit ==1.3.6.1, + any.conduit-extra ==1.3.8, + any.containers ==0.8, + any.contravariant ==1.5.6, + contravariant +statevar, + any.cookie ==0.5.1, + any.data-default ==0.8.0.2, + any.data-default-class ==0.2.0.0, + any.data-fix ==0.3.4, + any.deepseq ==1.5.1.0, + any.directory ==1.3.10.0, + any.distributive ==0.6.3, + distributive +tagged, + any.dlist ==1.0, + dlist -werror, + any.easy-file ==0.2.5, + any.exceptions ==0.10.11, + any.fakedata ==1.0.5, + any.fakedata-parser ==0.1.0.0, + any.fast-logger ==3.2.9, + any.file-io ==0.1.5, + any.filepath ==1.5.4.0, + any.free ==5.2, + any.ghc-bignum ==1.4, + any.ghc-boot-th ==9.14.1, + any.ghc-internal ==9.1401.0, + any.ghc-prim ==0.13.1, + any.happy ==2.2, + any.happy-lib ==2.2, + any.hashable ==1.5.1.0, + hashable -arch-native -random-initial-seed, + any.haskell-lexer ==1.2.1, + any.haskell-src-exts ==1.24.0, + any.heaps ==0.4.1, + any.hsc2hs ==0.68.10, + hsc2hs -in-ghc-tree, + any.hspec ==2.11.18, + any.hspec-attoparsec ==0.1.0.2, + any.hspec-contrib ==0.5.2, + any.hspec-core ==2.11.18, + any.hspec-discover ==2.11.18, + any.hspec-expectations ==0.8.4, + any.hspec-megaparsec ==2.2.1, + hspec-megaparsec -dev, + any.http-api-data ==0.7, + http-api-data -use-text-show, + any.http-types ==0.12.6, + any.indexed-traversable ==0.1.5, + indexed-traversable +base-ge-4-18, + any.indexed-traversable-instances ==0.1.2.1, + any.infinite-list ==0.1.3, + any.integer-conversion ==0.1.1, + any.integer-logarithms ==1.0.5, + integer-logarithms -check-bounds +integer-gmp, + any.invariant ==0.6.5, + any.kan-extensions ==5.2.8, + any.lens ==5.3.6, + lens -benchmark-uniplate -dump-splices +inlining -j +test-hunit +test-properties +test-templates +trustworthy, + any.libyaml ==0.1.4, + libyaml -no-unicode -system-libyaml, + any.libyaml-clib ==0.2.5, + any.lift-type ==0.1.2.0, + any.lifted-base ==0.2.3.12, + any.megaparsec ==9.8.3, + megaparsec -dev, + any.microlens ==0.5.0.0, + any.microlens-th ==0.4.3.18, + any.monad-control ==1.0.3.1, + any.monad-logger ==0.3.42, + monad-logger +template_haskell, + any.monad-loops ==0.4.3, + monad-loops +base4, + any.mono-traversable ==1.0.21.0, + any.mtl ==2.3.1, + any.network ==3.2.9.0, + network -devel, + any.network-uri ==2.6.4.2, + any.optparse-applicative ==0.19.0.0, + optparse-applicative +process, + any.os-string ==2.0.8, + any.parallel ==3.3.0.0, + any.parsec ==3.1.18.0, + any.parser-combinators ==1.3.1, + parser-combinators -dev, + any.path-pieces ==0.2.1, + any.persistent ==2.18.1.0, + any.persistent-sqlite ==2.13.3.1, + persistent-sqlite -build-sanity-exe +full-text-search +have-usleep +json1 -systemlib +uri-filenames -use-pkgconfig -use-stat3 +use-stat4, + any.persistent-template ==2.12.0.0, + any.pretty ==1.1.3.6, + any.prettyprinter ==1.7.2, + prettyprinter -buildreadme +text, + any.prettyprinter-ansi-terminal ==1.1.4, + prettyprinter-ansi-terminal +text, + any.primes ==0.2.1.0, + any.primitive ==0.9.1.0, + any.process ==1.6.26.1, + any.profunctors ==5.6.3, + any.quickcheck-io ==0.2.0, + any.random ==1.3.1, + any.reflection ==2.1.9, + reflection -slow +template-haskell, + any.regex-base ==0.94.0.3, + any.regex-pcre ==0.95.0.1, + regex-pcre +pkg-config, + any.regex-posix ==0.96.0.2, + regex-posix -_regex-posix-clib, + any.regex-tdfa ==1.3.2.7, + regex-tdfa +doctest -force-o2, + any.replace-megaparsec ==1.5.0.1, + any.resource-pool ==0.5.1.0, + any.resourcet ==1.3.0, + any.rts ==1.0.3, + any.safe-exceptions ==0.1.7.4, + any.scientific ==0.3.10.0, + scientific -integer-simple, + any.semialign ==1.4, + semialign +semigroupoids, + any.semigroupoids ==6.0.2, + semigroupoids +comonad +containers +contravariant +tagged +unordered-containers, + any.silently ==1.2.5.4, + any.split ==0.2.5.1, + any.splitmix ==0.1.3.2, + splitmix -optimised-mixer, + any.stm ==2.5.3.1, + any.stm-chans ==3.0.0.11, + any.streaming-commons ==0.2.3.1, + streaming-commons -use-bytestring-builder, + any.strict ==0.5.1, + any.string-random ==0.1.4.5, + any.tagged ==0.8.11, + tagged +deepseq +template-haskell, + any.tasty ==1.5.5, + tasty +terminal-size +unix, + any.template-haskell ==2.24.0.0, + any.terminal-size ==0.3.4, + any.text ==2.1.3, + any.text-iso8601 ==0.1.1.2, + any.text-short ==0.1.6.1, + text-short -asserts, + any.th-abstraction ==0.7.2.0, + any.th-compat ==0.1.7, + any.th-lift ==0.8.7, + any.th-lift-instances ==0.1.20, + any.these ==1.2.1, + any.time ==1.15, + any.time-compat ==1.9.9, + any.transformers ==0.6.1.2, + any.transformers-base ==0.4.6.1, + transformers-base +orphaninstances, + any.transformers-compat ==0.7.2, + transformers-compat -five +five-three -four +generic-deriving +mtl -three -two, + any.typed-process ==0.2.13.0, + any.unix ==2.8.8.0, + any.unix-compat ==0.7.4.1, + any.unix-time ==0.5.1, + any.unliftio ==0.2.25.1, + any.unliftio-core ==0.2.1.0, + any.unordered-containers ==0.2.21, + unordered-containers -debug, + any.uuid-types ==1.0.6.1, + any.vault ==0.3.2.0, + vault +useghc, + any.vector ==0.13.2.0, + vector +boundschecks -internalchecks -unsafechecks -wall, + any.vector-algorithms ==0.9.1.0, + vector-algorithms +bench +boundschecks -internalchecks -llvm -unsafechecks, + any.vector-stream ==0.1.0.1, + any.witherable ==0.5, + any.yaml ==0.11.11.2, + yaml +no-examples +no-exe, + any.zlib ==0.7.1.1, + zlib -bundled-c-zlib +non-blocking-ffi +pkg-config +index-state: hackage.haskell.org 2026-10-27T23:28:52Z diff --git a/rootfs/opt/haskell/challenge.cabal b/rootfs/opt/haskell/challenge.cabal new file mode 100644 index 0000000..7c4c466 --- /dev/null +++ b/rootfs/opt/haskell/challenge.cabal @@ -0,0 +1,39 @@ +cabal-version: 2.4 +name: challenge +version: 0.1.0 +build-type: Simple +library + exposed-modules: CodewarsDependencies + hs-source-dirs: src + default-language: Haskell2010 + build-depends: + base >= 4.7 && < 5, + attoparsec, + fakedata, + haskell-src-exts, + heaps, + hspec, + hspec-attoparsec, + hspec-codewars, + hspec-contrib, + hspec-formatters-codewars, + hspec-megaparsec, + HUnit-approx, + infinite-list, + lens, + megaparsec, + mtl, + parsec, + persistent, + persistent-sqlite, + persistent-template, + primes, + random, + regex-pcre, + regex-posix, + regex-tdfa, + split, + text, + transformers, + vector + build-tool-depends: hspec-discover:hspec-discover diff --git a/rootfs/opt/haskell/smoke/PackagesSpec.hs b/rootfs/opt/haskell/smoke/PackagesSpec.hs new file mode 100644 index 0000000..3af1397 --- /dev/null +++ b/rootfs/opt/haskell/smoke/PackagesSpec.hs @@ -0,0 +1,93 @@ +{-# LANGUAGE DataKinds, DerivingStrategies, FlexibleInstances, GADTs #-} +{-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes, StandaloneDeriving, TemplateHaskell, TypeFamilies #-} +{-# LANGUAGE UndecidableInstances #-} +module PackagesSpec (spec) where + +import Control.Lens ((&), (.~), (^.), _1) +import Control.Monad.State.Strict (execState, modify) +import Control.Monad.Trans.Maybe (runMaybeT, MaybeT(..)) +import qualified Data.Attoparsec.Text as A +import qualified Data.Heap as Heap +import Data.Numbers.Primes (isPrime, primeFactors, primes) +import qualified Data.List.Infinite as Inf +import Data.List.Split (splitOn) +import qualified Data.Text as T +import qualified Data.Vector as V +import Data.Void (Void) +import qualified Language.Haskell.Exts as H +import Database.Persist +import Database.Persist.Sqlite +import Database.Persist.TH +import Faker (generateNonDeterministic) +import qualified Faker.Name as FakerName +import System.Random (mkStdGen, randomRs) +import Test.Hspec +import Test.Hspec.Attoparsec () +import Test.Hspec.Megaparsec () +import Test.Hspec.Contrib.HUnit () +import Test.HUnit.Approx () +import Test.Hspec.Codewars +import Test.QuickCheck +import qualified Text.Megaparsec as M +import qualified Text.Megaparsec.Char as MC +import qualified Text.Parsec as P +import qualified Text.Regex.PCRE as PCRE +import qualified Text.Regex.Posix as POSIX +import qualified Text.Regex.TDFA as TDFA + +share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| +Widget + name T.Text + deriving Show Eq +|] + +spec :: Spec +spec = describe "9.14.1 package compatibility" $ do + it "uses attoparsec and text" $ + A.parseOnly A.decimal "42" `shouldBe` Right (42 :: Int) + it "uses megaparsec" $ + M.parse (MC.string "hello" :: M.Parsec Void T.Text T.Text) "input" "hello" `shouldBe` Right "hello" + it "uses parsec" $ + P.parse (P.string "hello") "input" ("hello" :: String) `shouldBe` Right "hello" + it "uses lens" $ + ((1, ()) & _1 .~ (2 :: Int)) ^. _1 `shouldBe` 2 + it "uses vector" $ + V.sum (V.fromList [1,2,3 :: Int]) `shouldBe` 6 + it "uses split" $ + splitOn "," "a,b" `shouldBe` ["a", "b"] + it "uses mtl" $ + execState (modify (+1)) (3 :: Int) `shouldBe` 4 + it "uses transformers" $ + runMaybeT (MaybeT (pure (Just 42))) `shouldReturn` Just (42 :: Int) + it "uses random" $ + length (take 5 (randomRs (1,10 :: Int) (mkStdGen 1))) `shouldBe` 5 + it "uses PCRE native linkage" $ + (("abc123" :: String) PCRE.=~ ("[0-9]+" :: String) :: String) `shouldBe` "123" + it "uses POSIX regex" $ + (("abc123" :: String) POSIX.=~ ("[0-9]+" :: String) :: String) `shouldBe` "123" + it "uses TDFA regex" $ + (("abc123" :: String) TDFA.=~ ("[0-9]+" :: String) :: String) `shouldBe` "123" + it "parses classic Haskell" $ + case H.parseModule "module Solution where\nanswer = 42\n" of + H.ParseOk _ -> pure () + H.ParseFailed loc msg -> expectationFailure (show loc ++ ": " ++ msg) + it "uses Codewars approximate comparison" $ + sqrt 2 `shouldBeApprox` (1.4142135 :: Double) + it "uses QuickCheck" $ property $ \n -> reverse (reverse n) == (n :: [Int]) + it "uses heaps" $ + Heap.minimum (Heap.fromList [5, 3, 8 :: Int]) `shouldBe` 3 + it "uses primes" $ do + take 5 primes `shouldBe` [2, 3, 5, 7, 11 :: Int] + isPrime (97 :: Int) `shouldBe` True + primeFactors (360 :: Int) `shouldBe` [2, 2, 2, 3, 3, 5] + it "uses fakedata and its bundled locale data" $ do + name <- generateNonDeterministic FakerName.name + T.null name `shouldBe` False + it "uses infinite-list" $ + Inf.take 5 (Inf.iterate (* 2) 1) `shouldBe` [1, 2, 4, 8, 16 :: Int] + it "uses persistent Template Haskell and SQLite" $ + runSqlite ":memory:" (do + runMigration migrateAll + key <- insert (Widget "cw12") + get key) `shouldReturn` Just (Widget "cw12") diff --git a/rootfs/opt/haskell/smoke/run.sh b/rootfs/opt/haskell/smoke/run.sh new file mode 100644 index 0000000..8c39926 --- /dev/null +++ b/rootfs/opt/haskell/smoke/run.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -eu +[ "$(ghc --numeric-version)" = 9.14.1 ] +test -x /opt/cabal/bin/hspec-discover +probe=$(mktemp -d) +trap 'rm -rf "$probe"' EXIT +mkdir -p "$probe/test" "$probe/src" "$probe/build" +cp /workspace/test/Main.hs /workspace/test/Spec.hs "$probe/test/" +cp /opt/haskell/smoke/PackagesSpec.hs "$probe/test/" +cd "$probe" +ghc -XGHC2021 -O -j2 +RTS -A128m -n2m -RTS --make -v0 -outputdir build -isrc:test test/Main.hs -o tests +./tests > package-results.txt +grep -q '' package-results.txt +! grep -Eq '<(FAILED|ERROR)::>' package-results.txt +cat package-results.txt diff --git a/rootfs/opt/haskell/src/CodewarsDependencies.hs b/rootfs/opt/haskell/src/CodewarsDependencies.hs new file mode 100644 index 0000000..f442b99 --- /dev/null +++ b/rootfs/opt/haskell/src/CodewarsDependencies.hs @@ -0,0 +1 @@ +module CodewarsDependencies where diff --git a/workspace/test/Main.hs b/rootfs/workspace/test/Main.hs similarity index 100% rename from workspace/test/Main.hs rename to rootfs/workspace/test/Main.hs diff --git a/workspace/test/Spec.hs b/rootfs/workspace/test/Spec.hs similarity index 100% rename from workspace/test/Spec.hs rename to rootfs/workspace/test/Spec.hs diff --git a/workspace/Setup.hs b/workspace/Setup.hs deleted file mode 100644 index 9a994af..0000000 --- a/workspace/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/workspace/package.yaml b/workspace/package.yaml deleted file mode 100644 index f0cd2f7..0000000 --- a/workspace/package.yaml +++ /dev/null @@ -1,34 +0,0 @@ -name: challenge -version: 0.1.0 -license: BSD3 -synopsis: Haskell challenge - -dependencies: -- base >= 4.7 && < 5 -- attoparsec -- haskell-src-exts -- hspec -- hspec-attoparsec -- hspec-codewars -- hspec-contrib -- hspec-formatters-codewars -- hspec-megaparsec -- HUnit-approx -- lens -- megaparsec -- mtl -- parsec -- persistent -- persistent-sqlite -- persistent-template -- random -- regex-pcre -- regex-posix -- regex-tdfa -- split -- text -- transformers -- vector - -library: - source-dirs: src diff --git a/workspace/src/Example.hs b/workspace/src/Example.hs deleted file mode 100644 index 20d8d04..0000000 --- a/workspace/src/Example.hs +++ /dev/null @@ -1,3 +0,0 @@ -module Example where -add :: Num a => a -> a -> a -add = (+) diff --git a/workspace/stack.yaml b/workspace/stack.yaml deleted file mode 100644 index 7e3a4cc..0000000 --- a/workspace/stack.yaml +++ /dev/null @@ -1,8 +0,0 @@ -resolver: lts-20.10 - -extra-deps: - - url: https://github.com/codewars/hspec-formatters-codewars/archive/v0.3.0.tar.gz - - url: https://github.com/codewars/hspec-codewars/archive/v0.1.0.tar.gz - -# Control whether we use the GHC we find on the path -system-ghc: true diff --git a/workspace/test/ExampleSpec.hs b/workspace/test/ExampleSpec.hs deleted file mode 100644 index 463ea9c..0000000 --- a/workspace/test/ExampleSpec.hs +++ /dev/null @@ -1,13 +0,0 @@ -module ExampleSpec where -import Test.Hspec -import Example - --- main is optional -main :: IO () -main = hspec spec - -spec :: Spec -spec = do - describe "add" $ do - it "adds Nums" $ do - (add 1 1) `shouldBe` (2 :: Integer) From 66cc2249a7cfcfde3f1fdf913d2eec4f21155e2b Mon Sep 17 00:00:00 2001 From: Mayowa Pitan Date: Mon, 30 Nov 2026 16:19:24 +0100 Subject: [PATCH 2/2] Publish amd64 and arm64 images --- .github/workflows/ci.yml | 18 +++++-- .github/workflows/push-image.yml | 86 ++++++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56121f0..7185d01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,16 @@ on: jobs: build: - runs-on: ubuntu-latest + # Build on each platform the release publishes, on native runners. + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-24.04 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} if: ${{ github.repository == 'codewars/haskell' }} steps: - uses: actions/checkout@v4 @@ -17,17 +26,18 @@ jobs: uses: docker/build-push-action@v6 with: context: . + platforms: ${{ matrix.platform }} push: false # Make the image available in next step load: true tags: ghcr.io/codewars/haskell:latest - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=${{ matrix.platform }} + cache-to: type=gha,mode=max,scope=${{ matrix.platform }} - name: Run Passing Example run: bin/run passing - name: Report Image Size run: | - echo "## Image Size" >> $GITHUB_STEP_SUMMARY + echo "## Image Size (${{ matrix.platform }})" >> $GITHUB_STEP_SUMMARY docker image inspect --format '{{.Size}}' ghcr.io/codewars/haskell:latest | numfmt --to=si --suffix=B >> $GITHUB_STEP_SUMMARY diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index b94ef6a..b257516 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -1,5 +1,6 @@ -# Build and push a Docker image to GitHub Container Registry when -# a new tag is pushed. +# Build and push a multi-platform Docker image to GitHub Container Registry +# when a new tag is pushed. Each platform builds on a native runner, because +# compiling the Haskell packages under QEMU emulation is too slow. name: Push Image on: @@ -7,10 +8,21 @@ on: tags: - "*" +env: + IMAGE: ghcr.io/codewars/haskell + jobs: - build-and-push-image: + build: if: ${{ github.repository == 'codewars/haskell' }} - runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-24.04 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} permissions: contents: read packages: write @@ -27,13 +39,65 @@ jobs: username: codewars password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push image + - name: Build and push by digest + id: build uses: docker/build-push-action@v6 with: context: . - push: true - tags: | - ghcr.io/codewars/haskell:latest - ghcr.io/codewars/haskell:${{ github.ref_name }} - cache-from: type=gha - cache-to: type=gha,mode=max + platforms: ${{ matrix.platform }} + outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true + cache-from: type=gha,scope=${{ matrix.platform }} + cache-to: type=gha,mode=max,scope=${{ matrix.platform }} + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digest-${{ strategy.job-index }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + needs: build + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digest-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: codewars + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create multi-platform tags + working-directory: /tmp/digests + run: | + sources=() + for digest in *; do sources+=("$IMAGE@sha256:$digest"); done + docker buildx imagetools create \ + -t "$IMAGE:latest" \ + -t "$IMAGE:${{ github.ref_name }}" \ + "${sources[@]}" + + - name: Check both platforms are published + run: | + manifest=$(docker buildx imagetools inspect --raw "$IMAGE:${{ github.ref_name }}") + echo "$manifest" | jq -e '[.manifests[].platform | "\(.os)/\(.architecture)"] | index("linux/amd64") and index("linux/arm64")' + docker buildx imagetools inspect "$IMAGE:${{ github.ref_name }}"