From 63d3ad32fd91216062bcf9dcdb7bc07b4fe5e925 Mon Sep 17 00:00:00 2001 From: Adrian Sieber <36796532+ad-si@users.noreply.github.com> Date: Tue, 9 Jan 2024 12:07:03 +0100 Subject: [PATCH] Initial commit --- .github/workflows/ci.yaml | 46 +++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ app/Main.hs | 8 ++++++ changelog.md | 4 +++ fourmolu.yaml | 12 +++++++++ makefile | 11 +++++++++ package.yaml | 51 +++++++++++++++++++++++++++++++++++++++ readme.md | 21 ++++++++++++++++ source/Lib.hs | 7 ++++++ stack.yaml | 5 ++++ stack.yaml.lock | 12 +++++++++ tests/Spec.hs | 10 ++++++++ 12 files changed, 189 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .gitignore create mode 100644 app/Main.hs create mode 100644 changelog.md create mode 100644 fourmolu.yaml create mode 100644 makefile create mode 100644 package.yaml create mode 100644 readme.md create mode 100644 source/Lib.hs create mode 100644 stack.yaml create mode 100644 stack.yaml.lock create mode 100644 tests/Spec.hs diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..08fb53f --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,46 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +jobs: + build: + strategy: + matrix: + os: [ubuntu-22.04, macos-12] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Stack + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-no-global: true + + - name: Cache Stack build files + uses: actions/cache@v3 + with: + path: | + ~/.stack + .stack-work + key: >- + ${{ runner.os }}-stack-${{ + hashFiles('stack.yaml.lock', 'package.yaml') }} + restore-keys: | + ${{runner.os}}-stack + + - name: Test + run: stack test --ghc-options="-O2" + + - name: Copy binary to ~/.local/bin so it can be uploaded + run: stack install + + - name: Upload ${{ runner.os }} Release + uses: actions/upload-artifact@v3 + with: + path: ~/.local/bin/haskell-template + name: haskell-template_${{ runner.os }}_${{ runner.arch }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75fe8a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.stack-work +/*.cabal diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..bcc07bf --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,8 @@ +module Main where + +import Protolude (IO, putStrLn, ($)) +import Lib (sayHello) + +main :: IO () +main = do + putStrLn $ sayHello "World!" diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..5c2d5d5 --- /dev/null +++ b/changelog.md @@ -0,0 +1,4 @@ +# Haskell Template + +- 2023-11-27 - 0.0.0.0 + - Initial release diff --git a/fourmolu.yaml b/fourmolu.yaml new file mode 100644 index 0000000..10624c3 --- /dev/null +++ b/fourmolu.yaml @@ -0,0 +1,12 @@ +indentation: 2 +function-arrows: leading +comma-style: leading +import-export-style: diff-friendly +indent-wheres: true +record-brace-space: false +newlines-between-decls: 2 +haddock-style: multi-line-compact +let-style: auto +in-style: left-align +respectful: true +unicode: never diff --git a/makefile b/makefile new file mode 100644 index 0000000..d008146 --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +.PHONY: test +test: + stack test + +.PHONY: build +build: + stack build + +.PHONY: install +install: + stack install diff --git a/package.yaml b/package.yaml new file mode 100644 index 0000000..f35c72a --- /dev/null +++ b/package.yaml @@ -0,0 +1,51 @@ +name: haskell-template +version: 0.0.0.0 +synopsis: A opinionated template for Haskell projects +description: Please check out the README for more information. +homepage: https://github.com/Airsequel/haskell-template#readme +license: AGPL-3.0-or-later +author: Adrian Sieber +maintainer: github@ad-si.com +copyright: Adrian Sieber +category: Web + +extra-source-files: + - readme.md + +dependencies: + - base + - protolude + +default-extensions: + - NoImplicitPrelude + - OverloadedRecordDot + - OverloadedStrings + +ghc-options: + - -Wall + - -Wcompat + - -Wincomplete-record-updates + - -Wincomplete-uni-patterns + - -Wredundant-constraints + - -fno-warn-orphans + +library: + language: GHC2021 + source-dirs: source + +executables: + haskell-template: + language: GHC2021 + source-dirs: app + main: Main.hs + dependencies: + - haskell-template + +tests: + haskell-template-test: + language: GHC2021 + source-dirs: tests + main: Spec.hs + dependencies: + - haskell-template + - hspec diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..36fea95 --- /dev/null +++ b/readme.md @@ -0,0 +1,21 @@ +# Haskell Template + +Opinionated template for new Haskell projects. + + +## Used Technologies + +- [Stack](https://docs.haskellstack.org/en/stable/README/) +- [Fourmolu](https://fourmolu.github.io) +- [Haskell Language Server ](https://github.com/haskell/haskell-language-server) +- [Protolude](https://github.com/protolude/protolude) + + +## Usage + +1. Clone this repository +1. Rename the folder to your project name +1. Replace all occurences of `haskell-template` with your project name +1. Run `stack test` to build the project and run the tests +1. Run `stack run` to run the project +1. Run `stack install` to install the project (make it available in your PATH) diff --git a/source/Lib.hs b/source/Lib.hs new file mode 100644 index 0000000..9246d00 --- /dev/null +++ b/source/Lib.hs @@ -0,0 +1,7 @@ +module Lib where + +import Protolude (Text, (<>)) + +sayHello :: Text -> Text +sayHello name = + "Hello " <> name <> "!" diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..15b488e --- /dev/null +++ b/stack.yaml @@ -0,0 +1,5 @@ +resolver: lts-21.15 +packages: + - "." + +extra-deps: [] diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..3b6260a --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: 350737ef1c4c748f4c7ff56b6e74f2f6d15039a2f148662a8ec1aded016b80d0 + size: 640033 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/15.yaml + original: lts-21.15 diff --git a/tests/Spec.hs b/tests/Spec.hs new file mode 100644 index 0000000..b2cb3b7 --- /dev/null +++ b/tests/Spec.hs @@ -0,0 +1,10 @@ +import Protolude (IO, ($)) +import Test.Hspec (hspec, shouldBe, describe, it) + +import Lib (sayHello) + +main :: IO () +main = hspec $ do + describe "Haskell Template" $ do + it "prints 'Hello World!'" $ do + sayHello "World" `shouldBe` "Hello World!"