From 19c7ecb9212855f4e66ece2d3b353ef18a9268c1 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 18 Jan 2020 11:29:01 -0500 Subject: [PATCH] Add builds for Mac OS --- .circleci/config.yml | 46 +++++++++++++++++------- .circleci/release.sh | 47 ------------------------ .circleci/tickle.sh | 24 ------------- Makefile | 86 +++++++++++++++++++++++++++++++++++++++++--- README.md | 2 +- 5 files changed, 116 insertions(+), 89 deletions(-) delete mode 100755 .circleci/release.sh delete mode 100755 .circleci/tickle.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c8027d..0929fce 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,13 +4,40 @@ workflows: version: 2 build-workflow: jobs: - - build: + - build-macos: + filters: + tags: + only: /.*/ + - build-linux: filters: tags: only: /.*/ jobs: - build: + build-macos: + macos: + xcode: '10.0.0' + steps: + - run: + name: 'Set up PATH' + command: echo "export PATH=$HOME/.local/bin:$PATH" >> $BASH_ENV + - checkout + - run: + name: 'Install stack' + command: 'curl -sSL https://get.haskellstack.org/ | sh' + - restore_cache: + key: 'v6-{{ arch }}' + - run: + command: 'make build test' + - save_cache: + key: 'v6-{{ arch }}' + paths: + - '~/.stack' + - run: + name: 'Upload release' + command: 'if [[ ! -z "$CIRCLE_TAG" ]]; then make release; fi' + + build-linux: # This image has most Haskell stuff preinstalled. docker: - image: 'haskell:8.6' @@ -18,20 +45,13 @@ jobs: steps: - checkout - restore_cache: - key: 'v5-patat-{{ arch }}-{{ .Branch }}' + key: 'v6-{{ arch }}' - run: - # We set jobs to 1 here because that prevents Out-Of-Memory exceptions - # while compiling dependencies. - name: 'Install' - command: '.circleci/tickle.sh stack build --pedantic --copy-bins --jobs=1 --no-terminal --test' - - run: - name: 'Run golden tests' - command: 'make test' + command: 'make build test' - save_cache: - key: 'v5-patat-{{ arch }}-{{ .Branch }}-{{ .Revision }}' + key: 'v6-{{ arch }}' paths: - - '~/.stack-work' - '~/.stack' - run: name: 'Upload release' - command: '.circleci/release.sh "$CIRCLE_TAG"' + command: 'if [[ ! -z "$CIRCLE_TAG" ]]; then make release; fi' diff --git a/.circleci/release.sh b/.circleci/release.sh deleted file mode 100755 index cf040bc..0000000 --- a/.circleci/release.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash -set -o nounset -o errexit -o pipefail - -TAG="$1" -SUFFIX="linux-$(uname -m)" -USER="jaspervdj" -REPOSITORY="$(basename -- *.cabal ".cabal")" -BINARY="$REPOSITORY" - -echo "Tag: $TAG" -echo "Suffix: $SUFFIX" -echo "Repository: $REPOSITORY" - -$BINARY --version - -if [[ -z "$TAG" ]]; then - echo "Not a tagged build, skipping release..." - exit 0 -fi - -# Install ghr -GHR_VERSION="v0.13.0" -curl --silent -L -O \ - "https://github.com/tcnksm/ghr/releases/download/${GHR_VERSION}/ghr_${GHR_VERSION}_linux_386.tar.gz" -tar xf ghr_${GHR_VERSION}_linux_386.tar.gz -mv ghr_${GHR_VERSION}_linux_386/ghr . - -# Install upx -UPX_VERSION="3.94" -curl --silent -L -O \ - "https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz" -tar xf upx-${UPX_VERSION}-amd64_linux.tar.xz -mv upx-${UPX_VERSION}-amd64_linux/upx . - -# Create tarball -PACKAGE="$REPOSITORY-$TAG-$SUFFIX" -mkdir -p "$PACKAGE" -cp "$(which "$BINARY")" "$PACKAGE" -./upx -q "$PACKAGE/$BINARY" -cp README.* "$PACKAGE" -cp CHANGELOG.* "$PACKAGE" -cp extra/patat.1 "$PACKAGE" -tar -czf "$PACKAGE.tar.gz" "$PACKAGE" -rm -r "$PACKAGE" - -# Actually upload -./ghr -u "$USER" -r "$REPOSITORY" "$TAG" "$PACKAGE.tar.gz" diff --git a/.circleci/tickle.sh b/.circleci/tickle.sh deleted file mode 100755 index 195c29c..0000000 --- a/.circleci/tickle.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -o nounset -o errexit -o pipefail - -function tickle() { - while [ true ]; do - echo "[$(date +%H:%M:%S)] Tickling..." - sleep 60 - done -} - -echo "Forking tickle process..." -tickle & -TICKLE_PID=$! - -echo "Forking build process..." -eval $@ & -BUILD_PID=$! - -echo "Waiting for build thread ($BUILD_PID)..." -wait $BUILD_PID - -echo "Killing tickle thread ($TICKLE_PID)..." -kill $TICKLE_PID -echo "All done!" diff --git a/Makefile b/Makefile index 9f8fede..6feccf6 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,104 @@ +ARCH=$(shell uname -m) +UNAME=$(shell uname | tr 'A-Z' 'a-z') + +PATAT_BINARY=$(HOME)/.local/bin/patat +PATAT_VERSION=$(shell sed -n 's/^Version: *//p' *.cabal) +PATAT_PACKAGE=patat-v$(PATAT_VERSION)-$(UNAME)-$(ARCH) + +GHR_VERSION=0.13.0 +GHR_NAME=ghr_v$(GHR_VERSION)_$(UNAME)_amd64 +GHR_BINARY=$(HOME)/.local/bin/ghr + +UPX_VERSION=3.94 +UPX_NAME=upx-$(UPX_VERSION)-amd64_$(UNAME) +UPX_BINARY=$(HOME)/.local/bin/upx + +ifeq ($(UNAME), darwin) +ARCHIVE=zip +ARCHIVE_CREATE=zip -r +ARCHIVE_EXTRACT=unzip +else +ARCHIVE=tar.gz +ARCHIVE_CREATE=tar czf +ARCHIVE_EXTRACT=tar xvzf +endif + +ifeq ($(UNAME), darwin) # We use `?=` to set SOURCE_DATE_EPOCH only if it is not present. Unfortunately # we can't use `git --date=unix` since only very recent git versions support # that, so we need to make a round trip through `date`. +SOURCE_DATE_EPOCH?=$(shell git log -1 --format=%cd --date=unix) +else SOURCE_DATE_EPOCH?=$(shell date '+%s' \ - --date="$(shell git log -1 --format=%cd --date=rfc)") + --date="$(shell git log -1 --format=%cd --date=rfc)") +endif -extra/patat.1: README.md +ifeq ($(UNAME), darwin) +COMPRESS_BIN_DEPS= +COMPRESS_BIN=ls +else +COMPRESS_BIN_DEPS=$(UPX_BINARY) +COMPRESS_BIN=upx +endif + +# Default target. +build: $(PATAT_BINARY) + +# Upload a release. +release: $(PATAT_PACKAGE).$(ARCHIVE) $(GHR_BINARY) + ghr -u jaspervdj -r patat v$(PATAT_VERSION) $(PATAT_PACKAGE).$(ARCHIVE) + +$(PATAT_PACKAGE).$(ARCHIVE): $(PATAT_BINARY) extra/patat.1 $(COMPRESS_BIN_DEPS) + mkdir $(PATAT_PACKAGE) + cp $(PATAT_BINARY) $(PATAT_PACKAGE)/ + $(COMPRESS_BIN) $(PATAT_PACKAGE)/patat + cp README.md $(PATAT_PACKAGE)/ + cp CHANGELOG.md $(PATAT_PACKAGE)/ + cp LICENSE $(PATAT_PACKAGE)/ + cp extra/patat.1 $(PATAT_PACKAGE)/ + $(ARCHIVE_CREATE) $(PATAT_PACKAGE).$(ARCHIVE) $(PATAT_PACKAGE) + +$(PATAT_BINARY): + stack build -j1 --copy-bins --pedantic + +# GHR is used to upload releases to GitHub. +$(GHR_BINARY): + curl -Lo /tmp/$(GHR_NAME).$(ARCHIVE) \ + https://github.com/tcnksm/ghr/releases/download/v$(GHR_VERSION)/$(GHR_NAME).$(ARCHIVE) + cd /tmp && $(ARCHIVE_EXTRACT) $(GHR_NAME).$(ARCHIVE) + mv /tmp/$(GHR_NAME)/ghr $(GHR_BINARY) + ghr --version + +# UPX is used to compress the resulting binary. We currently don't use this on +# Mac OS. +$(UPX_BINARY): + curl -Lo /tmp/$(UPX_NAME).tar.xz \ + https://github.com/upx/upx/releases/download/v$(UPX_VERSION)/$(UPX_NAME).tar.xz + cd /tmp && tar xf $(UPX_NAME).tar.xz + mv /tmp/$(UPX_NAME)/upx $(UPX_BINARY) + upx --version + +# Man page. +extra/patat.1: README.md $(PATAT_BINARY) SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)" patat-make-man >$@ +# Bash completion. extra/patat.bash-completion: patat --bash-completion-script patat >$@ +.PHONY: completion completion: extra/patat.bash-completion +.PHONY: man man: extra/patat.1 # Also check if we can generate the manual. +.PHONY: test test: man bash tests/golden.sh +.PHONY: clean clean: rm -f extra/patat.1 rm -f extra/make-man rm -f extra/patat.bash-completion - -.PHONY: man completion test clean diff --git a/README.md b/README.md index a98d056..6f28bcd 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ Installation - openSUSE: - Fedora: -You can also find generic linux binaries here: +You can also find generic Linux and Mac OS binaries here: . ### From source