[ ci ] Remove hardcoded Stack root on Unix #177
This file contains 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
# modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/windows.yml | |
name: CI (Windows) | |
on: | |
push: | |
branches: [master, ci-*, ci] | |
tags: | |
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 | |
pull_request: | |
branches: [master] | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- name: π₯ Checkout repository | |
uses: actions/checkout@v4 | |
- name: π Install yq (Windows) | |
if: runner.os == 'Windows' | |
uses: frenck/action-setup-yq@v1 | |
- name: π Determine Stack resolver & GHC version | |
run: | | |
STACK_RESOLVER=$(yq .resolver stack.yaml) | |
GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) | |
echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" | |
echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" | |
- name: π Setup Haskell | |
if : runner.os == 'macOS' | |
uses: haskell-actions/setup@v2 | |
id: setup-haskell | |
with: | |
ghc-version: ${{ env.GHC_VERSION }} | |
enable-stack: true | |
stack-version: 'latest' | |
- name: π Determine Stack root | |
run: | | |
STACK_ROOT="$(stack path --stack-root)" | |
echo STACK_ROOT="${STACK_ROOT}" >> "${GITHUB_ENV}" | |
# things to be restored: | |
# Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. | |
- name: πΎ Restore cached stack global package db | |
id: stack-global | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ env.STACK_ROOT }} | |
key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global | |
- name: πΎ Restore cached .stack-work | |
id: stack-work | |
uses: actions/cache/restore@v4 | |
with: | |
path: .stack-work | |
key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work | |
# actions | |
- name: Install the icu library | |
run: | | |
stack exec -- pacman -S --noconfirm mingw-w64-x86_64-icu mingw-w64-x86_64-pkgconf | |
- name: πΈ Build Snapshot | |
run: | | |
stack build --no-terminal --only-snapshot -j1 | |
- name: π§° Build Dependencies | |
run: | | |
stack build --no-terminal --only-dependencies | |
# - name: π¨ Build | |
# run: stack build | |
# - name: π§ͺ Run tests | |
# run: stack test | |
# 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: ${{ env.STACK_ROOT }} | |
key: ${{ steps.stack-global.outputs.cache-primary-key }} | |
- name: πΎ Cache .stack-work | |
if: always() && steps.stack-work.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: .stack-work | |
key: ${{ steps.stack-work.outputs.cache-primary-key }} | |
# artifacts: | |
- name: π¦ Compress executable and data files | |
shell: pwsh | |
run: | | |
# locate the data-dir | |
$snapshot = (stack path --snapshot-install-root) | |
$datadir = (ls $snapshot\share *Agda-* -Recurse -Directory).FullName | |
# locate the executable | |
$local = (stack path --local-install-root) | |
$executable = (ls $local\bin *als.exe* -Recurse -File).FullName | |
# make a temporary directory for compresssing | |
mkdir zip | |
cp -r $datadir zip/data | |
cp $executable zip/ | |
# include text-icu DLLs | |
$mingw64bin = (stack path --extra-library-dirs).split(", ") -match "\\bin" | |
ls $mingw64bin | |
cp (ls $mingw64bin *libicudt*) zip/ | |
cp (ls $mingw64bin *libicuin*) zip/ | |
cp (ls $mingw64bin *libicuuc*) zip/ | |
ls zip | |
# compress | |
cd zip | |
Compress-Archive * als-windows.zip | |
cd .. | |
mv zip/als-windows.zip . | |
- name: π§ͺ Run tests | |
run: stack test --ta --als-path=zip/als.exe | |
# release (optional) | |
- name: π’ Release Artifacts | |
if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release upload ${{ github.ref_name }} als-windows.zip --clobber |