Skip to content

Commit

Permalink
Merge branch 'master' into select-required-isNew
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Oct 1, 2023
2 parents 919d89c + 0b0ce55 commit 623ef5e
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ jobs:
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/a95ed9fe764c3ba2bf2d2fa223012c379cd6b32e.tar.gz
if: matrix.os != 'ARM64'
- uses: cachix/cachix-action@v12
with:
name: digitallyinduced
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
if: matrix.os != 'ARM64'
- run: git clone https://github.com/digitallyinduced/ihp-boilerplate.git
- name: Cache build directory
uses: actions/cache@v2
with:
path: |
ihp-boilerplate/build
key: ${{ runner.os }}-ghc
if: matrix.os != 'ARM64'
- run: |
cd ihp-boilerplate
php ../.github/patch-flakes.php ${{ github.ref }} ${{ github.event.repository.full_name }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/keep_releases_in_cachix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ jobs:
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/a95ed9fe764c3ba2bf2d2fa223012c379cd6b32e.tar.gz
if: matrix.os != 'ARM64'
- uses: cachix/cachix-action@v12
with:
name: digitallyinduced
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
if: matrix.os != 'ARM64'
- run: git clone https://github.com/digitallyinduced/ihp-boilerplate.git
- run: |
cd ihp-boilerplate
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr_compile_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ jobs:
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/a95ed9fe764c3ba2bf2d2fa223012c379cd6b32e.tar.gz
if: matrix.os != 'ARM64'
- uses: cachix/cachix-action@v12
with:
name: digitallyinduced
skipPush: true
if: matrix.os != 'ARM64'
- run: |
cd $GITHUB_WORKSPACE
mkdir -p ~/.config/nixpkgs
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ jobs:
- uses: cachix/install-nix-action@v22
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/a95ed9fe764c3ba2bf2d2fa223012c379cd6b32e.tar.gz
if: matrix.os != 'ARM64'
- uses: cachix/cachix-action@v12
with:
name: digitallyinduced
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
if: matrix.os != 'ARM64'
- run: nix develop --impure --command tests
56 changes: 30 additions & 26 deletions Guide/editors.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -214,40 +214,44 @@ To quickly look up function type signatures you can use the built-in hoogle serv

To install it:

1. Open `default.nix`
2. Add `withHoogle = true;` to the `haskellEnv` block, like this:
1. Open `flake.nix`
2. Add `withHoogle = true;` to the `ihp` project block, inside `perSystem` function invocation like this:

```nix
let
ihp = builtins.fetchGit {
url = "https://github.com/digitallyinduced/ihp.git";
ref = "refs/tags/v0.14.0";
};
haskellEnv = import "${ihp}/NixSupport/default.nix" {
ihp = ihp;
haskellDeps = p: with p; [
cabal-install
base
wai
text
hlint
p.ihp
];
otherDeps = p: with p; [
# Native dependencies, e.g. imagemagick
];
projectPath = ./.;
withHoogle = true; # <-------
...
outputs = inputs@{ ihp, flake-parts, systems, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = import systems;
imports = [ ihp.flakeModules.default ];
perSystem = { pkgs, ... }: {
ihp = {
enable = true;
projectPath = ./.;
packages = with pkgs; [
# Native dependencies, e.g. imagemagick
];
haskellPackages = p: with p; [
# Haskell dependencies go here
p.ihp
cabal-install
base
wai
text
hlint
];
withHoogle = true; # <-------
};
};
};
in
haskellEnv
```

Run `devenv up` to remake your dev environment.

After that you can use the following command to start hoogle at `localhost:8080`:

```bash
nix-shell --run 'hoogle server --local -p 8080'
hoogle server --local -p 8080
```
2 changes: 1 addition & 1 deletion Guide/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<a class="nav-link" href="https://www.youtube.com/playlist?list=PLenFm8BWuKlS0IaE31DmKB_PbkMLmwWmG" target="_blank">IHP Casts</a>
<a class="nav-link" href="https://ihp.digitallyinduced.com/api-docs/" target="_blank">API Docs</a>
<a class="nav-link" href="https://digitallyinduced.us10.list-manage.com/subscribe?u=03763c34fa6aaa4c52edfe6ce&id=a09e22a2d3" target="_blank">Newsletter</a>
<a class="nav-link" href="https://forum.ihpapp.com/" target="_blank">IHP Forum</a>
<a class="nav-link" href="https://discuss.ihp.digitallyinduced.com/" target="_blank">IHP Forum</a>
<a class="nav-link" href="https://stackoverflow.com/questions/tagged/ihp" target="_blank">StackOverflow #ihp</a>

<div class="mt-2">
Expand Down
69 changes: 69 additions & 0 deletions Guide/testing.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following setup and tests can be viewed in the [Blog example](https://github

```haskell
# Test/Main.hs

module Main where

import Test.Hspec
Expand Down Expand Up @@ -128,6 +129,12 @@ package flags have changed, resetting and loading new packages...
Loaded GHCi configuration from /home/amitaibu/Sites/Haskell/ihp/blog/.ghci
```

Another way of executing the tests, that we'll use on CI, is to use the `runghc` command, while running `devenv up` on another tab:

```
nix-shell --run "runghc $(make print-ghc-extensions) -i. -ibuild -iConfig Test/Main.hs"
```

## Setting the Current User During Testing

Use `withUser` to call an action with a specific user during testing:
Expand Down Expand Up @@ -293,3 +300,65 @@ tests = aroundAll (withIHPApp WebApplication config) do

## Advanced
For more details on how to structure test suites see the [Hspec manual](http://hspec.github.io/) (a Haskell testing library). You also might want to check out the cool [Hedgehog](https://hedgehog.qa/) library for automated property tests.

## GitHub Actions

The following GitHub Action workflow can be used to run the tests on CI:

```yaml
# .github/workflows/test.yml

name: Test

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/51bcdc4cdaac48535dabf0ad4642a66774c609ed.tar.gz

# Use the cachix cache for faster builds.
- name: Cachix Init
uses: cachix/cachix-action@v12
with:
name: digitallyinduced
skipPush: true

# Install devenv.
- uses: cachix/cachix-action@v12
with:
name: devenv
- name: Install devenv.sh
run: nix profile install github:cachix/devenv/latest
shell: sh

# Install direnv, which also `direnv allow`s the project.
- uses: HatsuneMiku3939/direnv-action@v1
with:
direnvVersion: 2.32.3

- run: |
# Build generated files.
nix-shell --run "make build/Generated/Types.hs"
# Start the project in the background.
nix-shell --run "devenv up &"
# Execute the tests.
nix-shell --run "runghc $(make print-ghc-extensions) -i. -ibuild -iConfig Test/Main.hs"
```
3 changes: 1 addition & 2 deletions IHP/RouterSupport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ instance {-# OVERLAPPABLE #-} (Show controller, AutoRoute controller) => HasPath
-- | Parses the HTTP Method from the request and returns it.
getMethod :: (?context :: RequestContext) => Parser StdMethod
getMethod =
case parseMethod ?context.request.requestMethod of
case parseMethod ?context.request.requestMethod of
Left error -> fail (ByteString.unpack error)
Right method -> pure method
{-# INLINABLE getMethod #-}
Expand Down Expand Up @@ -968,6 +968,5 @@ routeParam paramName =
--
-- > <a href={ShowProjectAction projectId}>Show project</a>
--
-- See https://forum.ihpapp.com/ShowThread?threadId=ad73d6a5-2481-4e2f-af46-9bf8849f998b
-- See https://github.com/digitallyinduced/ihp/issues/840
instance ((T.TypeError (T.Text "Looks like you forgot to pass a " :<>: (T.ShowType argument) :<>: T.Text " to this " :<>: (T.ShowType controller))), Data argument, Data controller, Data (argument -> controller)) => AutoRoute (argument -> controller) where
2 changes: 1 addition & 1 deletion IHP/SchemaCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ findForeignKeyConstraint CreateTable { name } column =
compileEnumDataDefinitions :: (?schema :: Schema) => Statement -> Text
compileEnumDataDefinitions CreateEnumType { values = [] } = "" -- Ignore enums without any values
compileEnumDataDefinitions enum@(CreateEnumType { name, values }) =
"data " <> modelName <> " = " <> (intercalate " | " valueConstructors) <> " deriving (Eq, Show, Read, Enum)\n"
"data " <> modelName <> " = " <> (intercalate " | " valueConstructors) <> " deriving (Eq, Show, Read, Enum, Bounded)\n"
<> "instance FromField " <> modelName <> " where\n"
<> indent (unlines (map compileFromFieldInstanceForValue values))
<> " fromField field (Just value) = returnError ConversionFailed field (\"Unexpected value for enum value. Got: \" <> Data.String.Conversions.cs value)\n"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<a href="https://twitter.com/digitallyinduce" target="_blank">
<img src="https://img.shields.io/twitter/follow/digitallyinduce"/>
</a>


<a href="https://console.algora.io/org/digitallyinduced/bounties?status=open" target="_blank">
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fconsole.algora.io%2Fapi%2Fshields%2Fdigitallyinduced%2Fbounties%3Fstatus%3Dopen"/>
</a>

<img src="https://api.scarf.sh/v2/packages/digitallyinduced/4b7241ee-9679-43fa-9b27-b5595b775c30/downloads-badge"/>
</p>

Expand Down Expand Up @@ -157,7 +157,7 @@ There's more on the IHP website.

Questions, or need help with haskell type errors? [Join our Slack Community](https://ihp.digitallyinduced.com/Slack)

[Also check out the IHP Forum!](https://forum.ihpapp.com/)
[Also check out the IHP Forum!](https://discuss.ihp.digitallyinduced.com/)

## Contributing

Expand Down
12 changes: 11 additions & 1 deletion flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ ihpFlake:
type = lib.types.path;
};

withHoogle = lib.mkOption {
description = ''
Enable Hoogle support. Adds `hoogle` command to PATH.
'';
type = lib.types.bool;
default = false;
};

dontCheckPackages = lib.mkOption {
description = ''
List of Haskell package names whose tests are skipped during build.
Expand Down Expand Up @@ -166,7 +174,9 @@ ihpFlake:
containers = lib.mkForce {};

languages.haskell.enable = true;
languages.haskell.package = ghcCompiler.ghc.withPackages cfg.haskellPackages;
languages.haskell.package = (if cfg.withHoogle
then ghcCompiler.ghc.withHoogle
else ghcCompiler.ghc.withPackages) cfg.haskellPackages;

languages.haskell.languageServer = ghcCompiler.haskell-language-server;
languages.haskell.stack = null; # Stack is not used in IHP
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

inputs = {
# TODO use nixpkgs-unstable and just .lock a version?
nixpkgs.url = "github:NixOS/nixpkgs?rev=ff303118b2ec262eb342eab88ae79318fac66d52";
nixpkgs.url = "github:mpscholten/nixpkgs/fix-ghc-m1-issue";

# pre-defined set of default target systems
systems.url = "github:nix-systems/default";
Expand Down
18 changes: 9 additions & 9 deletions ihp-hsx/ihp-hsx.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ source-repository head
library
default-language: Haskell2010
build-depends:
base >= 4.16.3 && < 4.17
, blaze-html >= 0.9.1 && < 0.10
, bytestring >= 0.11.3 && < 0.12
, template-haskell >= 2.18.0 && < 2.19
, text >= 1.2.5 && < 1.3
, containers >= 0.6.5 && < 0.7
, blaze-markup >= 0.8.2 && < 0.9
, ghc >= 9.2.4 && < 9.3
, megaparsec >= 9.2.1 && < 9.3
base >= 4.17.0 && < 4.18
, blaze-html >= 0.9.1 && < 0.10
, bytestring >= 0.11.3 && < 0.12
, template-haskell >= 2.19.0 && < 2.20
, text >= 2.0.1 && < 2.1
, containers >= 0.6.6 && < 0.7
, blaze-markup >= 0.8.2 && < 0.9
, ghc >= 9.4.4 && < 9.5
, megaparsec >= 9.2.2 && < 9.3
, string-conversions >= 0.4.0 && < 0.5
default-extensions:
OverloadedStrings
Expand Down

0 comments on commit 623ef5e

Please sign in to comment.