Skip to content

Commit

Permalink
ci: fix install for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
stevana committed Nov 4, 2024
1 parent d673563 commit 764ff2e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ permissions:
contents: write
packages: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
#linux:
# name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
Expand Down Expand Up @@ -157,6 +161,8 @@ jobs:
if: ${{ env.platform == 'x86_64-linux' }}
run: make pull-image

# XXX: only build if Dockerfile changed?
# git diff --name-only ${{ github.event.after }} ${{ github.event.before }} | grep Dockerfile?
- name: Build image (Linux only)
if: ${{ env.platform == 'x86_64-linux' }}
run: make build-image
Expand Down Expand Up @@ -212,6 +218,7 @@ jobs:
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
# XXX: is env needed?
env:
SPEX_GIT_COMMIT: ${{ github.sha }}
run: make build
Expand All @@ -230,7 +237,9 @@ jobs:
github.event_name == 'push' &&
github.ref == 'refs/heads/main' }}
id: install
# XXX: is shell bash needeD?
shell: bash
# XXX: is env needed?
env:
SPEX_GIT_COMMIT: ${{ github.sha }}
run: make install
Expand Down
37 changes: 36 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# This Makefile is supposed to work on Linux, MacOS and Windows (with WSL and
# GNU make). On Linux it should build static binaries using an Alpine
# container. All this should work both on GitHub actions CI and when run
# locally.

OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
PLATFORM := $(shell uname -m)-$(OS)
CABAL_VERSION := $(shell awk '/^version:/ { print $$2 }' spex.cabal)
RELEASED_VERSION := $(shell gh release list --limit 1 \
--exclude-drafts --exclude-pre-releases \
--json tagName \
--jq '.[].tagName // "unreleased" | sub("^v"; "") ')

# This variable is set to true on GitHub's CI.
GITHUB_ACTIONS ?= false

SPEX_GIT_COMMIT ?= $(shell git rev-parse HEAD)
Expand Down Expand Up @@ -33,6 +40,7 @@ NEW_VERSION = "$(shell awk -F '=' '/^new-version/ \
endif

ifeq ($(OS),linux)
ifeq ($(GITHUB_ACTIONS),true)
CABAL := docker run --rm --entrypoint=cabal \
--volume $(PWD):/mnt \
--volume $(HOME)/.cache/cabal/packages:/root/.cache/cabal/packages \
Expand All @@ -41,7 +49,16 @@ ifeq ($(OS),linux)
--env SPEX_GIT_COMMIT=$(SPEX_GIT_COMMIT) \
ghcr.io/spex-lang/spex-build:latest
ENABLE_STATIC := --enable-executable-static

else
CABAL := docker run --rm --entrypoint=cabal \
--volume $(PWD):/mnt \
--volume $(PWD)/.container-cache/cabal/packages:/root/.cache/cabal/packages \
--volume $(PWD)/.container-cache/cabal/store:/root/.local/state/cabal/store \
--volume $(PWD)/dist-newstyle:/mnt/dist-newstyle \
--env SPEX_GIT_COMMIT=$(SPEX_GIT_COMMIT) \
ghcr.io/spex-lang/spex-build:latest
ENABLE_STATIC := --enable-executable-static
endif
else
CABAL := cabal
ENABLE_STATIC :=
Expand All @@ -52,8 +69,15 @@ all: build-deps build test bump install release
# XXX: doesn't configure petstore...
dist-newstyle/cache/plan.json: cabal.project cabal.project.freeze spex.cabal
ifeq ($(OS),linux)
ifeq ($(GITHUB_ACTIONS),true)
mkdir -p $(PWD)/dist-newstyle
mkdir -p $(HOME)/.cache/cabal/packages
mkdir -p $(HOME)/.cabal/store
else
mkdir -p $(PWD)/dist-newstyle
mkdir -p $(PWD)/.container-cache/cabal/packages
mkdir -p $(PWD)/.container-cache/cabal/store
endif
endif
$(CABAL) configure $(ENABLE_STATIC) --disable-profiling --disable-library-for-ghci --enable-library-stripping --enable-executable-stripping --enable-tests --enable-benchmarks --disable-documentation
$(CABAL) update
Expand All @@ -64,6 +88,7 @@ build-deps: dist-newstyle/cache/plan.json
$(CABAL) build all --only-dependencies

build:
# XXX: shouldn't be needed?
$(CABAL) update
$(CABAL) build all

Expand All @@ -87,7 +112,15 @@ bump:
endif

install:
ifeq ($(OS),linux)
# Running `cabal install` inside a container will it inside the
# container, which isn't what we want. Instead find the binary inside
# dist-newstyle, which is shared with the host via a volume mount, and
# copy it from there to the right place.
find dist-newstyle/ -name 'spex*' -type f -executable -exec cp {} $(SPEX_BIN) \;
else
$(CABAL) install all --installdir=$(SPEX_BIN) --install-method=copy --overwrite-policy=always
endif

release:
@echo "NEW_VERSION=$(NEW_VERSION)"
Expand Down Expand Up @@ -117,6 +150,8 @@ release:
endif

clean:
rm -rf dist-newstyle
rm -rf .container-cache

pull-image:
docker pull ghcr.io/spex-lang/spex-build:latest
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ range of software that can be specified and tested will extended in the
[future](ROADMAP.md).

> [!CAUTION]
> Spex is pre-alpha and not suitable for general use yet.
> Spex is pre-alpha and not suitable for general use yet. Please don't share
> just yet, I'll announce it properly soon.
## Features

Expand Down

0 comments on commit 764ff2e

Please sign in to comment.