Skip to content

fix(cache): Cache hitting for cabal build #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

name: CI

on:
pull_request:
on:
pull_request:
branches:
- main
push:
Expand All @@ -20,7 +20,7 @@ concurrency:
jobs:
generate-matrix:
name: "Generate matrix from cabal"
outputs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
runs-on: ubuntu-latest
steps:
Expand All @@ -46,21 +46,50 @@ jobs:
id: setup
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: 'latest'
cabal-version: "latest"
cabal-update: true
- name: Configure the build

# TODO: Delete these outputs after testing
#- name: Debug Setup Outputs
# run: |
# echo "GHC Version: ${{ steps.setup.outputs.ghc-version }}"
# echo "Cabal Version: ${{ steps.setup.outputs.cabal-version }}"
# echo "Cabal Store: ${{ steps.setup.outputs.cabal-store }}"
# echo "Runner OS: ${{ runner.os }}"

# TODO: Refine this plan.json configuration
- name: Generate plan.json
run: |
cabal configure --enable-tests --disable-documentation
cabal build all --dry-run
cabal update
cabal build --dry-run --enable-benchmarks --enable-tests all > /dev/null
mkdir -p ${{ github.workspace }}/cache-info
cp dist-newstyle/cache/plan.json ${{ github.workspace }}/cache-info/
echo "Plan JSON Hash: $(sha256sum ${{ github.workspace }}/cache-info/plan.json | cut -d ' ' -f 1)"

# TODO: Configure options is needed???
#- name: Configure the build
# run: |
# cabal configure --enable-tests --disable-documentation
# cabal build all --dry-run

# TODO: delete /cache-info/ path
- 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') }}
key: ${{ env.key }}-plan-${{ hashFiles('**/cache-info/plan.json') }}
restore-keys: ${{ env.key }}-

# Debug the cache hit/miss
- name: Debug Cache Results
run: |
echo "Cache Hit: ${{ steps.cache.outputs.cache-hit }}"
echo "Cache Primary Key: ${{ steps.cache.outputs.cache-primary-key }}"
echo "Cache Matched Key: ${{ steps.cache.outputs.cache-matched-key }}"

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: cabal build all --only-dependencies
Expand Down
Loading