Skip to content

Commit

Permalink
Updated caching
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeTravelPenguin committed Nov 11, 2023
1 parent 7ac5662 commit 24a1603
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
ghc-version: ['9.6.3']

include:
- os: windows-latest
stack-global: |
~\AppData\Roaming\stack
~\AppData\Local\Programs\stack
- os: ubuntu-latest
stack-global: ~/.stack
- os: macos-latest
stack-global: ~/.stack
steps:
- uses: actions/checkout@v3

Expand All @@ -34,32 +42,39 @@ jobs:
enable-stack: true
stack-version: 'latest'
stack-setup-ghc: true
stack-no-global: true
stack-no-global: false

- name: Restore cached dependencies
- name: Restore stack global dependencies
uses: actions/cache/restore@v3
id: cache
env:
key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-stack-${{ steps.setup.outputs.stack-version }}
id: cache-stack-global
with:
path: |
~/.stack
.stack-work
key: ${{ runner.os }}-stack-${{ hashFiles('stack.yaml.lock', 'package.yaml') }}
restore-keys: |
${{ runner.os }}-stack
path: ${{ matrix.stack-global }}
key: ${{ matrix.os }}-stack-global-

- name: Restore stack-work dependencies
uses: actions/cache/restore@v3
id: cache-stack-work
with:
path: .stack-work
key: ${{ matrix.os }}-stack-work-

- name: Install dependencies
if: steps.cache-stack-global.outputs.cache-hit != 'true' || steps.cache-stack-work.outputs.cache-hit != 'true'
run: stack build --only-dependencies

# Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
- name: Save cached dependencies
- name: Save stack global dependencies
uses: actions/cache/save@v3
if: ${{ steps.cache-stack-global.outputs.cache-primary-key != steps.cache-stack-global.outputs.cache-matched-key }}
with:
path: ${{ matrix.stack-global }}
key: ${{ matrix.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}

- name: Save stack-work dependencies
uses: actions/cache/save@v3
# Caches are immutable, trying to save with the same key would error.
if: ${{ steps.cache.outputs.cache-primary-key != steps.cache.outputs.cache-matched-key }}
if: ${{ steps.cache-stack-work.outputs.cache-primary-key != steps.cache-stack-work.outputs.cache-matched-key }}
with:
path: ${{ steps.setup.outputs.stack-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}
path: .stack-work
key: ${{ matrix.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }}

- name: Build
run: stack build
Expand Down

0 comments on commit 24a1603

Please sign in to comment.