From 5029aab415393072091ff126b38d0c90f55081c6 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 1 Mar 2024 20:38:29 +0000 Subject: [PATCH] Add just and justfile --- .github/workflows/ci.yml | 5 ++- flake.nix | 1 + run => justfile | 66 ++++++++++++---------------------------- 3 files changed, 23 insertions(+), 49 deletions(-) rename run => justfile (63%) mode change 100755 => 100644 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36da515..a803e1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,8 @@ jobs: with: nix_path: nixpkgs=channel:nixos-23.05 - - run: ./run ci:test - - - run: ./run build + - run: nix develop --command just ci-test + - run: nix develop --command just build - run: | echo "DATE=$(date '+%Y-%m-%d-%H.%M.%S')" >> $GITHUB_ENV diff --git a/flake.nix b/flake.nix index a149852..218effd 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,7 @@ perSystem = { config, self', inputs', pkgs, system, ... }: { devshells.default = { packages = with pkgs; [ + "just" "php81" "php81Packages.composer" ]; diff --git a/run b/justfile old mode 100755 new mode 100644 similarity index 63% rename from run rename to justfile index 62a85c1..5474f99 --- a/run +++ b/justfile @@ -1,29 +1,18 @@ -#!/usr/bin/env bash +_default: + just --list -set -o errexit -set -o pipefail - -export PATH=$PATH:./bin:./vendor/bin:./vendor-bin/box/vendor/bin - -# Delete any temporary or generated files. -function clean { - rm -fr dist/* tmp vendor vendor-bin/box/vendor - touch dist/.keep var/.keep -} - -# Build the phar version of build-configs. -function build { - clean +build: + just clean # Install dependencies. composer validate composer install --no-dev --prefer-dist --optimize-autoloader composer install --prefer-dist --optimize-autoloader --working-dir ./vendor-bin/box - nix develop --command composer dump-env prod + composer dump-env prod - nix develop --command build-configs cache:clear - nix develop --command build-configs cache:warmup + ./build-configs cache:clear + ./build-configs cache:warmup # Generate the phar file. box compile --config box.json.dist @@ -33,36 +22,26 @@ function build { tree dist/ # TODO: build a Nix derivation and add it to the store. -} -function ci:test { +clean: + rm -fr dist/* tmp vendor vendor-bin/box/vendor + touch dist/.keep var/.keep + +ci-test: nix develop --command composer install nix develop --command ./run test:snapshots nix develop --command phpunit --testdox -} -# Display a list of all available commands. -function help { - printf "%s [args]\n\nTasks:\n" "${0}" +test *args: + phpunit {{ args }} - compgen -A function | grep -v "^_" | cat -n - - printf "\nExtended help:\n Each task has comments for general usage\n" -} - -function test { - phpunit "${@}" -} - -# Create a new snapshot for a configuration based on generated files. -function test:create-snapshot { +create-snapshot config: + #!/usr/bin/env bash set -o nounset - config="${1}" + config_file="tests/snapshots/configs/{{ config }}.yaml" + output_path="tests/snapshots/output/{{ config }}" - config_file="tests/snapshots/configs/${config}.yaml" - output_path="tests/snapshots/output/${config}" - cat "${config_file}" rm -fr "${output_path}" @@ -70,10 +49,9 @@ function test:create-snapshot { ./bin/build-configs app:generate --config-file "${config_file}" --output-dir "${output_path}" git status "${output_path}" -} -# Generate a file and ensure it matches the expected version. -function test:snapshots { +run-snapshots: + #!/usr/bin/env bash rm -rf .ignored/snapshots mkdir -p .ignored/snapshots @@ -107,7 +85,3 @@ function test:snapshots { fi done done -} - -TIMEFORMAT=$'\nTask completed in %3lR' -time "${@:-help}"