ci: try containerising the whole thing #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: main | |
env: | |
LANG: C.UTF-8 | |
on: | |
push: | |
branches: main | |
pull_request: | |
branches: main | |
permissions: | |
contents: write | |
jobs: | |
# Follows https://github.com/haskell-actions/setup#model-cabal-workflow-with-caching | |
build-and-deploy: | |
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-24.04] | |
ghc-version: ['9.6.6'] | |
cabal-version: ['3.12.1.0'] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: spex-lang | |
password: ${{ secrets.CR_PAT }} | |
- name: Pull build image | |
run: docker pull ghcr.io/spex-lang/static-build:9.6.6 | |
#- name: Restore cached GHC and cabal | |
# uses: actions/cache/restore@v4 | |
# id: ghc-cabal-cache | |
# env: | |
# with: | |
# path: | | |
# ${HOME}/.cabal/bin/cabal | |
# ${HOME}/.ghcup/bin/ghc-${{ matrix.ghc-version }} | |
# key: ${{ runner.os }}-ghc-${{ matrix.ghc-version }}-cabal-${{ matrix.cabal-version }} | |
# - name: Set up GHC ${{ matrix.ghc-version }} | |
# # if: steps.ghc-cabal-cache.outputs.cache-hit != 'true' | |
# uses: haskell-actions/setup@v2 | |
# id: setup | |
# with: | |
# ghc-version: ${{ matrix.ghc-version }} | |
# cabal-version: ${{ matrix.cabal-version }} | |
# cabal-update: true | |
#- name: Save cached GHC and cabal | |
# uses: actions/cache/save@v4 | |
# if: steps.cache.outputs.ghc-cabal-cache-hit != 'true' | |
# with: | |
# path: | | |
# $HOME/.ghcup/ghc/$GHC_VERSION/lib/ghc-$GHC_VERSION/lib/x86_64-linux-ghc-$GHC_VERSION/*.so | |
# $HOME/.ghcup/ghc/${{ matrix.ghc-version }}/lib/ghc-${{ matrix.ghc-version }}/bin/ | |
# $HOME/.ghcup/ghc/${{ matrix.ghc-version }}/lib/ghc-${{ matrix.ghc-version }}/lib/settings | |
# $HOME/.ghcup/ghc/${{ matrix.ghc-version }}/lib/ghc-${{ matrix.ghc-version }}/lib/package.conf.d | |
# ${HOME}/.cabal/bin/cabal | |
# # /root/.ghcup/bin/cabal | |
# # ${HOME}/.ghcup/bin/ghc-${{ matrix.ghc-version }} | |
# key: ${{ steps.ghc-cabal-cache.outputs.cache-primary-key }} | |
- name: Configure the build | |
run: | | |
docker run \ | |
-v "${PWD}":/mnt/:ro \ | |
-v "${HOME}/.cabal/packages":/root/.cache/cabal/packages \ | |
-v "${HOME}/.cabal/store":/root/.local/state/cabal/store \ | |
-v "${PWD}/dist-newstyle":/mnt/dist-newstyle \ | |
--entrypoint=cabal \ | |
ghcr.io/spex-lang/static-build:9.6.6 \ | |
configure --enable-tests --enable-benchmarks --disable-documentation --project-dir=/mnt | |
docker run \ | |
-v "${PWD}":/mnt/:ro \ | |
-v "${HOME}/.cabal/packages":/root/.cache/cabal/packages \ | |
-v "${HOME}/.cabal/store":/root/.local/state/cabal/store \ | |
-v "${PWD}/dist-newstyle":/mnt/dist-newstyle \ | |
--entrypoint=cabal \ | |
ghcr.io/spex-lang/static-build:9.6.6 \ | |
build all --dry-run --project-dir=/mnt | |
# The last step generates dist-newstyle/cache/plan.json for the cache key. | |
- name: Restore cached dependencies | |
uses: actions/cache/restore@v4 | |
id: cache | |
env: | |
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }} | |
with: | |
path: ${{ steps.setup.outputs.cabal-store }} | |
key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }} | |
restore-keys: ${{ env.key }}- | |
- name: Install dependencies | |
# If we had an exact cache hit, the dependencies will be up to date. | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: | |
docker run \ | |
-v "${PWD}":/mnt/:ro \ | |
-v "${HOME}/.cabal/packages":/root/.cache/cabal/packages \ | |
-v "${HOME}/.cabal/store":/root/.local/state/cabal/store \ | |
-v "${PWD}/dist-newstyle":/mnt/dist-newstyle \ | |
--entrypoint=cabal \ | |
ghcr.io/spex-lang/static-build:9.6.6 \ | |
build all --only-dependencies --project-dir=/mnt | |
# Cache dependencies already here, so that we do not have to rebuild them | |
# should the subsequent steps fail. | |
- name: Save cached dependencies | |
uses: actions/cache/save@v4 | |
if: steps.cache.outputs.cache-hit != 'true' | |
with: | |
path: | | |
"${HOME}/.cabal/packages" | |
"${HOME}/.cabal/store" | |
"${PWD}/dist-newstyle" | |
key: ${{ steps.cache.outputs.cache-primary-key }} | |
# - name: Build | |
# run: cabal build all | |
# - name: Run tests | |
# run: cabal test all | |
# - name: Check cabal file | |
# run: cabal check | |
# - name: Build documentation | |
# run: cabal haddock all | |
# | |
- name: Build static binary | |
run: | |
docker run \ | |
-v "${PWD}":/mnt/:ro \ | |
-v "${HOME}/.cabal/packages":/root/.cache/cabal/packages \ | |
-v "${HOME}/.cabal/store":/root/.local/state/cabal/store \ | |
-v "${PWD}/dist-newstyle":/mnt/dist-newstyle \ | |
--entrypoint=cabal \ | |
ghcr.io/spex-lang/static-build:9.6.6 \ | |
build exe:spex exe:spex-demo-petstore --enable-executable-static --project-dir=/mnt | |
# - name: Create new git tag, if merge to main and .cabal version is bumped | |
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
# uses: sol/haskell-autotag@v1 | |
# id: autotag | |
# - name: Create tarball | |
# run: cabal sdist | |
# if: steps.autotag.outputs.created | |
# - uses: haskell-actions/[email protected] | |
# with: | |
# # http://hackage.haskell.org/users/account-management | |
# hackageToken: ${{ secrets.HACKAGE_AUTH_TOKEN }} | |
# publish: true | |
# if: steps.autotag.outputs.created |