Skip to content

Commit

Permalink
Better organize Clojure code, unpublish extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed May 31, 2022
1 parent 7e1eb44 commit 653ec22
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 216 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
fetch-depth: 0

- run: clojure -M script/build.clj
- run: clojure -M -m community-extensions.build

- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -54,4 +54,4 @@ jobs:
env:
FIREBASE_SERVICE_KEY: ${{ secrets.FIREBASE_SERVICE_KEY }}

- run: clojure -M script/publish.clj --key ./firebase-key.json
- run: clojure -M -m community-extensions.publish --key ./firebase-key.json
3 changes: 2 additions & 1 deletion extensions/tonsky/roam-calculator.json
Expand Up @@ -3,8 +3,9 @@
"short_description": "Prints 'Test message 1'",
"author": "Nikita Prokopov",
"tags": [
"print",
"test",
"print"
"test2"
],
"source_url": "https://github.com/tonsky/roam-calculator",
"source_repo": "https://github.com/tonsky/roam-calculator.git",
Expand Down
65 changes: 0 additions & 65 deletions script/build.clj

This file was deleted.

148 changes: 0 additions & 148 deletions script/publish.clj

This file was deleted.

27 changes: 27 additions & 0 deletions src/community_extensions/build.clj
@@ -0,0 +1,27 @@
(ns community-extensions.build
(:require
[clojure.java.io :as io]
[clojure.java.shell :as shell]
[clojure.string :as str]
[community-extensions.core :as core]))

(def args-map
(apply array-map *command-line-args*))

(defn build [ext-id data]
(let [dir (io/file "checkout" ext-id)
{repo "source_repo"
commit "source_commit"} data]
(when-not (.exists dir)
(.mkdirs dir)
(core/sh "git" "clone" repo (str "checkout/" ext-id)))
(shell/with-sh-dir dir
(core/sh "git" "-c" "advice.detachedHead=false" "checkout" commit))))

(defn -main [& {:as args-map}]
(doseq [[mode ext-id data] (core/diff args-map)]
(cond
(= "A" mode) (build ext-id data)
(= "M" mode) (build ext-id data)
(str/starts-with? "R" mode) :nop))
(shutdown-agents))
30 changes: 30 additions & 0 deletions src/community_extensions/core.clj
@@ -0,0 +1,30 @@
(ns community-extensions.core
(:require
[cheshire.core :as json]
[clojure.java.io :as io]
[clojure.java.shell :as shell]
[clojure.string :as str]))

(defn sh [& cmd]
(apply println "[ sh ]" cmd)
(let [{:keys [out err exit]} (apply shell/sh cmd)]
(when-not (str/blank? err)
(binding [*out* *err*]
(println err)))
(if (= 0 exit)
(str/trim out)
(throw (Exception. (str "Command '" (str/join " " cmd) "' failed with exit code " exit))))))

(defn diff [args-map]
(let [{sha-from "--from"
sha-to "--to"} args-map]
(for [[mode path] (->> (sh "git" "diff" "--name-status" (or sha-from "HEAD~1") (or sha-to "HEAD"))
(str/split-lines)
(map #(str/split % #"\t")))
:when (str/starts-with? path "extensions/")
:let [[_ user repo] (re-matches #"extensions/([^/]+)/([^/]+)\.json" path)
ext-id (str user "+" repo)
data (-> (io/file path)
(slurp)
(json/parse-string))]]
[mode ext-id data])))

0 comments on commit 653ec22

Please sign in to comment.