|
1 | 1 | (defn run-process |
2 | 2 | ([argv] (run-process argv {})) |
3 | | - ([argv {:keys [dir env inherit? timeout-ms] :or {env {}}}] |
| 3 | + ([argv {:keys [dir env inherit?] :or {env {}}}] |
4 | 4 | (let [opts (cond-> {:env (merge (into {} (System/getenv)) env)} |
5 | 5 | dir (assoc :dir (str dir)) |
6 | 6 | inherit? (assoc :out :inherit :err :inherit) |
7 | 7 | (not inherit?) (assoc :out :string :err :string)) |
8 | | - proc (process/process argv opts) |
9 | | - result (if (and timeout-ms (pos? timeout-ms)) |
10 | | - (let [outcome (deref proc timeout-ms ::timeout)] |
11 | | - (if (= outcome ::timeout) |
12 | | - (do (process/destroy-tree proc) (deref proc) {:exit 124 :timed-out? true}) |
13 | | - outcome)) |
14 | | - @proc)] |
15 | | - (cond-> {:exit (:exit result) :out (or (:out result) "") :err (or (:err result) "")} |
16 | | - (:timed-out? result) (assoc :timed-out? true :err (str "timed out after " timeout-ms "ms")))))) |
| 8 | + result @(process/process argv opts)] |
| 9 | + {:exit (:exit result) :out (or (:out result) "") :err (or (:err result) "")}))) |
17 | 10 |
|
18 | 11 | (defn run-checked [argv options label] |
19 | 12 | (let [result (run-process argv options)] |
|
69 | 62 | bin)))) |
70 | 63 |
|
71 | 64 | (defn write-progress [message] (binding [*out* *err*] (println (str "[ccusage-perf] " message)))) |
72 | | -(def curl-timeout-flags ["--connect-timeout" "10" "--max-time" "60"]) |
73 | | -(defn git-sha [directory timeout-ms] |
74 | | - (str/trim (:out (run-checked ["git" "rev-parse" "HEAD"] {:dir directory :timeout-ms timeout-ms} "git rev-parse HEAD")))) |
| 65 | +(defn git-sha [directory] |
| 66 | + (str/trim (:out (run-checked ["git" "rev-parse" "HEAD"] {:dir directory} "git rev-parse HEAD")))) |
75 | 67 | (defn package-url-ready? [url] |
76 | | - (zero? (:exit (run-process (into ["curl" "--fail" "--head" "--location" "--silent"] |
77 | | - (concat curl-timeout-flags ["--output" "/dev/null" url])))))) |
| 68 | + (zero? (:exit (run-process ["curl" "--fail" "--head" "--location" "--silent" "--output" "/dev/null" url])))) |
78 | 69 | (defn wait-for-package-url [url timeout-ms] |
79 | 70 | (let [deadline (+ (System/currentTimeMillis) timeout-ms)] |
80 | 71 | (loop [] |
|
92 | 83 | (json/generate-string {:private true :dependencies {:ccusage url}} {:pretty true})) |
93 | 84 | (write-progress (str label " package install started: " url)) |
94 | 85 | (let [started (System/currentTimeMillis) |
95 | | - result (run-process ["bun" "install" "--no-progress"] {:dir install-dir :timeout-ms timeout-ms}) |
| 86 | + result (run-process ["bun" "install" "--no-progress"] {:dir install-dir}) |
96 | 87 | elapsed (- (System/currentTimeMillis) started)] |
97 | 88 | (when-not (zero? (:exit result)) |
98 | 89 | (fail! (str label " package install failed: " |
|
107 | 98 | (defn packed-tarball-path [destination filename] |
108 | 99 | (if (fs/absolute? filename) filename (path destination filename))) |
109 | 100 |
|
110 | | -(defn packed-tarball-size [repo-dir timeout-ms] |
| 101 | +(defn packed-tarball-size [repo-dir] |
111 | 102 | (let [package-dir (path repo-dir "apps" "ccusage") |
112 | 103 | package-json-path (path package-dir "package.json") |
113 | 104 | original (slurp package-json-path) |
114 | 105 | destination (temp-dir "ccusage-pack.")] |
115 | 106 | (try |
116 | | - (let [result (run-process ["pnpm" "pack" "--json" "--pack-destination" (str destination)] {:dir package-dir :timeout-ms timeout-ms})] |
| 107 | + (let [result (run-process ["pnpm" "pack" "--json" "--pack-destination" (str destination)] {:dir package-dir})] |
117 | 108 | (when-not (zero? (:exit result)) |
118 | 109 | (fail! (str "pnpm pack failed: " (str/trim (or (not-empty (:err result)) (:out result)))) |
119 | 110 | {:kind :package-metadata-failed :exit (:exit result)})) |
|
129 | 120 | (defn remote-tarball-size [url] |
130 | 121 | (let [output (fs/create-temp-file {:prefix "ccusage-package."})] |
131 | 122 | (try |
132 | | - (run-checked (into ["curl" "--fail" "--location" "--silent"] |
133 | | - (concat curl-timeout-flags ["--output" (str output) url])) |
| 123 | + (run-checked ["curl" "--fail" "--location" "--silent" "--output" (str output) url] |
134 | 124 | {} (str "Failed to fetch " url)) |
135 | 125 | (optional-file-size output) |
136 | 126 | (finally (fs/delete-if-exists output))))) |
|
0 commit comments