Skip to content

Commit

Permalink
[ ci ] Only setup the Haskell environment when failed to restore prev…
Browse files Browse the repository at this point in the history
…iously cached Agda
  • Loading branch information
banacorn committed Nov 22, 2024
1 parent 470fe8e commit 5809fa3
Showing 1 changed file with 52 additions and 50 deletions.
102 changes: 52 additions & 50 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,9 @@ jobs:

# actions:

- name: ⏬ Setup Haskell environment
id: haskell-setup
uses: haskell-actions/setup@v2
with:
ghc-version: '9.2.8'
stack-version: latest
cabal-update: false
enable-stack: true

# $DIST is where the binary & its dependencies is placed
- name: 🛠️ Setting variables
run: |
echo "STACK_LOCAL_BIN=$(stack path --local-bin)" >> "$GITHUB_ENV"
echo "DIST=${{ matrix.agda }}-${{ matrix.os }}" >> "$GITHUB_ENV"
- name: 🔍 Reviewing variables
Expand All @@ -56,27 +46,26 @@ jobs:
echo "stack-path = ${{ steps.haskell-setup.outputs.stack-path }}"
echo "stack-exe = ${{ steps.haskell-setup.outputs.stack-exe }}"
echo "stack-root = ${{ steps.haskell-setup.outputs.stack-root }}"
echo "STACK_LOCAL_BIN = $STACK_LOCAL_BIN"
echo "DIST = $DIST"
# cached stuff to be restored:
- name: 💾 Restore cached stack global package db
id: stack-global
uses: actions/cache/restore@v4
with:
path: ${{ steps.haskell-setup.outputs.stack-root }}
key: ${{ runner.os }}-stack-global-${{ matrix.agda }}
restore-keys: |
${{ runner.os }}-stack-global
- name: 💾 Restore stack-installed binaries in ~/.local/bin
id: stack-binaries
uses: actions/cache/restore@v4
with:
path: ${{ env.STACK_LOCAL_BIN }}
key: ${{ runner.os }}-stack-binaries-${{ matrix.agda }}
restore-keys: |
${{ runner.os }}-stack-binaries
# - name: 💾 Restore cached stack global package db
# id: stack-global
# uses: actions/cache/restore@v4
# with:
# path: ${{ steps.haskell-setup.outputs.stack-root }}
# key: ${{ runner.os }}-stack-global-${{ matrix.agda }}
# restore-keys: |
# ${{ runner.os }}-stack-global

# - name: 💾 Restore stack-installed binaries in ~/.local/bin
# id: stack-binaries
# uses: actions/cache/restore@v4
# with:
# path: ${{ env.STACK_LOCAL_BIN }}
# key: ${{ runner.os }}-stack-binaries-${{ matrix.agda }}
# restore-keys: |
# ${{ runner.os }}-stack-binaries

- name: 💾 Restore Agda from ${{ env.DIST }}
id: agda-artefacts
Expand Down Expand Up @@ -109,11 +98,24 @@ jobs:
mkdir -p $DIST
mkdir -p $DIST/bin
- name: ⏬ Setup Haskell environment
if: ${{ steps.check-agda.outcome == 'failure'}}
id: haskell-setup
uses: haskell-actions/setup@v2
with:
ghc-version: '9.2.8'
stack-version: latest
cabal-update: false
enable-stack: true

- name: ⏬ Install Agda
if: ${{ steps.check-agda.outcome == 'failure'}}
run: stack install --resolver=lts-20.26 ${{ matrix.agda }}
run: |
stack install --resolver=lts-20.26 ${{ matrix.agda }}
echo "STACK_LOCAL_BIN=$(stack path --local-bin)" >> "$GITHUB_ENV"
- name: 📦 Move artefacts to ${{ env.DIST }}
if: ${{ steps.check-agda.outcome == 'failure'}}
run: |
# Copy the binary:
Expand All @@ -131,33 +133,33 @@ jobs:
# Copy the rest of the artefacts:
cp -a $($STACK_LOCAL_BIN/agda --print-agda-dir)/. $DIST
# Setting the $Agda_datadir environment variable as $DIST
echo "Agda_datadir=$(pwd)/$DIST" >> "$GITHUB_ENV"
- name: 🌐 Setting the $Agda_datadir environment variable
run: echo "Agda_datadir=$(pwd)/$DIST" >> "$GITHUB_ENV"

- name: 🔍 Check if Agda has been installed again
if: ${{ steps.check-agda.outcome == 'failure'}}
run: |
echo "Agda_datadir = $Agda_datadir"
which agda
agda -V
echo "Agda_datadir = $Agda_datadir"
echo "Path of Agda = $(which agda)"
echo "Version of Agda = $(agda -V)"
# things to be cached
- name: 💾 Cache stack global package db
if: always() && steps.stack-global.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ steps.haskell-setup.outputs.stack-root }}
key: ${{ steps.stack-global.outputs.cache-primary-key }}

- name: 💾 Cache stack-installed binaries
if: always() && steps.stack-binaries.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ env.STACK_LOCAL_BIN }}
key: ${{ steps.stack-binaries.outputs.cache-primary-key }}
# - name: 💾 Cache stack global package db
# if: always() && steps.stack-global.outputs.cache-hit != 'true'
# uses: actions/cache/save@v4
# with:
# path: ${{ steps.haskell-setup.outputs.stack-root }}
# key: ${{ steps.stack-global.outputs.cache-primary-key }}

# - name: 💾 Cache stack-installed binaries
# if: always() && steps.stack-binaries.outputs.cache-hit != 'true'
# uses: actions/cache/save@v4
# with:
# path: ${{ env.STACK_LOCAL_BIN }}
# key: ${{ steps.stack-binaries.outputs.cache-primary-key }}

- name: 💾 Cache Agda in ${{ env.DIST }}
if: always()
# if: always() && steps.agda-artefacts.outputs.cache-hit != 'true'
if: always() && steps.agda-artefacts.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ env.DIST }}
Expand Down

0 comments on commit 5809fa3

Please sign in to comment.