Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and Improve Tests #20

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ jobs:
- name: "Checkout Codebase"
uses: "actions/checkout@v4"

- name: "Install nix"
uses: "cachix/install-nix-action@v27"
with:
nix_path: "nixpkgs=channel:nixos-24.05"
- name: "Install Nix"
uses: "DeterminateSystems/nix-installer-action@v16"

- name: "Use Magic Nix cache"
uses: "DeterminateSystems/magic-nix-cache-action@v7"
- name: "Use Nix Cache"
uses: "DeterminateSystems/magic-nix-cache-action@v8"

- name: "Check, Test and Build"
run: |
nix-shell --pure --run "cabal update --ignore-project && dev-test-build"
nix-shell --pure --run "cabal update --ignore-project && cabal dev-test-build"
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,22 @@ hpack &&
cabal haddock -O0
```

To test and build codebase in development environment, run:
To run checks, tests and build the codebase in the development environment, run:

```sh
dev-test-build
cabal-dev-test-build
```

You can pass `-c` to clean the build artifacts first:

```sh
cabal-dev-test-build -c
```

As of Cabal 3.12, you can now run the above as an external `cabal` command:

```sh
cabal dev-test-build [-c]
```

<!-- REFERENCES -->
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let

## Prepare dev-test-build script:
dev-test-build = pkgs.writeShellApplication {
name = "dev-test-build";
name = "cabal-dev-test-build";
text = builtins.readFile ./nix/dev-test-build.sh;
runtimeInputs = [ pkgs.bash pkgs.bc pkgs.moreutils ];
};
Expand Down
36 changes: 27 additions & 9 deletions nix/dev-test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ fi

_clean=""

## Check if we are an cabal external command:
CABAL="${CABAL:-}"
if [ -n "${CABAL}" ]; then
_cabal="${CABAL}"
shift
else
_cabal="$(command -v cabal)"
fi

## Parse options:
while getopts ":c" opt; do
case ${opt} in
c)
Expand Down Expand Up @@ -80,7 +90,7 @@ _print_success() {
_clean() {
_print_header "clean"
_start=$(_get_now)
chronic -- cabal clean && chronic -- cabal v1-clean
chronic -- "${_cabal}" clean && chronic -- "${_cabal}" v1-clean
_print_success "${_start}" "$(_get_now)"
}

Expand Down Expand Up @@ -120,23 +130,23 @@ _hlint() {
}

_cabal_build() {
_print_header "cabal build (v$(cabal --numeric-version))"
_print_header "cabal build (v$("${_cabal}" --numeric-version))"
_start=$(_get_now)
chronic -- cabal build -O0
chronic -- "${_cabal}" build -O0
_print_success "${_start}" "$(_get_now)"
}

_cabal_run() {
_print_header "cabal run (v$(cabal --numeric-version))"
_print_header "cabal run (v$("${_cabal}" --numeric-version))"
_start=$(_get_now)
chronic -- cabal run -O0 haskell-template-hebele -- --version
chronic -- "${_cabal}" run -O0 haskell-template-hebele -- --version
_print_success "${_start}" "$(_get_now)"
}

_cabal_test() {
_print_header "cabal test (v$(cabal --numeric-version))"
_print_header "cabal test (v$("${_cabal}" --numeric-version))"
_start=$(_get_now)
chronic -- cabal v1-test
chronic -- "${_cabal}" v1-test
_print_success "${_start}" "$(_get_now)"
}

Expand All @@ -147,10 +157,17 @@ _weeder() {
_print_success "${_start}" "$(_get_now)"
}

_stan() {
_print_header "stan ($(stan --version | head -n 1 | cut -f 2 -d " "))"
_start=$(_get_now)
chronic -- stan --hiedir ./dist-newstyle
_print_success "${_start}" "$(_get_now)"
}

_cabal_haddock() {
_print_header "cabal haddock (v$(cabal --numeric-version))"
_print_header "cabal haddock (v$("${_cabal}" --numeric-version))"
_start=$(_get_now)
chronic -- cabal haddock -O0 \
chronic -- "${_cabal}" haddock -O0 \
--haddock-quickjump \
--haddock-hyperlink-source \
--haddock-html-location="https://hackage.haskell.org/package/\$pkg-\$version/docs"
Expand All @@ -169,6 +186,7 @@ _hlint
_cabal_build
_cabal_run
_cabal_test
_stan
_weeder
_cabal_haddock
printf "Finished all in %ss\n" "$(_get_diff "${_scr_start}" "$(_get_now)")"
Loading