From 8dea3c6745a4692c10a0aff6cab37fc4c91c7f6d Mon Sep 17 00:00:00 2001 From: Hernan Rajchert Date: Tue, 22 Nov 2022 16:39:29 -0300 Subject: [PATCH] Re-add ci tests and hooks --- .github/workflows/test.yml | 64 ++---------- .stylish-haskell.yaml | 2 +- flake.lock | 109 ++++++++++++++++++++- flake.nix | 89 +++++++++++++++-- marlowe-playground-server/app/Webserver.hs | 2 +- nix/fix-png-optimization/default.nix | 7 ++ nix/fix-stylish-haskell/default.nix | 13 +++ nix/formatting.nix | 40 ++++++++ nix/scripts.nix | 47 +++++---- nix/tests/default.nix | 36 +++++++ nix/tests/generated.nix | 27 +++++ nix/tests/nixpkgs-fmt.nix | 21 ++++ nix/tests/png-optimization.nix | 30 ++++++ nix/tests/prettier.nix | 46 +++++++++ nix/tests/purs-tidy.nix | 40 ++++++++ nix/tests/shellcheck.nix | 31 ++++++ nix/tests/stylish-haskell.nix | 41 ++++++++ 17 files changed, 560 insertions(+), 85 deletions(-) create mode 100644 nix/fix-png-optimization/default.nix create mode 100644 nix/fix-stylish-haskell/default.nix create mode 100644 nix/formatting.nix create mode 100644 nix/tests/default.nix create mode 100644 nix/tests/generated.nix create mode 100644 nix/tests/nixpkgs-fmt.nix create mode 100644 nix/tests/png-optimization.nix create mode 100644 nix/tests/prettier.nix create mode 100644 nix/tests/purs-tidy.nix create mode 100644 nix/tests/shellcheck.nix create mode 100644 nix/tests/stylish-haskell.nix diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2432ca9dae..562e412895 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,92 +14,46 @@ on: - shlevy workflow_call: jobs: - nix-instantiate: - strategy: - matrix: - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v16 - with: - nix_path: nixpkgs=channel:nixos-unstable - install_url: https://releases.nixos.org/nix/nix-2.5.1/install - extra_nix_config: | - allowed-uris = ${{ env.ALLOWED_URIS }} - trusted-public-keys = ${{ env.TRUSTED_PUBLIC_KEYS }} - substituters = ${{ env.SUBSTITUTERS }} - experimental-features = nix-command flakes - - uses: cachix/cachix-action@v10 - with: - name: ${{ env.CACHE_NAME }} - authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - run: nix-instantiate release.nix --arg checkMaterialization true --arg supportedSystems '[ builtins.currentSystem ]' --restrict-eval -I . nix-code-formatting: strategy: matrix: os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v16 with: nix_path: nixpkgs=channel:nixos-unstable - install_url: https://releases.nixos.org/nix/nix-2.5.1/install + install_url: https://releases.nixos.org/nix/nix-2.8.1/install extra_nix_config: | allowed-uris = ${{ env.ALLOWED_URIS }} trusted-public-keys = ${{ env.TRUSTED_PUBLIC_KEYS }} substituters = ${{ env.SUBSTITUTERS }} experimental-features = nix-command flakes - - uses: cachix/cachix-action@v10 + - uses: cachix/cachix-action@v12 with: name: ${{ env.CACHE_NAME }} authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - run: nix-build -A tests.nixpkgsFmt -A tests.pursTidy -A tests.prettier -A tests.shellcheck -A tests.stylishHaskell --arg supportedSystems '[ builtins.currentSystem ]' --restrict-eval -I . + - run: nix build .#test-nix-fmt .#test-prettier .#test-purs-tidy .#test-png .#test-shell .#test-stylish-haskell nix-code-generation: strategy: matrix: os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2.3.4 - - uses: cachix/install-nix-action@v16 - with: - nix_path: nixpkgs=channel:nixos-unstable - install_url: https://releases.nixos.org/nix/nix-2.5.1/install - extra_nix_config: | - allowed-uris = ${{ env.ALLOWED_URIS }} - trusted-public-keys = ${{ env.TRUSTED_PUBLIC_KEYS }} - substituters = ${{ env.SUBSTITUTERS }} - experimental-features = nix-command flakes - - uses: cachix/cachix-action@v10 - with: - name: ${{ env.CACHE_NAME }} - authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - run: nix-build -A tests.generated --arg supportedSystems '[ builtins.currentSystem ]' --restrict-eval -I . - check-for-updates: - strategy: - matrix: - os: [ubuntu-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v3 - uses: cachix/install-nix-action@v16 with: nix_path: nixpkgs=channel:nixos-unstable - install_url: https://releases.nixos.org/nix/nix-2.5.1/install + install_url: https://releases.nixos.org/nix/nix-2.8.1/install extra_nix_config: | allowed-uris = ${{ env.ALLOWED_URIS }} trusted-public-keys = ${{ env.TRUSTED_PUBLIC_KEYS }} substituters = ${{ env.SUBSTITUTERS }} experimental-features = nix-command flakes - - uses: cachix/cachix-action@v10 + - uses: cachix/cachix-action@v12 with: name: ${{ env.CACHE_NAME }} authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - run: | - nix flake lock - nix-shell --command "update-client-deps" - # Disabled until we can find a way to run it only for Linux - # nix-shell --command "updateMaterialized" --option trusted-public-keys "${{ env.TRUSTED_PUBLIC_KEYS }}" --option substituters "${{ env.SUBSTITUTERS }}" - git diff --exit-code + - run: nix build .#test-generated + diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml index 3f00f0f752..77168f23e0 100644 --- a/.stylish-haskell.yaml +++ b/.stylish-haskell.yaml @@ -6,7 +6,7 @@ steps: records: always - imports: align: none - post_qualify: true + post_qualify: false - language_pragmas: remove_redundant: false diff --git a/flake.lock b/flake.lock index 10433934f2..43e1aeb40e 100644 --- a/flake.lock +++ b/flake.lock @@ -204,6 +204,22 @@ "type": "github" } }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1656928814, @@ -279,6 +295,21 @@ "type": "github" } }, + "flake-utils_6": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "ghc-8.6.5-iohk": { "flake": false, "locked": { @@ -296,6 +327,27 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "gomod2nix": { "inputs": { "nixpkgs": "nixpkgs_2", @@ -670,6 +722,22 @@ "type": "indirect" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1668984258, + "narHash": "sha256-0gDMJ2T3qf58xgcSbYoXiRGUkPWmKyr5C3vcathWhKs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "cf63ade6f74bbc9d2a017290f1b2e33e8fbfa70a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-unstable": { "locked": { "lastModified": 1663905476, @@ -733,6 +801,22 @@ "type": "github" } }, + "nixpkgs_5": { + "locked": { + "lastModified": 1668994630, + "narHash": "sha256-1lqx6HLyw6fMNX/hXrrETG1vMvZRGm2XVC9O/Jt0T6c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "af50806f7c6ab40df3e6b239099e8f8385f6c78b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "old-ghc-nix": { "flake": false, "locked": { @@ -750,6 +834,28 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_3", + "flake-utils": "flake-utils_6", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_5", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1669152228, + "narHash": "sha256-FEDReoTLWJHXcNso7aaAlAUU7uOqIR6Hc/C/nqlfooE=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "078b0dee35e2da01334af682ec347463b70a9986", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "easy-purescript-nix": "easy-purescript-nix", @@ -758,7 +864,8 @@ "nixpkgs": [ "haskellNix", "nixpkgs-unstable" - ] + ], + "pre-commit-hooks": "pre-commit-hooks" } }, "stackage": { diff --git a/flake.nix b/flake.nix index 9d87effed7..93ccd9d0de 100644 --- a/flake.nix +++ b/flake.nix @@ -1,15 +1,15 @@ { - inputs.haskellNix.url = "github:input-output-hk/haskell.nix"; inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; inputs.easy-purescript-nix = { url = "github:justinwoo/easy-purescript-nix"; flake = false; }; - outputs = { self, nixpkgs, flake-utils, haskellNix, easy-purescript-nix }: + outputs = { self, nixpkgs, flake-utils, haskellNix, easy-purescript-nix, pre-commit-hooks }: let supportedSystems = [ "x86_64-linux" @@ -24,9 +24,57 @@ in p // { purs = p.purs-0_15_2; }; + fixPngOptimization = pkgs.callPackage ./nix/fix-png-optimization { }; + fixStylishHaskell = pkgs.callPackage ./nix/fix-stylish-haskell { }; + + writeShellScriptBinInRepoRoot = name: script: pkgs.writeShellScriptBin name '' + cd `${pkgs.git}/bin/git rev-parse --show-toplevel` + ${script} + ''; + scripts = import ./nix/scripts.nix { - inherit pkgs easyPS; + inherit pkgs easyPS writeShellScriptBinInRepoRoot; inherit (pkgs.nodePackages) prettier; + + }; + + formatting = import ./nix/formatting.nix { + inherit writeShellScriptBinInRepoRoot pkgs easyPS; + }; + + tests = import ./nix/tests/default.nix { + inherit pkgs fixPngOptimization fixStylishHaskell; + inherit (formatting) fix-prettier; + inherit (easyPS) purs-tidy; + src = ./.; + play-generated = scripts.generated-purescript; + }; + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = (pkgs.lib.cleanSource ./.); + hooks = { + prettier = { + enable = true; + types_or = [ "javascript" "css" "html" ]; + }; + purs-tidy-hook = { + enable = true; + name = "purs-tidy"; + description = "Ensure PureScript files are formatted"; + entry = "${easyPS.purs-tidy}/bin/purs-tidy format-in-place"; + files = "\\.purs$"; + language = "system"; + }; + shellcheck.enable = true; + stylish-haskell.enable = true; + nixpkgs-fmt.enable = true; + png-optimization = { + enable = true; + name = "png-optimization"; + description = "Ensure that PNG files are optimized"; + entry = "${pkgs.optipng}/bin/optipng"; + files = "\\.png$"; + }; + }; }; overlays = [ haskellNix.overlay @@ -40,6 +88,12 @@ # hlint = {}; haskell-language-server = { }; }; + shell.shellHook = '' + ${pre-commit-check.shellHook} + + # The green prompt familiar to those used to nix-shell + export PS1="\n\[\033[1;32m\][nix develop:\w]\$\[\033[0m\] " + ''; shell.buildInputs = (with pkgs; [ nixpkgs-fmt @@ -48,8 +102,15 @@ ) ++ (with scripts; [ - marlowePlaygroundGeneratePurs - startBackend + marlowe-playground-generate-purs + start-backend + ] + ) + ++ + (with formatting; [ + fix-prettier + fix-purs-tidy + fix-nix-fmt ] ) ++ @@ -62,12 +123,17 @@ purescript-language-server pscid ] + ++ [ + fixPngOptimization + fixStylishHaskell + ] ) ; }; }) ]; + pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; }; flake = pkgs.playground.flake { }; ghc-with-marlowe = pkgs.playground.ghcWithPackages (ps: [ ps.marlowe ]); @@ -77,7 +143,18 @@ legacyPackages = pkgs; }) { - packages = { inherit ghc-with-marlowe; }; + packages = { + inherit ghc-with-marlowe fixPngOptimization fixStylishHaskell; + inherit (scripts) marlowe-playground-generate-purs generated-purescript; + inherit (formatting) fix-purs-tidy fix-nix-fmt; + test-nix-fmt = tests.nixpkgsFmt; + test-prettier = tests.prettier; + test-generated = tests.generated; + test-purs-tidy = tests.pursTidy; + test-png = tests.pngOptimization; + test-stylish-haskell = tests.stylishHaskell; + test-shell = tests.shellcheck; + }; } ); diff --git a/marlowe-playground-server/app/Webserver.hs b/marlowe-playground-server/app/Webserver.hs index 7e47f0522d..3c6ddd1ed3 100644 --- a/marlowe-playground-server/app/Webserver.hs +++ b/marlowe-playground-server/app/Webserver.hs @@ -10,8 +10,8 @@ import Data.Time.Units (Second) import qualified Marlowe.Symbolic.Server as MS import Network.Wai.Handler.Warp as Warp import Servant (serve, (:<|>) ((:<|>))) -import Server (initializeServerContext) import qualified Server +import Server (initializeServerContext) import qualified Webghc.Server as Webghc type API = Server.Web :<|> Webghc.API :<|> MS.API diff --git a/nix/fix-png-optimization/default.nix b/nix/fix-png-optimization/default.nix new file mode 100644 index 0000000000..e3a7af2c71 --- /dev/null +++ b/nix/fix-png-optimization/default.nix @@ -0,0 +1,7 @@ +{ writeShellScriptBin, fd, optipng }: + +writeShellScriptBin "fix-png-optimization" '' + ${fd}/bin/fd \ + --extension png \ + --exec "${optipng}/bin/optipng" {} +'' diff --git a/nix/fix-stylish-haskell/default.nix b/nix/fix-stylish-haskell/default.nix new file mode 100644 index 0000000000..4968a98096 --- /dev/null +++ b/nix/fix-stylish-haskell/default.nix @@ -0,0 +1,13 @@ +{ writeShellScriptBin, fd, stylish-haskell }: + +writeShellScriptBin "fix-stylish-haskell" '' + # stylish-haskell can fail for some files that it can't parse, and fd will terminate + # if any of the exec commands fail. Rather than blacklisting the bad files, we simply + # ignore the exit code, which is usually unhelpful. + ${fd}/bin/fd \ + --extension hs \ + --exclude 'dist-newstyle/*' \ + --exclude 'dist/*' \ + --exclude '.stack-work/*' \ + --exec bash -c "${stylish-haskell}/bin/stylish-haskell -i {} || true" +'' diff --git a/nix/formatting.nix b/nix/formatting.nix new file mode 100644 index 0000000000..3ae21a05e4 --- /dev/null +++ b/nix/formatting.nix @@ -0,0 +1,40 @@ +{ writeShellScriptBinInRepoRoot +, pkgs +, easyPS +}: +let + inherit (builtins) concatStringsSep; + inherit (pkgs.nodePackages) prettier; + inherit (easyPS) purs-tidy; + xargs = "${pkgs.findutils}/bin/xargs"; + extensionsToRegex = extensions: "\\.(${concatStringsSep "|" extensions})"; + writeFormatter = name: cmd: extensions: writeShellScriptBinInRepoRoot "fix-${name}" '' + set -e + echo formatting with ${name} + ${pkgs.git}/bin/git ls-files ':!:bitte/node/config/*'\ + | grep -E '${extensionsToRegex extensions}' \ + | ${xargs} -d $'\\n' ${cmd} + echo done. + ''; +in +{ + fix-prettier = writeFormatter + "prettier" + "${prettier}/bin/prettier -w" + [ "js" "ts" "css" "html" ]; + fix-purs-tidy = writeFormatter + "purs-tidy" + "${purs-tidy}/bin/purs-tidy format-in-place" + [ "purs" ]; + fix-nix-fmt = writeFormatter + "nixfmt" + "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" + [ "nix" ]; + purs-tidy-hook = { + enable = true; + name = "purs-tidy"; + entry = "${purs-tidy}/bin/purs-tidy format-in-place"; + files = "\\.purs$"; + language = "system"; + }; +} diff --git a/nix/scripts.nix b/nix/scripts.nix index cc08120ebd..b3c1e10403 100644 --- a/nix/scripts.nix +++ b/nix/scripts.nix @@ -1,40 +1,45 @@ -{ pkgs, easyPS, prettier }: +{ pkgs, easyPS, prettier, writeShellScriptBinInRepoRoot }: let - writeShellScriptBinInRepoRoot = name: script: pkgs.writeShellScriptBin name '' - cd `${pkgs.git}/bin/git rev-parse --show-toplevel` - ${script} + + # Output containing the purescript bridge code + generated-purescript = pkgs.runCommand "marlowe-playground-purescript" { } '' + mkdir $out + ${pkgs.playground.hsPkgs.marlowe-playground-server.components.exes.marlowe-playground-server}/bin/marlowe-playground-server psgenerator $out + cp ${builtins.path { name = "tidyrc.json"; path = ../.tidyrc.json; } } $out/.tidyrc.json + cp ${builtins.path { name = "tidyoperators"; path = ../.tidyoperators; } } $out/.tidyoperators + cd $out + ${easyPS.purs-tidy}/bin/purs-tidy format-in-place * + ${prettier}/bin/prettier -w . + rm -f $out/.tidyrc.json + rm -f $out/.tidyoperators ''; - marlowePlaygroundGeneratePurs = writeShellScriptBinInRepoRoot "marlowe-playground-generate-purs" '' - #!/bin/bash + # generate-purescript = writeShellScriptBinInRepoRoot "marlowe-playground-generate-purs" '' + # generated=./marlowe-playground-client/generated + # rm -rf $generated + # cp -a $(nix-build -A marlowe-playground.generated-purescript --no-out-link "$@") $generated + # chmod -R +w $generated + # ''; + + + marlowe-playground-generate-purs = writeShellScriptBinInRepoRoot "marlowe-playground-generate-purs" '' generated=./marlowe-playground-client/generated # Clean old build rm -rf $generated # Re-generate the files - mkdir -p $generated - nix run .#marlowe-playground-server:exe:marlowe-playground-server -- psgenerator $generated - - # Format them - cp ${builtins.path { name = "tidyrc.json"; path = ../.tidyrc.json; } } $generated/.tidyrc.json - cp ${builtins.path { name = "tidyoperators"; path = ../.tidyoperators; } } $generated/.tidyoperators - cd $generated - ${easyPS.purs-tidy}/bin/purs-tidy format-in-place * - ${prettier}/bin/prettier -w . - rm -f .tidyrc.json - rm -f .tidyoperators - cd ../.. + cp -a $(nix build .#generated-purescript --no-link --print-out-paths) $generated chmod -R +w $generated ''; - build-ghc-with-marlowe = "$(nix build .#ghc-with-marlowe --print-out-paths)"; + build-ghc-with-marlowe = "$(nix build .#ghc-with-marlowe --no-link --print-out-paths)"; # start-backend: script to start the plutus-playground-server # # Note: We need to add ghc to the path because the server provides /runghc # which needs ghc and dependencies. - startBackend = writeShellScriptBinInRepoRoot "marlowe-playground-server" '' + start-backend = writeShellScriptBinInRepoRoot "marlowe-playground-server" '' echo "marlowe-playground-server: for development use only" GHC_WITH_PKGS=${build-ghc-with-marlowe} export PATH=$GHC_WITH_PKGS/bin:$PATH @@ -43,5 +48,5 @@ let ''; in { - inherit marlowePlaygroundGeneratePurs startBackend; + inherit marlowe-playground-generate-purs start-backend generated-purescript; } diff --git a/nix/tests/default.nix b/nix/tests/default.nix new file mode 100644 index 0000000000..869f7b5ef5 --- /dev/null +++ b/nix/tests/default.nix @@ -0,0 +1,36 @@ +{ pkgs +, fixStylishHaskell +, purs-tidy +, fix-prettier +, fixPngOptimization +, src +, play-generated +}: +{ + shellcheck = pkgs.callPackage ./shellcheck.nix { inherit src; }; + stylishHaskell = pkgs.callPackage ./stylish-haskell.nix { + inherit src fixStylishHaskell; + }; + + generated = pkgs.callPackage ./generated.nix { + inherit src play-generated; + }; + + pursTidy = pkgs.callPackage ./purs-tidy.nix { + inherit src purs-tidy; + }; + + prettier = pkgs.callPackage ./prettier.nix { + inherit src fix-prettier; + }; + + nixpkgsFmt = pkgs.callPackage ./nixpkgs-fmt.nix { + inherit src; + inherit (pkgs) nixpkgs-fmt; + }; + + pngOptimization = pkgs.callPackage ./png-optimization.nix { + inherit src fixPngOptimization; + }; + +} diff --git a/nix/tests/generated.nix b/nix/tests/generated.nix new file mode 100644 index 0000000000..937caafa1f --- /dev/null +++ b/nix/tests/generated.nix @@ -0,0 +1,27 @@ +{ runCommand, play-generated, src, diffutils, glibcLocales }: +runCommand "generated-purescript-test" +{ + buildInputs = [ diffutils glibcLocales ]; +} '' + set +e + echo ${toString src} + cp -a ${src} expected + cp -a ${src} actual + chmod -R +w actual + rm -rf actual/marlowe-playground-client/generated + cp -a ${play-generated} actual/marlowe-playground-client/generated + diff --brief --recursive expected actual + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + mkdir -p $out/nix-support + diff -ur expected actual > $out/actual.diff + echo "file none $out/actual.diff" > $out/nix-support/hydra-build-products + echo "*** actual found changes that need addressed first" + echo "*** Please run \`generate-purescript\` and commit changes." + echo "*** or apply the diff generated by hydra if you don't have nix." + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi +'' diff --git a/nix/tests/nixpkgs-fmt.nix b/nix/tests/nixpkgs-fmt.nix new file mode 100644 index 0000000000..f19168c731 --- /dev/null +++ b/nix/tests/nixpkgs-fmt.nix @@ -0,0 +1,21 @@ +{ runCommand, nixpkgs-fmt, src }: + +# Runs `nixpkgs-fmt --check` on ${src}. If nixpkgs-fmt +# reports that files need to be re-formatted details are +# written to `$out/nix-support/hydra-build-products` +runCommand "nixpkgs-fmt" +{ + buildInputs = [ nixpkgs-fmt ]; +} '' + set +e + nixpkgs-fmt --check ${src} 2>&1 >nixpkgs-fmt.log + if [ $? -ne 0 ]; then + mkdir -p $out/nix-support + cat nixpkgs-fmt.log > $out/nix-support/hydra-build-products + echo "*** nixpkgs-fmt found files that haven't been formatted" + echo "*** Please run \`nix run .#fix-nix-fmt\` and commit the changes" + exit 1 + else + echo 0 > $out + fi +'' diff --git a/nix/tests/png-optimization.nix b/nix/tests/png-optimization.nix new file mode 100644 index 0000000000..de9a20e1b3 --- /dev/null +++ b/nix/tests/png-optimization.nix @@ -0,0 +1,30 @@ +{ runCommand, lib, src, diffutils, glibcLocales, fixPngOptimization }: +let + # just pngs + src' = lib.sourceFilesBySuffices src [ ".png" ]; +in +runCommand "png-optimization-check" +{ + buildInputs = [ fixPngOptimization diffutils glibcLocales ]; +} '' + set +e + cp -a ${src'} orig + cp -a ${src'} png + chmod -R +w png + cd png + fix-png-optimization + cd .. + diff --brief --recursive orig png > /dev/null + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + mkdir -p $out/nix-support + diff -ur orig png > $out/png.diff + echo "file none $out/png.diff" > $out/nix-support/hydra-build-products + echo "*** optipng found changes that need addressed first" + echo "*** Please run \`nix run .#fixPngOptimization\` and commit changes." + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi +'' diff --git a/nix/tests/prettier.nix b/nix/tests/prettier.nix new file mode 100644 index 0000000000..3cb97cb5a0 --- /dev/null +++ b/nix/tests/prettier.nix @@ -0,0 +1,46 @@ +{ runCommand, fix-prettier, src, lib, diffutils, glibcLocales }: +let + # just JavaScript, HTML, and CSS sources + src' = lib.cleanSourceWith { + inherit src; + filter = with lib; + name: type: + let baseName = baseNameOf (toString name); in + ( + (type == "regular" && hasSuffix ".js" baseName) || + (type == "regular" && hasSuffix ".ts" baseName) || + (type == "regular" && hasSuffix ".html" baseName) || + (type == "regular" && hasSuffix ".css" baseName) || + (type == "directory" && (baseName != "generated" + && baseName != "output" + && baseName != "node_modules" + && baseName != ".spago")) + ); + }; +in +runCommand "prettier-check" +{ + buildInputs = [ fix-prettier diffutils glibcLocales ]; +} '' + set +e + cp -a ${src'} orig + cp -a ${src'} prettier + chmod -R +w prettier + cd prettier + fix-prettier + cd .. + diff --brief --recursive orig prettier > /dev/null + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + mkdir -p $out/nix-support + diff -ur orig prettier > $out/prettier.diff + echo "file none $out/prettier.diff" > $out/nix-support/hydra-build-products + echo "*** prettier found changes that need addressed first" + echo "*** Please run \`nix-shell --run fix-prettier\` and commit changes" + echo "*** or apply the diff generated by hydra if you don't have nix." + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi +'' diff --git a/nix/tests/purs-tidy.nix b/nix/tests/purs-tidy.nix new file mode 100644 index 0000000000..edd695a5f5 --- /dev/null +++ b/nix/tests/purs-tidy.nix @@ -0,0 +1,40 @@ +{ runCommand, purs-tidy, src, lib }: +let + # just purescript sources + src' = lib.cleanSourceWith { + inherit src; + filter = with lib; + name: type: + let baseName = baseNameOf (toString name); in + ( + baseName == ".tidyoperators" || + baseName == ".tidyrc.json" || + (type == "regular" && hasSuffix ".purs" baseName) || + type == "directory" + ); + }; +in +runCommand "purs-tidy-check" +{ + buildInputs = [ purs-tidy ]; +} '' + set +e + echo ${toString src'} + cp -a ${src'} orig + cp -a ${src'} purs-tidy + chmod -R +w purs-tidy + cd purs-tidy + ${purs-tidy}/bin/purs-tidy format-in-place * + cd .. + diff --brief --recursive orig purs-tidy + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + echo "*** purs-tidy found changes that need addressed first" + echo "*** Please run \`nix run .#fix-purs-tidy\` and commit changes" + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi + +'' diff --git a/nix/tests/shellcheck.nix b/nix/tests/shellcheck.nix new file mode 100644 index 0000000000..9de53ccd14 --- /dev/null +++ b/nix/tests/shellcheck.nix @@ -0,0 +1,31 @@ +{ runCommand, shellcheck, src, lib }: +let + # just the shell scripts + src' = lib.cleanSourceWith { + inherit src; + filter = with lib; + name: type: + let baseName = baseNameOf (toString name); in + ( + (type == "regular" && hasSuffix ".sh" baseName) || + (type == "directory") + ); + }; +in +runCommand "shellcheck" { buildInputs = [ shellcheck ]; } '' + EXIT_STATUS=0 + cd ${src'} + while IFS= read -r -d ''' i + do + if shellcheck -x -e 1008 -e 2148 "$i" + then + echo "$i [ PASSED ]" + else + echo "$i [ FAILED ]" + EXIT_STATUS=$(($EXIT_STATUS+1)) + fi + done < <(find -name '*.sh' -print0) + echo $EXIT_STATUS > $out + echo Total Failed Files: $EXIT_STATUS + exit "$EXIT_STATUS" +'' diff --git a/nix/tests/stylish-haskell.nix b/nix/tests/stylish-haskell.nix new file mode 100644 index 0000000000..1cad85c71e --- /dev/null +++ b/nix/tests/stylish-haskell.nix @@ -0,0 +1,41 @@ +{ runCommand, fixStylishHaskell, src, lib, diffutils, glibcLocales }: +let + # just haskell sources and the stylish-haskell config file + src' = lib.cleanSourceWith { + inherit src; + filter = with lib; + name: type: + let baseName = baseNameOf (toString name); in + ( + (type == "regular" && hasSuffix ".hs" baseName) || + (type == "regular" && hasSuffix ".yaml" baseName) || + (type == "directory" && (baseName != "dist-newstyle" && baseName != "dist" && baseName != ".stack-work")) + ); + }; +in +runCommand "stylish-check" +{ + buildInputs = [ fixStylishHaskell diffutils glibcLocales ]; +} '' + set +e + cp -a ${src'} orig + cp -a ${src'} stylish + chmod -R +w stylish + cd stylish + fix-stylish-haskell + cd .. + diff --brief --recursive orig stylish > /dev/null + EXIT_CODE=$? + if [[ $EXIT_CODE != 0 ]] + then + mkdir -p $out/nix-support + diff -ur orig stylish > $out/stylish.diff + echo "file none $out/stylish.diff" > $out/nix-support/hydra-build-products + echo "*** Stylish-haskell found changes that need addressed first" + echo "*** Please run \`nix run .#fixStylishHaskell\` and commit changes" + echo "*** or apply the diff generated by hydra if you don't have nix." + exit $EXIT_CODE + else + echo $EXIT_CODE > $out + fi +''