git.iko.soy/typeable/compaREST
on master help sign in
181 lines 6.1 kB history raw
1{ sources ? import ./nix/sources.nix
2, gomod2nix ? sources.gomod2nix
3, haskellNix ? (import ../. {}).haskellNix
4, pkgs ? import haskellNix.sources.nixpkgs-2105 (haskellNix.nixpkgsArgs // {
5 overlays = haskellNix.nixpkgsArgs.overlays ++ [
6 (self: super: {
7 buildGoApplication = super.callPackage (gomod2nix + "/builder") { };
8 })
9 ];
10 })
11, compaRESThsPkgs ? (import ../. {}).hsPkgs
12, npmNix ? import (sources.npmNix + "/npmPackages") { inherit pkgs; }
13, mavenix ? import (sources.mavenix) { inherit pkgs; }
14, bumpToken ? null
15, bumpDocumentation ? null
16}:
17let
18 typeable-comparest = compaRESThsPkgs.comparest.components.exes.comparest;
19 typeable-comparest-exe = typeable-comparest + "/bin/comparest";
20 typeable-comparest-differ = pkgs.writeScript "typeable-comparest-differ" ''
21 #!${pkgs.stdenv.shell}
22 set +e
23 ${typeable-comparest-exe} -c $1 -s $2 -o $3/typeable.md
24 exit 0
25 '';
27 atlassian-openapi-diff = pkgs.mkYarnPackage {
28 name = "openapi-diff";
29 src = sources.atlassian-openapi-diff;
30 yarnLock = ./atlassian/yarn.lock;
31 patches = [ ./atlassian/addDist.patch ];
32 postBuild = "yarn run gulp compileDist";
33 };
34 atlassian-openapi-diff-exe = atlassian-openapi-diff + "/bin/openapi-diff";
35 atlassian-openapi-diff-differ = pkgs.writeScript "atlassian-openapi-diff-differ" ''
36 #!${pkgs.stdenv.shell}
37 set +e
38 ${atlassian-openapi-diff-exe} $1 $2 >$3/atlassian.json 2>$3/atlassian.error.txt
39 if [ ! -s $3/atlassian.error.txt ]; then
40 rm $3/atlassian.error.txt
41 fi
42 exit 0
43 '';
45 openapitools-openapi-diff = mavenix.buildMaven {
46 maven = pkgs.maven;
47 src = sources.openapitools-openapi-diff;
48 doCheck = false;
49 infoFile = ./openapitools/mavenix.lock;
50 MAVEN_OPTS = "-Dgithook.plugin.skip=true";
51 };
52 openapitools-openapi-diff-exe =
53 pkgs.runCommand "openapitools-openapi-diff"
54 { buildInputs = [ pkgs.makeWrapper ]; }
55 ''makeWrapper ${pkgs.jdk}/bin/java $out --add-flags "-jar ${openapitools-openapi-diff}/share/java/openapi-diff-cli-2.0.0-SNAPSHOT-all.jar"'';
56 openapitools-openapi-diff-differ = pkgs.writeScript "openapitools-openapi-diff-differ" ''
57 #!${pkgs.stdenv.shell}
58 set +e
59 ${openapitools-openapi-diff-exe} $1 $2 --off --markdown $3/openapitools.md 2>$3/openapitools.error.txt
60 if [ ! -s $3/openapitools.error.txt ]; then
61 rm $3/openapitools.error.txt
62 fi
63 exit 0
64 '';
66 oasdiff = pkgs.pkgs.buildGoApplication {
67 pname = "oasdiff";
68 version = "0.1";
69 src = sources.oasdiff;
70 modules = ./oasdiff/gomod2nix.toml;
71 };
72 oasdiff-differ = pkgs.writeScript "oasdiff-differ" ''
73 #!${pkgs.stdenv.shell}
74 set +e
75 ${oasdiff}/bin/oasdiff -base $1 -revision $2 -format text >$3/oasdiff.txt 2>$3/oasdiff.error.txt
76 if [ ! -s $3/oasdiff.error.txt ]; then
77 rm $3/oasdiff.error.txt
78 fi
79 exit 0
80 '';
82 bump-differ = { bumpToken, bumpDocumentation }: pkgs.writeScript "bump-differ" ''
83 #!${pkgs.stdenv.shell}
85 ${pkgs.httpie}/bin/https --ignore-stdin POST bump.sh/api/v1/versions definition=@$1 documentation=${bumpDocumentation} -a ${bumpToken}: >/dev/null
86 id=$(${pkgs.httpie}/bin/https --ignore-stdin POST bump.sh/api/v1/versions definition=@$2 documentation=${bumpDocumentation} -a ${bumpToken}: | ${pkgs.jq}/bin/jq -r .id)
88 if [ -z "$id" ]
89 then
90 echo "Not changed" > $3/bump.txt
91 else
92 state=""
94 while [ "$state" != "deployed" ]
95 do
96 state=$(${pkgs.httpie}/bin/https --ignore-stdin GET bump.sh/api/v1/versions/$id -a ${bumpToken}: | ${pkgs.jq}/bin/jq -r .state)
97 done
99 ${pkgs.httpie}/bin/https --ignore-stdin GET bump.sh/api/v1/versions/$id -a ${bumpToken}: | ${pkgs.jq}/bin/jq -r .diff_summary > $3/bump.txt
100 fi
101 '';
103 getInputs = with pkgs;
104 dir: lib.flatten (lib.mapAttrsToList
105 (name: type:
106 if type == "directory" then
107 let
108 path = dir + "/${name}";
109 contents = builtins.readDir path;
110 in
111 if contents."a.yaml" or null == "regular" && contents."b.yaml" or null == "regular"
112 then path
113 else getInputs path
114 else [ ]
115 )
116 (builtins.readDir dir)
117 );
119 runBenchmark = root: pkgs.runCommand "openapi-diff-benchmarks"
120 {
121 dirs = map
122 (path: builtins.toJSON {
123 relativePath = pkgs.lib.removePrefix (builtins.toString root) (builtins.toString path);
124 a = path + "/a.yaml";
125 b = path + "/b.yaml";
126 })
127 (getInputs root);
128 differs = [
129 typeable-comparest-differ
130 atlassian-openapi-diff-differ
131 openapitools-openapi-diff-differ
132 oasdiff-differ
133 ] ++ (
134 if bumpToken == null || bumpDocumentation == null
135 then builtins.trace "Warning: bumpToken or bumpDocumentation not provided. Skipping bump.sh benchmarks." [ ]
136 else [ (bump-differ { inherit bumpToken bumpDocumentation; }) ]
137 );
138 }
139 ''
140 echo "Running compatibility checks:"
141 for dir in $dirs
142 do
143 a=$(echo $dir | ${pkgs.jq}/bin/jq -r .a)
144 b=$(echo $dir | ${pkgs.jq}/bin/jq -r .b)
145 relativePath=$(echo $dir | ${pkgs.jq}/bin/jq -r .relativePath)
146 echo "''\t$relativePath"
147 output=$out$relativePath
148 mkdir -p $output
149 for differ in $differs
150 do
151 $differ $a $b $output
152 done
153 cp $a $output/a.yaml
154 cp $b $output/b.yaml
155 done
156 '';
158 benchmarkReportTemplate = root:
159 let
160 tools = [
161 "Typeable"
162 "Atlassian"
163 "OpenAPI Tools"
164 "oasdiff"
165 "Bump.sh"
166 ];
167 foo = with pkgs.lib.strings;
168 concatMapStrings (x: "| " + x) ([ "" ] ++ tools) + "| \n" + concatMapStrings (_: "|---") ([ "" ] ++ tools) + "| \n" +
169 concatMapStrings
170 (path:
171 let
172 relativePath = pkgs.lib.removePrefix (builtins.toString root + "/") (builtins.toString path);
174 in
175 "[${relativePath}](./${relativePath})${concatMapStrings (_: " | ✅❌") tools} \n")
176 (getInputs root);
177 in
178 foo;
180in
181runBenchmark ../test/golden/common