diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fac1141..b68aec7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,46 +1,14 @@ -name: "Build" - -permissions: - contents: read - pages: write - id-token: write - +name: "Test" on: - push: - branches: [ "main" ] pull_request: - branches: [ "main" ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - + push: jobs: - build: + tests: runs-on: ubuntu-latest - container: - image: "docker://ghcr.io/chrisdone/hell-build:2025-03-04@sha256:ca21e3be038cf1f10fa18306123b4d5f0e2009fe8938cea3afcef7f900bbea71" - - env: - # For the ~/.stack root. - HOME: /root/ - STACK_ROOT: /root/.stack - - # This can be both of these, depending on whether it's a PR or - # main. GitHub Actions is weird. - # - # * "GIT_BRANCH=refs/heads/main" - # * "GIT_BRANCH=cd/2024-08-28-check-examples" - # - GIT_BRANCH: ${{ github.head_ref || github.ref }} - steps: - - run: | - git clone https://github.com/chrisdone/hell /tmp/hell && \ - cd /tmp/hell && \ - git checkout $GIT_BRANCH - - run: | - cd /tmp/hell && stack build --fast - - run: | - cd /tmp/hell && stack exec hell scripts/check-examples.hell - - run: | - cd /tmp/hell && HOME=/home/chris/ stack exec hell scripts/check-docs.hell + - uses: actions/checkout@v5 + - uses: cachix/install-nix-action@v31 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} + - run: nix build + - run: nix flake check diff --git a/flake.nix b/flake.nix index af7bf2a..2e60ed4 100644 --- a/flake.nix +++ b/flake.nix @@ -41,6 +41,15 @@ pkgs.zlib ]; }; + checks = { + run-script-check = pkgs.runCommand "test-hell-script" { + buildInputs = [ app ]; + } '' + hell ${./scripts/check.hell} --dir ${./examples} --dir ${./scripts} + touch $out + ''; + build = app; + }; packages = { default = app; static-arm64 = mkStaticApp pkgsStaticArm64; diff --git a/scripts/check-examples.hell b/scripts/check-examples.hell deleted file mode 100644 index 5d07f2b..0000000 --- a/scripts/check-examples.hell +++ /dev/null @@ -1,10 +0,0 @@ -main = do - examples <- Directory.listDirectory "examples/" - let check = \fp -> do - Text.putStrLn $ Text.concat ["Checking ", fp] - Process.runProcess_ (Process.proc "hell" ["--check", fp]) - Monad.forM_ examples \example -> do - check $ Text.concat ["examples/", example] - check "scripts/static-build.hell" - check "scripts/install-hell.hell" - Text.putStrLn "All OK." diff --git a/scripts/check.hell b/scripts/check.hell index b206d6b..3eae609 100644 --- a/scripts/check.hell +++ b/scripts/check.hell @@ -1,22 +1,24 @@ data Opts = Opts { + dirs :: [Text], compilerStats :: Bool } options = - (\compilerStats -> Main.Opts { compilerStats }) - <$> Options.switch (Flag.long "compiler-stats" <> Flag.help "Pass --compiler-stats in?") + (\dirs compilerStats -> Main.Opts { compilerStats, dirs }) + <$> Alternative.many (Options.strOption (Option.long "dir" <> Option.help "Directory to check")) + <*> Options.switch (Flag.long "compiler-stats" <> Flag.help "Pass --compiler-stats in?") main = do opts <- Options.execParser (Options.info (Main.options <**> Options.helper) Options.fullDesc) let extra = if Record.get @"compilerStats" opts then ["--compiler-stats"] else [] + let dirs = Record.get @"dirs" opts let list = \dir -> - Functor.fmap (List.filter (Text.isSuffixOf ".hell") . List.map (\x -> dir <> x)) + Functor.fmap (List.filter (Text.isSuffixOf ".hell") . List.map (\x -> dir <> "/" <> x)) $ Directory.listDirectory dir - examples <- list "examples/" - scripts <- list "scripts/" - Async.pooledForConcurrently (examples <> scripts) \fp -> do + examples <- Functor.fmap List.concat $ Monad.mapM list dirs + Async.pooledForConcurrently examples \fp -> do Text.putStrLn $ Text.concat ["Checking ", fp] Process.runProcess_ (Process.proc "hell" (["--check", fp] <> extra)) Text.putStrLn "All OK." diff --git a/scripts/readme.md b/scripts/readme.md deleted file mode 100644 index e6c4b1e..0000000 --- a/scripts/readme.md +++ /dev/null @@ -1,62 +0,0 @@ -## Build a distributable - -This builds a fully static musl x86-64 Linux binary. - -Outside of docker (because it uses Docker): - - hell scripts/static-build.hell - -At the end you should have: - - hell-linux-x86-64bit - -## Docs - -Regenerate docs: - - stack run scripts/gen-docs.hell - -Or within the docker container: - - docker exec hell stack run scripts/gen-docs.hell - -Example: - - 25-03-04 21:41:39.839 $ docker exec hell stack run scripts/gen-docs.hell - Generating docs ... - Rendering examples/01-hello-world.hell - Rendering examples/02-interaction.hell - Rendering examples/03-press-any-key.hell - Rendering examples/04-writing-files.hell - Rendering examples/05-lists.hell - Rendering examples/06-polymorphism.hell - Rendering examples/07-loops.hell - Rendering examples/08-tuples.hell - Rendering examples/09-processes.hell - Rendering examples/10-current-directory.hell - Rendering examples/11-env-vars.hell - Rendering examples/12-fib.hell - Rendering examples/13-concurrency.hell - Rendering examples/14-text.hell - Rendering examples/15-type-classes.hell - Rendering examples/16-if.hell - Rendering examples/17-reuse.hell - Rendering examples/18-monads.hell - Rendering examples/19-blog-generator.hell - Rendering examples/20-dollar.hell - Rendering examples/21-json.hell - Rendering examples/22-records.hell - Rendering examples/23-args.hell - Rendering examples/24-exitcode.hell - Rendering examples/25-sum-types.hell - Rendering examples/26-reference-other-types.hell - Rendering examples/27-discussion-64.hell - Rendering examples/28-trees.hell - Rendering examples/29-temp-files.hell - Rendering examples/30-process-handlers.hell - Rendering examples/31-open-file-handle.hell - Rendering examples/32-optparse.hell - Rendering examples/33-null-stream.hell - Rendering examples/34-field-puns.hell - Rendering examples/35-type-sigs.hell - Generated docs. diff --git a/src/Hell.hs b/src/Hell.hs index ccde6f7..c2d0e86 100644 --- a/src/Hell.hs +++ b/src/Hell.hs @@ -2147,6 +2147,7 @@ polyLits = -- Alternative operations "Alternative.optional" (optional) :: forall (f :: Type -> Type) a. (Alternative f) => f a -> f (Maybe a) + "Alternative.many" (many) :: forall (f :: Type -> Type) a. (Alternative f) => f a -> f [a] -- Monadic operations "Monad.mapM_" mapM_ :: forall a (m :: Type -> Type). (Monad m) => (a -> m ()) -> [a] -> m ()