diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8f040bf..1d578c5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,46 +8,22 @@ on: pull_request: branches: [main] -# Run CI on all 3 latest OSes jobs: - build: + check: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - uses: purescript-contrib/setup-purescript@main - with: - purescript: "0.15.9" - purs-tidy: "0.10.0" - psa: "0.8.2" - spago: "unstable" - - - name: Cache PureScript dependencies - uses: actions/cache@v2 - with: - key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} - path: | - .spago - output + - uses: actions/checkout@v3 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Set up Node toolchain - uses: actions/setup-node@v2 - with: - node-version: "18" + - name: "Nix check" + run: nix flake check - # Compile the library/project - # censor-lib: ignore warnings emitted by dependencies - # strict: convert warnings into errors - # Note: `purs-args` actually forwards these args to `psa` - - name: Build the project + - name: "Run tests" run: | - spago build --purs-args "--censor-lib --strict" + nix develop --command 'run-install' + nix develop --command 'run-test' - - name: Run tests - run: | - spago -x test.dhall test + - name: "Check format" + run: nix develop --command 'run-check-format' - - name: Check Formatting - run: | - purs-tidy check src test diff --git a/flake.nix b/flake.nix index e5f8648..acfb7ff 100644 --- a/flake.nix +++ b/flake.nix @@ -6,20 +6,59 @@ purescript-overlay.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, flake-utils, purescript-overlay }: - flake-utils.lib.eachDefaultSystem (system: - let - overlays = [ purescript-overlay.overlays.default ]; - pkgs = import nixpkgs { inherit system overlays; }; - in { - devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - purs - purs-tidy - purs-backend-es - nodejs - spago-unstable - ]; + outputs = { + self, + nixpkgs, + flake-utils, + purescript-overlay, + }: + flake-utils.lib.eachDefaultSystem (system: let + overlays = [purescript-overlay.overlays.default]; + pkgs = import nixpkgs {inherit system overlays;}; + scripts = pkgs.symlinkJoin { + name = "scripts"; + paths = pkgs.lib.mapAttrsToList pkgs.writeShellScriptBin { + run-install = '' + spago install + ''; + + run-test = '' + spago test + ''; + + run-check-format = '' + purs-tidy check src test + ''; }; - }); + }; + in { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + scripts + + # PureScript tools + purs + purs-tidy + purs-backend-es + spago-unstable + # Node + nodejs + # Nix + alejandra + ]; + }; + + checks = { + format = + pkgs.runCommand "check-format" + { + buildInputs = with pkgs; [ + alejandra + ]; + } '' + ${pkgs.alejandra}/bin/alejandra --check ${./.} + touch $out + ''; + }; + }); }