fix(cache): Cache hitting for Cabal build #177
Workflow file for this run
This file contains hidden or 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
| # The following workflow is based on the example provided by | |
| # haskell-actions/setup: | |
| # | |
| # https://github.com/haskell-actions/setup#model-cabal-workflow-with-caching | |
| name: CI | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: build-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| generate-matrix: | |
| name: "Generate matrix from cabal" | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract the tested GHC versions | |
| id: set-matrix | |
| uses: kleidukos/[email protected] | |
| with: | |
| cabal-file: rollbar-client/rollbar-client.cabal | |
| ubuntu-version: latest | |
| macos-version: 13 | |
| version: 0.1.7.0 | |
| build: | |
| name: GHC ${{ matrix.ghc }} on ${{ matrix.os }} | |
| needs: generate-matrix | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Haskell tools | |
| uses: haskell-actions/setup@v2 | |
| id: setup | |
| with: | |
| ghc-version: ${{ matrix.ghc }} | |
| cabal-version: "latest" | |
| cabal-update: true | |
| # TODO: Refine this plan.json configuration | |
| - name: Generate plan.json | |
| 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: 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('**/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 | |
| - name: Save cached dependencies | |
| uses: actions/cache/save@v4 | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| with: | |
| path: ${{ steps.setup.outputs.cabal-store }} | |
| key: ${{ steps.cache.outputs.cache-primary-key }} | |
| - name: Build | |
| run: cabal build all | |
| - name: Run tests | |
| run: cabal test all | |
| env: | |
| ROLLBAR_TOKEN: ${{ secrets.ROLLBAR_TOKEN }} | |