hledger/.github/workflows/binaries-linux-x64.yml
Simon Michael ce0cd344b5 ci: more consistent, platform- and ghc-specific cache keys
These github caches created once and never updated; so it's important
to have keys that are specific enough that it doesn't
(a) waste time restoring cached data that we won't be able to use
(b) fail to cache new data because it thinks the old cache was used.
2025-06-13 21:00:42 -10:00

119 lines
4.5 KiB
YAML

# TRIGGER: Runs on any push to binaries-linux-x64 or binaries branches.
# ACTION: Builds, unit-tests and saves linux x64 static binaries with cabal and the ghc version below,
# in an Alpine linux container which provides the statically-linkable musl.
name: binaries-linux-x64
on:
push:
branches: [ binaries-linux-x64, binaries ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-24.04
# arch: x64
# image: https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
container: alpine:latest
env:
stack: stack
ghc: 9.10.1
steps:
- name: Check out
uses: actions/checkout@v4
# have to fetch everything for git describe for --version
with:
fetch-depth: 0
- name: Install general tools with system package manager
run: |
apk --no-cache add gmp-dev gmp-static libffi-dev zlib-dev zlib-static ncurses-dev ncurses-static binutils-gold curl gcc g++ git make xz tar perl
# CACHES
- name: Cache - ~/.ghcup
id: ghcup
uses: actions/cache@v4
with:
path: ~/.ghcup
key: ${{ runner.os }}-x64-ghcup-${{ env.ghc }}-${{ hashFiles('**.yaml') }}
restore-keys: |
${{ runner.os }}-x64-ghcup-${{ env.ghc }}
- name: Cache - ~/.cabal
id: cabal
uses: actions/cache@v4
with:
path: ~/.cabal
key: ${{ runner.os }}-x64-cabal-${{ env.ghc }}-${{ hashFiles('**.yaml') }}
restore-keys: |
${{ runner.os }}-x64-cabal-${{ env.ghc }}
# actions:
# - name: Check tool versions
# run: |
# which ghcup; ghcup --version
# which stack; stack --version
# which cabal; cabal --version
# which ghc; ghc --version
# no preinstalled tools because using alpine container
# - name: Install haskell ghcup
# uses: haskell/ghcup-setup@v1
- name: Add .ghcup/bin to PATH
run: |
echo "$HOME/.ghcup/bin/" >> $GITHUB_PATH
- name: Install haskell tools if needed
run: |
if [[ ! -x ~/.ghcup/bin/ghcup ]]; then mkdir -p ~/.ghcup/bin && curl https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > ~/.ghcup/bin/ghcup && chmod +x ~/.ghcup/bin/ghcup; fi; printf "ghcup: "; ghcup --version
if [[ ! -x ~/.ghcup/bin/ghc-9.12.2 ]]; then ghcup install ghc 9.12.2 && ghcup set ghc 9.12.2; fi; printf "ghc: "; ghc --version
if [[ ! -x ~/.ghcup/bin/cabal ]]; then ghcup install cabal 3.14.2.0 && ghcup set cabal 3.14.2.0; fi; printf "cabal: "; cabal --version
- name: Update cabal package index
run: |
cabal update
- name: Build with cabal
run: |
cabal build --enable-executable-static --ghc-options=-Werror hledger || (echo "ERROR: building hledger failed"; false)
cabal build --enable-executable-static --ghc-options=-Werror hledger-ui || (echo "ERROR: building hledger-ui failed"; false)
cabal build --enable-executable-static --ghc-options=-Werror hledger-web || (echo "ERROR: building hledger-web failed"; false)
- name: Gather binaries
run: |
mkdir tmp
cp dist-newstyle/build/x86_64-linux/ghc-*/hledger-*/x/hledger/build/hledger/hledger tmp
cp dist-newstyle/build/x86_64-linux/ghc-*/hledger-ui-*/x/hledger-ui/build/hledger-ui/hledger-ui tmp
cp dist-newstyle/build/x86_64-linux/ghc-*/hledger-web-*/x/hledger-web/build/hledger-web/hledger-web tmp
cp hledger/embeddedfiles/*.1 tmp
cp hledger/embeddedfiles/*.info tmp
cp hledger/shell-completion/hledger-completion.bash tmp
strip tmp/hledger
strip tmp/hledger-ui
strip tmp/hledger-web
cd tmp
tar cvf hledger-linux-x64.tar hledger hledger-ui hledger-web *.1 *.info hledger-completion.bash
ldd hledger || true
ldd hledger-ui || true
ldd hledger-web || true
# file hledger
# file hledger-ui
# file hledger-web
./hledger --version
./hledger-ui --version
./hledger-web --version
# upload-artifact loses execute permissions, so we tar the binaries to preserve them.
# github UI always zips artifacts when they are downloaded, so we don't bother compressing the tar.
# https://github.com/actions/upload-artifact?tab=readme-ov-file#limitations
# In release workflows, we repack these using the platform's native compression scheme.
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: hledger-linux-x64
path: tmp/hledger-linux-x64.tar