summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2020-08-24 14:27:23 +0200
committerGitHub <noreply@github.com>2020-08-24 14:27:23 +0200
commitce3feb1db9a0e7998a66c9dfdc7aebd9bae79477 (patch)
tree255302cb799ade981fd55d56cbb0ad86d7266389
parent14f943126394b653a6ebac215d5722eb3fe4f6c5 (diff)
downloadstylish-haskell-ce3feb1db9a0e7998a66c9dfdc7aebd9bae79477.tar.gz
Switch to GitHub action
-rw-r--r--.circleci/config.yml31
-rwxr-xr-x.circleci/release.sh45
-rw-r--r--.github/workflows/ci.yml100
-rw-r--r--Makefile65
4 files changed, 165 insertions, 76 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index c8c1def..0000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-version: 2
-
-workflows:
- version: 2
- simple-workflow:
- jobs:
- - build:
- filters:
- tags:
- only: /.*/
-
-jobs:
- build:
- docker:
- - image: 'haskell:8.8'
-
- steps:
- - checkout
- - restore_cache:
- key: 'v3-stylish-haskell-{{ arch }}-{{ .Branch }}'
- - run:
- name: 'Build, install and test'
- command: 'stack build --test --copy-bins --jobs=1'
- - save_cache:
- key: 'v3-stylish-haskell-{{ arch }}-{{ .Branch }}-{{ .Revision }}'
- paths:
- - '~/.stack-work'
- - '~/.stack'
- - run:
- name: 'Upload release'
- command: '.circleci/release.sh "$CIRCLE_TAG"'
diff --git a/.circleci/release.sh b/.circleci/release.sh
deleted file mode 100755
index a55247f..0000000
--- a/.circleci/release.sh
+++ /dev/null
@@ -1,45 +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 CHANGELOG* LICENSE* README* "$PACKAGE"
-tar -czf "$PACKAGE.tar.gz" "$PACKAGE"
-rm -r "$PACKAGE"
-
-# Actually upload
-./ghr -u "$USER" -r "$REPOSITORY" "$TAG" "$PACKAGE.tar.gz"
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..a1f5174
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,100 @@
+name: CI
+
+on: ['pull_request', 'push']
+
+jobs:
+ build:
+ name: Build on ${{ matrix.os }}
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macOS-latest]
+ stack: ["2.1.3"]
+ ghc: ["8.8.3"]
+
+ steps:
+ - name: Get the version
+ id: get_version
+ run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'
+
+ - uses: actions/checkout@v2
+
+ - uses: actions/setup-haskell@v1.1
+ name: Setup Haskell Stack
+ with:
+ ghc-version: ${{ matrix.ghc }}
+ stack-version: ${{ matrix.stack }}
+
+ - uses: actions/cache@v2
+ name: Cache ~/.stack
+ with:
+ path: ~/.stack
+ key: ${{ runner.os }}-${{ matrix.ghc }}-v2
+
+ - name: Add ~/.local/bin to PATH
+ run: echo "::add-path::$HOME/.local/bin"
+
+ - name: Build
+ run: make build
+ id: build
+
+ - name: Test
+ run: make test
+
+ - name: Build artifact
+ if: startsWith(github.ref, 'refs/tags')
+ run: make artifact
+ env:
+ PATAT_TAG: ${{ steps.get_version.outputs.version }}
+
+ - uses: actions/upload-artifact@v2
+ if: startsWith(github.ref, 'refs/tags')
+ with:
+ path: artifacts/*
+ name: artifacts
+
+ release:
+ name: Release
+ needs: build
+ runs-on: ubuntu-latest
+ if: startsWith(github.ref, 'refs/tags')
+
+ steps:
+ - name: Get the version
+ id: get_version
+ run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'
+
+ - uses: actions/download-artifact@v2
+ with:
+ name: artifacts
+
+ - name: Display structure of downloaded files
+ run: ls -R
+
+ - uses: actions/create-release@v1
+ id: create_release
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ tag_name: ${{ steps.get_version.outputs.version }}
+ release_name: ${{ steps.get_version.outputs.version }}
+
+ - name: Upload Linux Asset
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./stylish-haskell-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
+ asset_name: stylish-haskell-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
+ asset_content_type: application/gzip
+
+ - name: Upload MacOS Asset
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }}
+ asset_path: ./stylish-haskell-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
+ asset_name: stylish-haskell-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
+ asset_content_type: application/zip
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..058f0cd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,65 @@
+ARCH=$(shell uname -m)
+UNAME=$(shell uname | tr 'A-Z' 'a-z')
+
+STYLISH_BINARY=$(HOME)/.local/bin/stylish-haskell
+STYLISH_TAG?=v$(shell sed -n 's/^Version: *//p' *.cabal)
+STYLISH_PACKAGE=stylish-haskell-$(STYLISH_TAG)-$(UNAME)-$(ARCH)
+
+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)
+COMPRESS_BIN_DEPS=
+COMPRESS_BIN=ls
+else
+COMPRESS_BIN_DEPS=$(UPX_BINARY)
+COMPRESS_BIN=upx
+endif
+
+STACK=stack --system-ghc
+
+# Default target.
+.PHONY: build
+build: $(STYLISH_BINARY)
+
+# When we want to do a release.
+.PHONY: artifact
+artifact: $(STYLISH_PACKAGE).$(ARCHIVE)
+ mkdir -p artifacts
+ cp $(STYLISH_PACKAGE).$(ARCHIVE) artifacts/
+
+$(STYLISH_PACKAGE).$(ARCHIVE): $(STYLISH_BINARY) $(COMPRESS_BIN_DEPS)
+ mkdir -p $(STYLISH_PACKAGE)
+ cp $(STYLISH_BINARY) $(STYLISH_PACKAGE)/
+ $(COMPRESS_BIN) $(STYLISH_PACKAGE)/stylish-haskell
+ cp README.markdown $(STYLISH_PACKAGE)/
+ cp CHANGELOG $(STYLISH_PACKAGE)/
+ cp LICENSE $(STYLISH_PACKAGE)/
+ $(ARCHIVE_CREATE) $(STYLISH_PACKAGE).$(ARCHIVE) $(STYLISH_PACKAGE)
+
+$(STYLISH_BINARY):
+ $(STACK) build --copy-bins
+
+# 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
+
+.PHONY: test
+test:
+ stack build --test