diff --git a/.cargo/config.toml b/.cargo/config.toml index 3880865..4be529d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ -[build] -rustflags = ["-C", "link-arg=-fuse-ld=mold", "-C", "link-arg=-Wl,--compress-debug-sections=zlib"] +# [build] +# rustflags = ["-C", "link-arg=-fuse-ld=mold", "-C", "link-arg=-Wl,--compress-debug-sections=zlib"] diff --git a/.config/flakebox/id b/.config/flakebox/id new file mode 100644 index 0000000..877cdc2 --- /dev/null +++ b/.config/flakebox/id @@ -0,0 +1 @@ +aedc7b7ff9bf20dbb75ece15fdb9ff1a72bc1f9c5214b967800561df5d2aa745bc1c357fed49da2caa6d2973930b68a749d6913836284051322fe5352bd236b4 diff --git a/.config/flakebox/shellHook.sh b/.config/flakebox/shellHook.sh new file mode 100644 index 0000000..c69bae2 --- /dev/null +++ b/.config/flakebox/shellHook.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +root="$(git rev-parse --show-toplevel)" +dot_git="$(git rev-parse --git-common-dir)" +if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi +# fix old bug +rm -f "${dot_git}/hooks/comit-msg" +rm -f "${dot_git}/hooks/commit-msg" +ln -sf "${root}/misc/git-hooks/commit-msg" "${dot_git}/hooks/commit-msg" + +root="$(git rev-parse --show-toplevel)" +dot_git="$(git rev-parse --git-common-dir)" +if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi +# fix old bug +rm -f "${dot_git}/hooks/pre-comit" +rm -f "${dot_git}/hooks/pre-commit" +ln -sf "${root}/misc/git-hooks/pre-commit" "${dot_git}/hooks/pre-commit" + +# set template +git config commit.template misc/git-hooks/commit-template.txt + +if [ -n "${DIRENV_IN_ENVRC:-}" ]; then + # and not set DIRENV_LOG_FORMAT + if [ -n "${DIRENV_LOG_FORMAT:-}" ]; then + >&2 echo "💡 Set 'DIRENV_LOG_FORMAT=\"\"' in your shell environment variables for a cleaner output of direnv" + fi +fi + +>&2 echo "💡 Run 'just' for a list of available 'just ...' helper recipes" diff --git a/.config/last-share b/.config/last-share deleted file mode 120000 index afffa9c..0000000 --- a/.config/last-share +++ /dev/null @@ -1 +0,0 @@ -/nix/store/56932h8ybkp5cxbgik091gr6bhkjbzaf-mk-flakebox-share-dir \ No newline at end of file diff --git a/.github/workflows/flakebox-ci.yml b/.github/workflows/flakebox-ci.yml index 71fe901..a9f8c35 100644 --- a/.github/workflows/flakebox-ci.yml +++ b/.github/workflows/flakebox-ci.yml @@ -1,19 +1,30 @@ +# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION + jobs: build: name: Build - runs-on: ubuntu-latest + runs-on: ${{ matrix.runs-on }} steps: - uses: actions/checkout@v4 - name: Install Nix uses: DeterminateSystems/nix-installer-action@v4 - name: Magic Nix Cache uses: DeterminateSystems/magic-nix-cache-action@v2 - - name: Build Flake - run: '# run the same check that git `pre-commit` hook does - - nix flake check .# - - ' + - name: Build on ${{ matrix.host }} + run: nix build .#ci.htmx-sorta + strategy: + matrix: + host: + - macos + - linux + include: + - host: linux + runs-on: ubuntu-latest + timeout: 60 + - host: macos + runs-on: macos-12 + timeout: 60 + timeout-minutes: ${{ matrix.timeout }} flake: name: Flake self-check runs-on: ubuntu-latest @@ -60,3 +71,6 @@ name: CI tags: - v* workflow_dispatch: {} + + +# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION diff --git a/.github/workflows/flakebox-flakehub-publish.yml b/.github/workflows/flakebox-flakehub-publish.yml index 25869e0..5b81f6e 100644 --- a/.github/workflows/flakebox-flakehub-publish.yml +++ b/.github/workflows/flakebox-flakehub-publish.yml @@ -1,13 +1,16 @@ +# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION + jobs: flakehub-publish: + permissions: + contents: read + id-token: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: - ref: '${{ (inputs.tag != null) && format(''refs/tags/{0}'', inputs.tag) || - '''''' }} - - ' + ref: ${{ (inputs.tag != null) && format('refs/tags/{0}', inputs.tag) || '' + }} - name: Install Nix uses: DeterminateSystems/nix-installer-action@v4 - name: Flakehub Push @@ -27,3 +30,6 @@ name: Publish to Flakehub description: The existing tag to publish to FlakeHub required: true type: string + + +# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..b32175c --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,4 @@ +group_imports = "StdExternalCrate" +wrap_comments = true +format_code_in_doc_comments = true +imports_granularity = "Module" diff --git a/Cargo.toml b/Cargo.toml index 9b06d8d..407b0cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,15 +6,6 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[profile.dev] -debug = "line-tables-only" -lto = "off" - -[profile.release] -debug = "line-tables-only" -lto = "fat" -codegen-units = 1 - [dependencies] anyhow = "1.0.75" astra = { git = "https://github.com/dpc/astra", rev = "f135e4c8be0409d371218669bcdb13566f35f116" } @@ -36,3 +27,27 @@ serde_urlencoded = "0.7.1" [dev-dependencies] quickcheck = "1.0.3" quickcheck_macros = "1.0.0" + + + +[profile.dev] +debug = "line-tables-only" +lto = "off" + +[profile.ci] +inherits = "dev" +incremental = false + +[profile.release] +debug = "line-tables-only" +lto = "fat" +codegen-units = 1 + +# Workaround: https://github.com/rust-lang/cargo/issues/12457 which causes +# https://github.com/ipetkov/crane/issues/370 +[profile.dev.build-override] +debug = false +[profile.ci.build-override] +debug = false +[profile.release.build-override] +debug = false diff --git a/flake.lock b/flake.lock index 4cc1ea1..e6d9a64 100644 --- a/flake.lock +++ b/flake.lock @@ -1,9 +1,33 @@ { "nodes": { + "android-nixpkgs": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "flakebox", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1695500413, + "narHash": "sha256-yinrAWIc4XZbWQoXOYkUO0lCNQ5z/vMyl+QCYuIwdPc=", + "owner": "dpc", + "repo": "android-nixpkgs", + "rev": "2e42268a196375ce9b010a10ec5250d2f91a09b4", + "type": "github" + }, + "original": { + "owner": "dpc", + "repo": "android-nixpkgs", + "rev": "2e42268a196375ce9b010a10ec5250d2f91a09b4", + "type": "github" + } + }, "crane": { "inputs": { "flake-compat": "flake-compat", - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils_3", "nixpkgs": [ "flakebox", "nixpkgs" @@ -11,17 +35,40 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1695159108, - "narHash": "sha256-Uaav5HU0aDePH8uPHauUXIabJzeHxVu3em6SQXr40w8=", + "lastModified": 1696222002, + "narHash": "sha256-2xCGgEXOIJsaS6zFUhST/t7kiroMofjViw01w65JEfs=", "owner": "dpc", "repo": "crane", - "rev": "60dcbcab46446bb852473a995fb0008d74c8b78d", + "rev": "bf5f4b71b446e5784900ee9ae0f2569e5250e360", "type": "github" }, "original": { "owner": "dpc", "repo": "crane", - "rev": "60dcbcab46446bb852473a995fb0008d74c8b78d", + "rev": "bf5f4b71b446e5784900ee9ae0f2569e5250e360", + "type": "github" + } + }, + "devshell": { + "inputs": { + "nixpkgs": [ + "flakebox", + "android-nixpkgs", + "nixpkgs" + ], + "systems": "systems_2" + }, + "locked": { + "lastModified": 1695195896, + "narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=", + "owner": "numtide", + "repo": "devshell", + "rev": "05d40d17bf3459606316e3e9ec683b784ff28f16", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", "type": "github" } }, @@ -68,11 +115,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1689068808, - "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -83,7 +130,25 @@ }, "flake-utils_2": { "inputs": { - "systems": "systems_2" + "systems": "systems_3" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_4" }, "locked": { "lastModified": 1681202837, @@ -99,9 +164,9 @@ "type": "github" } }, - "flake-utils_3": { + "flake-utils_4": { "inputs": { - "systems": "systems_3" + "systems": "systems_5" }, "locked": { "lastModified": 1694529238, @@ -119,35 +184,67 @@ }, "flakebox": { "inputs": { + "android-nixpkgs": "android-nixpkgs", "crane": "crane", "fenix": "fenix", - "flake-utils": "flake-utils_3", - "nixpkgs": [ - "nixpkgs" - ] + "flake-utils": "flake-utils_4", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" }, "locked": { - "lastModified": 1695502308, - "narHash": "sha256-vTIVBSA48Gtpjzpk5xEMofOpcZibKb+1XHKURBOOKmM=", + "lastModified": 1696988882, + "narHash": "sha256-jH1R4E8SWZrw7HtzA+7cJwnH4n98yx3527JGd1UD258=", "owner": "rustshop", "repo": "flakebox", - "rev": "36b349dc4e6802a0a26bafa4baef1f39fbf4e870", + "rev": "1e4cce8057d7d68798147ab18cf7ad2ab16506b8", "type": "github" }, "original": { "owner": "rustshop", "repo": "flakebox", - "rev": "36b349dc4e6802a0a26bafa4baef1f39fbf4e870", + "rev": "1e4cce8057d7d68798147ab18cf7ad2ab16506b8", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1695145219, - "narHash": "sha256-Eoe9IHbvmo5wEDeJXKFOpKUwxYJIOxKUesounVccNYk=", + "lastModified": 1696697597, + "narHash": "sha256-q26Qv4DQ+h6IeozF2o1secyQG0jt2VUT3V0K58jr3pg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "5a237aecb57296f67276ac9ab296a41c23981f56", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1696193975, + "narHash": "sha256-mnQjUcYgp9Guu3RNVAB2Srr1TqKcPpRXmJf4LJk6KRY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "fdd898f8f79e8d2f99ed2ab6b3751811ef683242", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1695360818, + "narHash": "sha256-JlkN3R/SSoMTa+CasbxS1gq+GpGxXQlNZRUh9+LIy/0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5ba549eafcf3e33405e5f66decd1a72356632b96", + "rev": "e35dcc04a3853da485a396bdd332217d0ac9054f", "type": "github" }, "original": { @@ -161,7 +258,7 @@ "inputs": { "flake-utils": "flake-utils", "flakebox": "flakebox", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs_2" } }, "rust-analyzer-src": { @@ -252,6 +349,36 @@ "repo": "default", "type": "github" } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_5": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 879abed..1aa05ad 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,11 @@ { - description = "dpc's basic flake template"; + description = "Rust + htmx + tailwind + nix + redb + twind demo web app"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; flakebox = { - url = "github:rustshop/flakebox?rev=36b349dc4e6802a0a26bafa4baef1f39fbf4e870"; - inputs.nixpkgs.follows = "nixpkgs"; + url = "github:rustshop/flakebox?rev=1e4cce8057d7d68798147ab18cf7ad2ab16506b8"; }; }; @@ -15,46 +14,83 @@ let pkgs = import nixpkgs { inherit system; + + overlays = [ + (final: prev: { + # mold wrapper from https://discourse.nixos.org/t/using-mold-as-linker-prevents-libraries-from-being-found/18530/5 + mold-wrapped = + let + bintools-wrapper = "${nixpkgs}/pkgs/build-support/bintools-wrapper"; + in + prev.symlinkJoin { + name = "mold"; + paths = [ prev.mold ]; + nativeBuildInputs = [ prev.makeWrapper ]; + suffixSalt = prev.lib.replaceStrings [ "-" "." ] [ "_" "_" ] prev.targetPlatform.config; + postBuild = '' + for bin in ${prev.mold}/bin/*; do + rm $out/bin/"$(basename "$bin")" + + export prog="$bin" + substituteAll "${bintools-wrapper}/ld-wrapper.sh" $out/bin/"$(basename "$bin")" + chmod +x $out/bin/"$(basename "$bin")" + + mkdir -p $out/nix-support + substituteAll "${bintools-wrapper}/add-flags.sh" $out/nix-support/add-flags.sh + substituteAll "${bintools-wrapper}/add-hardening.sh" $out/nix-support/add-hardening.sh + substituteAll "${bintools-wrapper}/../wrapper-common/utils.bash" $out/nix-support/utils.bash + done + ''; + }; + }) + ]; }; - lib = pkgs.lib; - extLib = import ./nix/lib.nix { inherit lib; }; - - flakeboxLib = flakebox.lib.${system} { }; - craneLib = flakeboxLib.craneLib; - - commonArgs = - let - staticFilesFilter = path: type: if type == "directory" then lib.hasPrefix "/static/" path else lib.hasPrefix "/static/" path; - in - { - src = extLib.cleanSourceWithRel { - src = builtins.path { - name = "htmx-demo"; - path = ./.; - }; - filter = path: type: - (staticFilesFilter path type) - || - (craneLib.filterCargoSources path type) - ; - }; - - installCargoArtifactsMode = "use-zstd"; - - buildInputs = [ ]; - - nativeBuildInputs = builtins.attrValues - { - inherit (pkgs) lld mold; - } ++ [ ]; + projectName = "htmx-sorta"; + + flakeboxLib = flakebox.lib.${system} { + config = { + github.ci.buildOutputs = [ ".#ci.htmx-sorta" ]; }; + }; + + buildPaths = [ + "Cargo.toml" + "Cargo.lock" + ".cargo" + "src" + "static" + ]; + + buildSrc = flakeboxLib.filterSubPaths { + root = builtins.path { + name = projectName; + path = ./.; + }; + paths = buildPaths; + }; + + multiBuild = + (flakeboxLib.craneMultiBuild { }) (craneLib': + let + craneLib = (craneLib'.overrideArgs { + pname = "flexbox-multibuild"; + src = buildSrc; + nativeBuildInputs = [ pkgs.mold-wrapped ]; + }); + in + { + htmx-sorta = craneLib.buildPackage { }; + }); in { - packages.default = craneLib.buildPackage ({ } // commonArgs); + packages.default = multiBuild.htmx-sorta; + + legacyPackages = multiBuild; devShells = { default = flakeboxLib.mkDevShell { - packages = [ pkgs.mold ]; + packages = [ ]; + nativeBuildInputs = [ pkgs.mold-wrapped ]; }; }; } diff --git a/justfile b/justfile index 57a76f7..de8cabe 100644 --- a/justfile +++ b/justfile @@ -1,42 +1,51 @@ +# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION alias b := build alias c := check alias t := test +[private] default: @just --list -# run and restart on changes -watch: - env RUST_LOG=${RUST_LOG:-debug} cargo watch -x run - + # run `cargo build` on everything build: cargo build --workspace --all-targets + # run `cargo check` on everything check: cargo check --workspace --all-targets -# run tests -test: build - cargo test - -# run lints (git pre-commit hook) -lint: - env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit # run all checks recommended before opening a PR -final-check: lint +final-check: lint clippy cargo test --doc just test + # run code formatters format: cargo fmt --all nixpkgs-fmt $(echo **.nix) +# run lints (git pre-commit hook) +lint: + env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit + + +# run tests +test: build + cargo test + + +# run and restart on changes +watch: + env RUST_LOG=${RUST_LOG:-debug} cargo watch -x run + + # run `cargo clippy` on everything clippy: cargo clippy --workspace --all-targets -- --deny warnings --allow deprecated @@ -58,12 +67,14 @@ typos *PARAMS: #!/usr/bin/env bash set -eo pipefail - git_ls_files="$(git ls-files)" - git_ls_nonbinary_files="$(echo "$git_ls_files" | grep -v -E "^db/|\.png\$|\.ods\$")" + export FLAKEBOX_GIT_LS + FLAKEBOX_GIT_LS="$(git ls-files)" + export FLAKEBOX_GIT_LS_TEXT + FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "^db/|\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico)\$")" - if ! echo "$git_ls_nonbinary_files" | typos {{PARAMS}} --stdin-paths; then - >&2 echo "Typos found: Valid new words can be added to '_typos.toml'" + if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos {{PARAMS}} --stdin-paths; then + >&2 echo "Typos found: Valid new words can be added to '.typos.toml'" return 1 fi @@ -71,3 +82,5 @@ typos *PARAMS: [no-exit-message] typos-fix-all: just typos -w + +# THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION diff --git a/misc/git-hooks/commit-msg b/misc/git-hooks/commit-msg index fef6082..b4fe09a 100755 --- a/misc/git-hooks/commit-msg +++ b/misc/git-hooks/commit-msg @@ -1,4 +1,4 @@ -#!/nix/store/vqvj60h076bhqj6977caz0pfxs6543nb-bash-5.2-p15/bin/bash +#!/usr/bin/env bash # Sanitize file first, by removing leading lines that are empty or start with a hash, # as `convco` currently does not do it automatically (but git will) # TODO: next release of convco should be able to do it automatically @@ -21,4 +21,3 @@ if ! convco check --from-stdin <<<"$MESSAGE" ; then >&2 echo "Use git recommit to fix your commit" exit 1 fi - diff --git a/misc/git-hooks/commit-template.txt b/misc/git-hooks/commit-template.txt index 55960b8..a9aff55 100644 --- a/misc/git-hooks/commit-template.txt +++ b/misc/git-hooks/commit-template.txt @@ -1,3 +1,2 @@ # Explain *why* this change is being made width limit ->| - diff --git a/misc/git-hooks/pre-commit b/misc/git-hooks/pre-commit index 6781a07..f7438b3 100755 --- a/misc/git-hooks/pre-commit +++ b/misc/git-hooks/pre-commit @@ -1,15 +1,6 @@ -#!/nix/store/vqvj60h076bhqj6977caz0pfxs6543nb-bash-5.2-p15/bin/bash #!/usr/bin/env bash -set -eo pipefail - -# https://stackoverflow.com/a/72183258/134409 -# this hangs in CI (no tty?) -# yes 'will cite' | parallel --citation 2>/dev/null 1>/dev/null || true -if [ -n "${HOME:-}" ] && [ -d "$HOME" ]; then - mkdir -p "$HOME/.parallel" - touch "$HOME/.parallel/will-cite" -fi +set -euo pipefail set +e git diff-files --quiet @@ -29,14 +20,16 @@ if [ -z "${NO_STASH:-}" ] && [ $is_unclean -ne 0 ]; then trap revert_git_stash EXIT fi -export git_ls_files -git_ls_files="$(git ls-files)" -export git_ls_nonbinary_files -git_ls_nonbinary_files="$(echo "$git_ls_files" | xargs file --mime | grep -v "; charset=binary" | cut -d: -f1)" +export FLAKEBOX_GIT_LS +FLAKEBOX_GIT_LS="$(git ls-files)" +export FLAKEBOX_GIT_LS_TEXT +FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$")" -export git_ls_nonbinary_files -git_ls_nonbinary_files="$(echo "$git_ls_files" | xargs file --mime | grep -v "; charset=binary" | cut -d: -f1)" +function check_nothing() { + true +} +export -f check_nothing function check_cargo_fmt() { set -euo pipefail @@ -55,20 +48,12 @@ function check_cargo_lock() { } export -f check_cargo_lock -function check_clippy() { - set -euo pipefail - - cargo clippy --workspace --all-targets -- --deny warnings --allow deprecated - -} -export -f check_clippy - function check_leftover_dbg() { set -euo pipefail errors="" - for path in $(echo "$git_ls_nonbinary_files" | grep '.*\.rs'); do - if grep 'dbg!(' "$path" > /dev/null; then + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do + if grep 'dbg!(' "$path" > /dev/null; then >&2 echo "$path contains dbg! macro" errors="true" fi @@ -110,18 +95,56 @@ export -f check_semgrep function check_shellcheck() { set -euo pipefail - for path in $(echo "$git_ls_nonbinary_files" | grep -E '.*\.sh$') ; do + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do shellcheck --severity=warning "$path" done } export -f check_shellcheck +function check_trailing_newline() { + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do + + # extra branches for clarity + if [ ! -s "$path" ]; then + # echo "$path is empty" + true + elif [ -z "$(tail -c 1 < "$path")" ]; then + # echo "$path ends with a newline or with a null byte" + true + else + >&2 echo "$path doesn't end with a newline" 1>&2 + errors="true" + fi + done + + if [ -n "$errors" ]; then + >&2 echo "Fix the problems above or use --no-verify" 1>&2 + return 1 + fi + +} +export -f check_trailing_newline + +function check_trailing_whitespace() { + set -euo pipefail + + if ! git diff --check HEAD ; then + echo "Trailing whitespace detected. Please remove them before committing." + return 1 + fi + +} +export -f check_trailing_whitespace + function check_typos() { set -euo pipefail - if ! echo "$git_ls_nonbinary_files" | typos --stdin-paths ; then - >&2 echo "Typos found: Valid new words can be added to '_typos.toml'" + if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --stdin-paths ; then + >&2 echo "Typos found: Valid new words can be added to '.typos.toml'" return 1 fi @@ -129,13 +152,14 @@ function check_typos() { export -f check_typos parallel \ + --nonotice \ ::: \ check_cargo_fmt \ check_cargo_lock \ - check_clippy \ check_leftover_dbg \ check_semgrep \ check_shellcheck \ + check_trailing_newline \ + check_trailing_whitespace \ check_typos \ - # newline for the last \ to work - + check_nothing