···88# Create a tmp directory and cd into it
99tmpdir() {
1010 mkdir -p "$CACHE_DIR"
1111- local dir=$(mktemp --directory --tmpdir="$CACHE_DIR")
1111+ local dir
1212+ dir=$(mktemp --directory --tmpdir="$CACHE_DIR")
1213 cd "$dir"
1314}
1415···3031 local file2="$2"
3132 # Use $3 as the max difference or 100 bytes
3233 local max_diff=${3:-100}
3333- local size1=$(stat -c %s "$file1")
3434- local size2=$(stat -c %s "$file2")
3535- if [ $((size1 - size2)) -gt $max_diff ]; then
3434+ local size1
3535+ local size2
3636+ size1=$(stat -c %s "$file1")
3737+ size2=$(stat -c %s "$file2")
3838+ if [ $((size1 - size2)) -gt "$max_diff" ]; then
3639 echo "Size difference too large: $file1:$size1 $file2:$size2"
3740 exit 1
3841 fi
···6770 echo "Creating random data"
6871 random_file 1000000 file
6972 echo "Compressing with gzip and cmprss"
7070- gzip -$1 -c file >gzip_file.gz
7171- cmprss gzip --level $1 file cmprss_file.gz --progress=off
7373+ gzip -"$1" -c file >gzip_file.gz
7474+ cmprss gzip --level "$1" file cmprss_file.gz --progress=off
7275 # Compare the two archives
7376 # The archives may have slight variations (versioning or whatever) so we
7477 # only compare the sizes to make sure they are similar
···100103 echo "Creating random data"
101104 random_file 1000000 file
102105 echo "Compressing with xz and cmprss"
103103- xz -$1 --stdout file >xz_file.xz
104104- cmprss xz --level $1 file cmprss_file.xz --progress=off
106106+ xz -"$1" --stdout file >xz_file.xz
107107+ cmprss xz --level "$1" file cmprss_file.xz --progress=off
105108 # Compare the two archives
106109 # The archives may have slight variations (versioning or whatever) so we
107110 # only compare the sizes to make sure they are similar
···134137 echo "Creating random data"
135138 random_file 1000000 file
136139 echo "Compressing with bzip2 and cmprss"
137137- bzip2 -$1 --stdout file >bzip2_file.bz2
138138- cmprss bzip2 --level $1 file cmprss_file.bz2 --progress=off
140140+ bzip2 -"$1" --stdout file >bzip2_file.bz2
141141+ cmprss bzip2 --level "$1" file cmprss_file.bz2 --progress=off
139142 # Compare the two archives
140143 # The archives may have slight variations (versioning or whatever) so we
141144 # only compare the sizes to make sure they are similar
···167170 echo "Creating random data"
168171 random_file 1000000 file
169172 echo "Compressing with zstd and cmprss"
170170- zstd -$1 -c file >zstd_file.zst
171171- cmprss zstd --level $1 file cmprss_file.zst --progress=off
173173+ zstd -"$1" -c file >zstd_file.zst
174174+ cmprss zstd --level "$1" file cmprss_file.zst --progress=off
172175 # Compare the two archives
173176 # The archives may have slight variations (versioning or whatever) so we
174177 # only compare the sizes to make sure they are similar
+67-7
flake.nix
···8383 doCheck = false; # Tests are run as a separate build with nextest
8484 meta.mainProgram = "cmprss";
8585 });
8686+ # Source filtered to specific file extensions for lightweight linter checks
8787+ cleanSrc = pkgs.lib.cleanSource ./.;
8888+ sourceWithExts = exts:
8989+ pkgs.lib.cleanSourceWith {
9090+ src = cleanSrc;
9191+ filter = path: type:
9292+ (type == "directory")
9393+ || (pkgs.lib.any (ext: pkgs.lib.hasSuffix ".${ext}" path) exts);
9494+ };
9595+9696+ mkSimpleLinter = {
9797+ name,
9898+ packages ? [],
9999+ src ? cleanSrc,
100100+ command,
101101+ }:
102102+ pkgs.runCommand "lint-${name}" {
103103+ nativeBuildInputs = packages;
104104+ inherit src;
105105+ } ''
106106+ cd $src
107107+ ${command}
108108+ mkdir -p $out
109109+ '';
110110+111111+ linters = {
112112+ statix = mkSimpleLinter {
113113+ name = "statix";
114114+ packages = [pkgs.statix];
115115+ src = sourceWithExts ["nix"];
116116+ command = "statix check .";
117117+ };
118118+ deadnix = mkSimpleLinter {
119119+ name = "deadnix";
120120+ packages = [pkgs.deadnix];
121121+ src = sourceWithExts ["nix"];
122122+ command = "deadnix --fail .";
123123+ };
124124+ shellcheck = mkSimpleLinter {
125125+ name = "shellcheck";
126126+ packages = [pkgs.shellcheck pkgs.findutils];
127127+ src = sourceWithExts ["sh"];
128128+ command = ''find . -name "*.sh" -type f -exec shellcheck {} +'';
129129+ };
130130+ actionlint = mkSimpleLinter {
131131+ name = "actionlint";
132132+ packages = [pkgs.actionlint pkgs.shellcheck pkgs.findutils];
133133+ src = pkgs.lib.cleanSourceWith {
134134+ src = cleanSrc;
135135+ filter = path: type:
136136+ (type == "directory")
137137+ || (pkgs.lib.hasSuffix ".yml" path && pkgs.lib.hasInfix ".github" path);
138138+ };
139139+ command = ''find .github/workflows -name "*.yml" -exec actionlint {} +'';
140140+ };
141141+ };
86142 in {
87143 packages = {
88144 default = cmprss;
8989- cmprss = cmprss;
145145+ inherit cmprss;
9014691147 # Check code coverage with tarpaulin
92148 coverage = craneLib.cargoTarpaulin (commonArgs
···118174 });
119175 };
120176121121- checks = {
122122- inherit cmprss;
123123- # Build almost every package in checks, with exceptions:
124124- # - coverage: It requires a full rebuild, and only needs to be run occasionally
125125- inherit (self.packages.${system}) clippy doc fmt test deny;
126126- };
177177+ checks =
178178+ {
179179+ inherit cmprss;
180180+ # Build almost every package in checks, with exceptions:
181181+ # - coverage: It requires a full rebuild, and only needs to be run occasionally
182182+ inherit (self.packages.${system}) clippy doc fmt test deny;
183183+ }
184184+ // linters;
127185128186 # This also sets up `nix fmt` to run all formatters
129187 treefmt = {
···167225 packages = with pkgs; [
168226 act # For running Github Actions locally
169227 alejandra
228228+ actionlint
170229 deadnix
171230 git-cliff
172231 go-task
173232 gum # Pretty printing in scripts
174233 nodePackages.prettier
234234+ shellcheck
175235 statix
176236177237 # For running tests