Skip to content

Commit

Permalink
Re-add ci tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrajchert committed Nov 23, 2022
1 parent 9a98c5d commit debcb33
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 80 deletions.
66 changes: 11 additions & 55 deletions .github/workflows/test.yml
Expand Up @@ -14,92 +14,48 @@ 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
# - 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 .
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
# - run: nix-build -A tests.generated --arg supportedSystems '[ builtins.currentSystem ]' --restrict-eval -I .

37 changes: 33 additions & 4 deletions flake.nix
Expand Up @@ -23,11 +23,28 @@
p = pkgs.callPackage (easy-purescript-nix) { };
in
p // { purs = p.purs-0_15_2; };
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;
inherit (formatting) fix-prettier;
src = ./.;
play-generated = scripts.generated-purescript;
};

overlays = [
haskellNix.overlay
(final: prev: {
Expand All @@ -48,8 +65,13 @@
)
++
(with scripts; [
marlowePlaygroundGeneratePurs
startBackend
marlowe-playground-generate-purs
start-backend
]
)
++
(with formatting; [
fix-prettier
]
)
++
Expand All @@ -68,6 +90,7 @@
};
})
];

pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
flake = pkgs.playground.flake { };
ghc-with-marlowe = pkgs.playground.ghcWithPackages (ps: [ ps.marlowe ]);
Expand All @@ -77,7 +100,13 @@
legacyPackages = pkgs;
})
{
packages = { inherit ghc-with-marlowe; };
packages = {
inherit ghc-with-marlowe;
inherit (scripts) marlowe-playground-generate-purs generated-purescript;
test-nix-fmt = tests.nixpkgsFmt;
test-prettier = tests.prettier;
test-generated = tests.generated;
};
}

);
Expand Down
35 changes: 35 additions & 0 deletions nix/formatting.nix
@@ -0,0 +1,35 @@
{ writeShellScriptBinInRepoRoot
, pkgs
, easyPS
}:
let
inherit (builtins) concatStringsSep;
inherit (pkgs.nodePackages) prettier;
inherit (easyPS) purs-tidy;
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" ];
purs-tidy-hook = {
enable = true;
name = "purs-tidy";
entry = "${purs-tidy}/bin/purs-tidy format-in-place";
files = "\\.purs$";
language = "system";
};
}
47 changes: 26 additions & 21 deletions 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
Expand All @@ -43,5 +48,5 @@ let
'';
in
{
inherit marlowePlaygroundGeneratePurs startBackend;
inherit marlowe-playground-generate-purs start-backend generated-purescript;
}
50 changes: 50 additions & 0 deletions nix/tests/default.nix
@@ -0,0 +1,50 @@
{ pkgs
# , gitignore-nix
# , fixStylishHaskell
# , fix-purs-tidy
, fix-prettier
# , fixPngOptimization
, src
# , marlowe-playground
, play-generated
# , web-ghc
# , docs
# , sources
# , vmCompileTests ? false
}:
{
# shellcheck = pkgs.callPackage ./shellcheck.nix { src = cleanSrc; };

# stylishHaskell = pkgs.callPackage ./stylish-haskell.nix {
# src = cleanSrc;
# inherit fixStylishHaskell;
# };

generated = pkgs.callPackage ./generated.nix {
inherit src play-generated;
};

# pursTidy = pkgs.callPackage ./purs-tidy.nix {
# src = cleanSrc;
# inherit fix-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 {
# src = cleanSrc;
# inherit fixPngOptimization;
# };

# vmTests = pkgs.callPackage ./vm.nix {
# inherit vmCompileTests marlowe-playground
# web-ghc docs sources;
# };
}
27 changes: 27 additions & 0 deletions 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
''
21 changes: 21 additions & 0 deletions 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-shell --run \"nixpkgs-fmt .\"\` and commit the changes"
exit 1
else
echo 0 > $out
fi
''

0 comments on commit debcb33

Please sign in to comment.