Skip to content

Commit

Permalink
[ ci ] Make Agda binary distributable hence cachable
Browse files Browse the repository at this point in the history
  • Loading branch information
banacorn committed Nov 21, 2024
1 parent 0e2c17a commit f745133
Showing 1 changed file with 78 additions and 36 deletions.
114 changes: 78 additions & 36 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
agda: ["Agda-2.6.4", "Agda-2.7.0"]
agda: ["Agda-2.7.0"]
# agda: ["Agda-2.6.4", "Agda-2.7.0"]
fail-fast: false

# Steps represent a sequence of tasks that will be executed as part of the job
Expand All @@ -41,9 +42,11 @@ jobs:
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
run: |
Expand All @@ -53,35 +56,45 @@ 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 "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 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
# - 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
uses: actions/cache/restore@v4
with:
path: ${{ env.STACK_LOCAL_BIN }}
key: ${{ runner.os }}-stack-binaries-${{ matrix.agda }}
path: ${{ env.DIST }}
key: ${{ env.DIST }}
restore-keys: |
${{ runner.os }}-stack-binaries
${{ env.DIST }}
- name: ⏬ Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: πŸ› οΈ Add Stack install directory to PATH
run: echo $STACK_LOCAL_BIN >> $GITHUB_PATH

- name: πŸ› οΈ Add ${{ env.DIST }} to PATH
run: echo ${{ env.DIST }} >> $GITHUB_PATH

- name: πŸ” Check if Agda has been installed
id: check-agda
continue-on-error: true
Expand All @@ -91,34 +104,63 @@ jobs:
if: ${{ steps.check-agda.outcome == 'failure'}}
run: |
stack install --resolver=lts-20.26 ${{ matrix.agda }}
which agda
agda --version
- name: πŸ“¦ Move artefacts to ${{ env.DIST }}
continue-on-error: true
run: |
dist=${{ env.DIST }}
mkdir -p "${dist}"
if [[ ${{ runner.os }} == "Windows" ]]; then
cp "${{ env.STACK_LOCAL_BIN }}"/agda.exe "${dist}"
strip "${dist}"/agda.exe
file "${dist}"/agda.exe
else
cp "${{ env.STACK_LOCAL_BIN }}"/agda "${dist}"
strip "${dist}"/agda
file "${dist}"/agda
fi
ls "${dist}"
- name: πŸ” Check if Agda has been installed again
continue-on-error: true
run: which agda

# things to be cached
- name: πŸ’Ύ Cache stack global package db
if: always() && env.AGDA_INSTALLED != '0' && 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 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() && env.AGDA_INSTALLED != '0' && steps.stack-binaries.outputs.cache-hit != 'true'
# - 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() && steps.agda-artefacts.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ env.STACK_LOCAL_BIN }}
key: ${{ steps.stack-binaries.outputs.cache-primary-key }}
path: ${{ env.DIST }}
key: ${{ steps.agda-artefacts.outputs.cache-primary-key }}

- name: ⏬ Install NPM Dependencies
run: npm install

- name: πŸ”¨ Build stuff
run: npm run build

- name: πŸš— Run tests (Linux)
if: runner.os == 'Linux'
run: xvfb-run -a npm test
- name: πŸš— Run tests
run: |
if [[ ${{ runner.os }} == "Linux" ]]; then
xvfb-run -a npm test
else
npm test
fi
- name: πŸš— Run tests (Windows, MacOS)
if: runner.os != 'Linux'
run: npm test

0 comments on commit f745133

Please sign in to comment.