Skip to content

Commit

Permalink
Add Makefile fmt target (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
saschagrunert committed Jun 3, 2019
1 parent b39341c commit a9388a3
Show file tree
Hide file tree
Showing 18 changed files with 316 additions and 80 deletions.
116 changes: 109 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,142 @@
version: 2.1

executors:
docker:
container:
docker:
- image: &image nixos/nix
- image: nixos/nix

workflows:
version: 2
pipeline:
jobs:
- build
- doc
- doc-publish:
requires:
- doc
filters:
branches:
only: master
- lint
- test

prepare-env: &prepare-env
run:
name: Install dependencies
command: |
apk add -y make
command: apk add -y bash ca-certificates curl findutils git make openssh

jobs:
build:
executor: docker
executor: container
steps:
- <<: *prepare-env
- checkout
- restore_cache:
keys:
- v1-build-{{ checksum "nix/nixpkgs.json" }}
- run:
name: build
command: make
- save_cache:
key: v1-build-{{ checksum "nix/nixpkgs.json" }}
paths:
- /nix
- store_artifacts:
path: result/bin/performabot
path: result/bin
destination: bin
- store_artifacts:
path: result/lib
destination: lib

doc:
executor: container
steps:
- <<: *prepare-env
- checkout
- restore_cache:
keys:
- v1-doc-{{ checksum "nix/nixpkgs.json" }}
- run:
name: documentation
command: make doc
- save_cache:
key: v1-doc-{{ checksum "nix/nixpkgs.json" }}
paths:
- /nix
- dist-newstyle
- store_artifacts:
path: dist-newstyle
destination: .
- persist_to_workspace:
root: .
paths:
- dist-newstyle

doc-publish:
executor: container
steps:
- add_ssh_keys:
fingerprints:
- bd:c1:fb:d1:82:51:92:b3:00:1c:e0:f8:99:a3:40:46
- <<: *prepare-env
- checkout
- attach_workspace:
at: .
- run:
name: Setup git
command: |
mkdir -p ~/.ssh
echo -e "Host github.com\n\tStrictHostKeyChecking no\n" \
>> ~/.ssh/config
git config --global user.email mail@saschagrunert.de
git config --global user.name "CircleCI"
- run:
name: Deploy documentation
command: |
git fetch origin gh-pages
git checkout -f gh-pages
mv dist-newstyle /
rm -rf *
mv $(find /dist-newstyle -name index.html -printf '%h')/* .
git add .
git diff-index --quiet HEAD || git commit -m 'Update documentation'
git push -f origin gh-pages
lint:
executor: docker
executor: container
steps:
- <<: *prepare-env
- checkout
- restore_cache:
keys:
- v1-lint-{{ checksum "nix/nixpkgs.json" }}
- run:
name: lint
command: make lint
- save_cache:
key: v1-lint-{{ checksum "nix/nixpkgs.json" }}
paths:
- /nix

test:
executor: container
steps:
- <<: *prepare-env
- checkout
- restore_cache:
keys:
- v1-test-{{ checksum "nix/nixpkgs.json" }}
- run:
name: test
command: make test
- run:
name: Upload coverage
command: /bin/bash -c 'bash <(curl -s https://codecov.io/bash)'
- save_cache:
key: v1-test-{{ checksum "nix/nixpkgs.json" }}
paths:
- /nix
- dist-newstyle
- store_artifacts:
path: dist-newstyle
destination: .
20 changes: 20 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
codecov:
notify:
after_n_builds: 1
require_ci_to_pass: false

coverage:
precision: 1
round: down
range: 50..75

status:
project: true
patch: true
changes: false

comment:
layout: "header, diff"
behavior: default
require_changes: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.orig
.ghc.environment.*
dist
dist-*
result
43 changes: 17 additions & 26 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
Copyright (c) 2019, Sascha Grunert
MIT License

All rights reserved.
Copyright (c) 2019 Sascha Grunert

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Sascha Grunert nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
51 changes: 43 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
.PHONY: cabal2nix lint shell

all:
nix-build release.nix
nix-build nix/release.nix

define nix-shell
nix-shell --pure -p ${1} --run ${2}
nix-shell nix/shell.nix --pure $(1)
endef

define nix-shell-run
$(call nix-shell,--run "$(1)")
endef

.PHONY: cabal2nix
cabal2nix:
$(call nix-shell,cabal2nix,"cabal2nix ." > default.nix)
$(call nix-shell-run,cd nix && cabal2nix .. > default.nix)

.PHONY: clean
clean:
$(call nix-shell-run,git clean -fdx)

.PHONY: doc
doc:
$(call nix-shell-run,cabal new-haddock)

lint: cabal2nix
$(call nix-shell,git,"git diff --exit-code")
.PHONY: fmt
fmt:
floskell src/*.hs

.PHONY: hlint
hlint:
$(call nix-shell-run,hlint -g)

.PHONY: lint
lint: cabal2nix hlint
$(call nix-shell-run,git diff --exit-code)

.PHONY: nixpkgs
nixpkgs:
nix-shell -p nix-prefetch-git --run "nix-prefetch-git --no-deepClone \
https://github.com/nixos/nixpkgs > nix/nixpkgs.json"

.PHONY: repl
repl:
$(call nix-shell-run,cabal new-repl exe:performabot)

.PHONY: shell
shell:
nix-shell --pure shell.nix
$(call nix-shell)

.PHONY: test
test:
$(call nix-shell-run,\
cabal new-test --enable-coverage --enable-library-coverage)
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# performabot

[![CircleCI](https://circleci.com/gh/saschagrunert/performabot.svg?style=shield)](https://circleci.com/gh/saschagrunert/performabot)
[![Coverage](https://codecov.io/gh/saschagrunert/performabot/branch/master/graph/badge.svg)](https://codecov.io/gh/saschagrunert/performabot)
[![Doc](https://img.shields.io/badge/doc-performabot-orange.svg)](https://saschagrunert.github.io/performabot)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/saschagrunert/performabot/blob/master/LICENSE)
8 changes: 5 additions & 3 deletions default.nix → nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
mkDerivation {
pname = "performabot";
version = "0.1.0";
src = ./.;
isLibrary = false;
src = ./..;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base ];
executableHaskellDepends = [
base heavy-logger mtl text-format-heavy
];
license = stdenv.lib.licenses.bsd3;
testHaskellDepends = [ base ];
license = stdenv.lib.licenses.mit;
}
7 changes: 7 additions & 0 deletions nix/nixpkgs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"url": "https://github.com/nixos/nixpkgs",
"rev": "1a28cf89432d5f3c06134c20f866570a2594e149",
"date": "2019-06-03T05:52:47-07:00",
"sha256": "18prhyilncrmrh6n4bprzs37g8q5bfa68n39d3pc1cm77p67zma5",
"fetchSubmodules": false
}
8 changes: 8 additions & 0 deletions nix/nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let
json = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
nixpkgs = import (builtins.fetchTarball {
name = "nixos-unstable";
url = "${json.url}/archive/${json.rev}.tar.gz";
inherit (json) sha256;
});
in nixpkgs
4 changes: 4 additions & 0 deletions nix/release.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let
pkgs = import ./nixpkgs.nix { };
in
pkgs.haskellPackages.callPackage ./default.nix { }
14 changes: 14 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let
pkgs = import ./nixpkgs.nix { };
project = import ./release.nix;
in
pkgs.stdenv.mkDerivation {
name = "shell";
buildInputs = with pkgs; project.env.nativeBuildInputs ++ [
cabal-install
cabal2nix
git
hlint
nix-prefetch-git
];
}
8 changes: 0 additions & 8 deletions nixpkgs.nix

This file was deleted.

Loading

0 comments on commit a9388a3

Please sign in to comment.