-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1128748
commit 6183084
Showing
8 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
{ sources ? import ./sources.nix | ||
, pkgs ? import sources.nixpkgs { } | ||
}: | ||
|
||
let | ||
yq = import ./yq.nix { inherit pkgs; }; | ||
diff-yaml = import ./diff-yaml.nix { inherit pkgs; }; | ||
in | ||
pkgs.mkShell { | ||
packages = [ pkgs.haskellPackages.fourmolu ]; | ||
packages = [ pkgs.haskellPackages.fourmolu diff-yaml yq ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
let | ||
inherit (pkgs) stdenv; | ||
yq = import ./yq.nix { inherit pkgs; }; | ||
in | ||
stdenv.mkDerivation { | ||
name = "diff-yaml"; | ||
|
||
src = ../scripts/diff-yaml; | ||
|
||
buildInputs = [ pkgs.bash yq ]; | ||
|
||
phases = [ "installPhase" ]; | ||
|
||
installPhase = '' | ||
mkdir -p $out/bin | ||
cp $src $out/bin/diff-yaml | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Normalise YAML files passed as inputs, then run diff on them. | ||
|
||
check_util() { | ||
local util=$1 | ||
|
||
if [ -z $util ]; then | ||
echo "Error: $util not found in PATH" | ||
exit 1 | ||
fi | ||
} | ||
|
||
DIFF=`which diff` | ||
check_util $DIFF | ||
|
||
YQ=`which yq` | ||
check_util $YQ | ||
|
||
# Only normalise YAML files. | ||
# Print anything else as is. | ||
normalise() { | ||
local file=$1 | ||
local contents=($YQ -y -S '.' $file) | ||
|
||
# if $contents contains actual YAML data, print it | ||
if [[ $? == 0 ]]; then | ||
echo $contents | ||
else | ||
cat $file | ||
fi | ||
} | ||
|
||
$DIFF -u <(normalise $1) <(normalise $2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters