-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-tests.clj
151 lines (136 loc) · 5.43 KB
/
generate-tests.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;; /usr/bin/env sh
;;
;; Benchmarks are generated from two lists of clients + registries
;; So having the lists ["npm" "yarn"] and ["npm-reg" "yarn-reg"] should generate
;; one list of ["npm--npm-reg"]
;; (def projects [
;; "freeCodeCamp/freeCodeCamp#35cfffebd5db40837e285a8731eadc1a2d99f7c1"
;; "vuejs/vue"
;; "twbs/bootstrap"
;; "facebook/react"
;; "getify/You-Dont-Know-JS"
;; "airbnb/javascript"
;; "electron/electron"
;; "nodejs/node"
;; "axios/axios"
;; "mrdoob/three.js"
;; "justjavac/free-programming-books-zh_CN"
;; "atom/atom"
;; "webpack/webpack"
;; "trekhleb/javascript-algorithms"
;; "Microsoft/TypeScript"
;; "angular/angular"
;; "mui-org/material-ui"
;; "expressjs/express"
;; "30-seconds/30-seconds-of-code"
;; "chartjs/Chart.js"
;; "h5bp/html5-boilerplate"
;; "meteor/meteor"
;; "lodash/lodash"
;; "ionic-team/ionic"
;; "ElemeFE/element"
;; "storybooks/storybook"
;; "Dogfalo/materialize"
;; "yarnpkg/yarn"
;; "nwjs/nw.js"
;; "thedaviddias/Front-End-Checklist"
;; ])
;; (def packages ["lodash"
;; "request"
;; "chalk"
;; "react"
;; "express"
;; "commander"
;; "moment"
;; "debug"
;; "async"
;; "bluebird"
;; "prop-types"
;; "react-dom"])
(def clients {:yarn "1.15.2"
:npm "6.9.0"
:pnpm "3.1.0"
})
(def registries {;; https://yarnpkg.com/
:yarn "https://registry.yarnpkg.com"
;; https://www.npmjs.com/
:npm "https://registry.npmjs.org"
;; https://github.com/ipfs-shipyard/npm-on-ipfs
:ipfs "https://registry.js.ipfs.io"
;; http://node-modules.io/
;; TODO seems registry.node-modules.io no longer works
;; :node-modules "https://registry.node-modules.io"
;; https://cnpmjs.org/
:cnpmjs "https://r.cnpmjs.org"
;; https://github.com/open-services/open-registry
:open-registry "https://npm.open-registry.dev"
;; https://github.com/open-services/bolivar
:bolivar "http://localhost:8080"})
;; :github "https://npm.pkg.github.com"
;; Bolivar-specifics
(def bolivar-dist "https://github.com/open-services/bolivar/releases/download/0.1.0/bolivar-0.1.0-linux-amd64")
(def fetch-bolivar (str "RUN wget " bolivar-dist))
(def make-bolivar+x "RUN chmod +x bolivar-0.1.0-linux-amd64")
(def move-bolivar "RUN mv bolivar-0.1.0-linux-amd64 /usr/local/bin/bolivar")
(def start-and-wait "until tail -f bolivar.log | grep -m 1 \"Starting server\"; do : ; done")
(def run-bolivar+client-install
(format "bash -c 'bolivar > bolivar.log & %s && $client install --verbose'" start-and-wait))
;; Here you can add any specific steps a registry needs
(def special-build-steps {:bolivar [fetch-bolivar
make-bolivar+x
move-bolivar]})
;; Here you can define a separate command for running the test. It should,
;; as a last action, install all dependences for the project in WORKDIR
(def run-cmds {:bolivar run-bolivar+client-install})
(def default-run-cmd "$client install --verbose")
(defn get-run-cmd [registry]
(let [run-cmd (registry run-cmds)]
(if (nil? run-cmd)
default-run-cmd
run-cmd)))
(defn dockerfile-template [extra-steps cmd]
(clojure.string/join "\n"
(vec (concat ["FROM benchmarks-base"
"RUN npm install -g $client@$version"]
extra-steps
["RUN $client config set registry $registry"
(str "CMD " cmd)]))))
(defn cartesian-product
"All the ways to take one item from each sequence"
[& seqs]
(let [v-original-seqs (vec seqs)
step
(fn step [v-seqs]
(let [increment
(fn [v-seqs]
(loop [i (dec (count v-seqs)), v-seqs v-seqs]
(if (= i -1) nil
(if-let [rst (next (v-seqs i))]
(assoc v-seqs i rst)
(recur (dec i) (assoc v-seqs i (v-original-seqs i)))))))]
(when v-seqs
(cons (map first v-seqs)
(lazy-seq (step (increment v-seqs)))))))]
(when (every? seq seqs)
(lazy-seq (step v-original-seqs)))))
(def versions (cartesian-product (keys clients) (keys registries)))
(defn new-dockerfile [template client version registry]
(-> template
(clojure.string/replace "$client" client)
(clojure.string/replace "$version" version)
(clojure.string/replace "$registry" registry)))
(println "Different versions:")
(println versions)
(doseq [[client registry] versions]
(println (format "### Generating for test = Client: %s Registry %s" client registry))
(let [client-version (client clients)
registry-url (registry registries)
image-name (format "%s--%s" (name registry) (name client))
extra-steps (registry special-build-steps)
run-cmd (get-run-cmd registry)]
(println image-name)
(spit (str "tests/" image-name)
(new-dockerfile (dockerfile-template extra-steps run-cmd)
(name client)
client-version
registry-url))))