take optional ssh-key argument for enterprise release publisher
parent
ccbf5ecb7a
commit
1c6b27ae7a
|
@ -5,7 +5,11 @@
|
|||
(def cli-options
|
||||
[["-s" "--skip-build" "Skips the building process and will upload the currently built version."
|
||||
:id :skip-build
|
||||
:default false]])
|
||||
:default false]
|
||||
["-k" "--key SSH-KEY" "The SSH key to use to connect to the server."
|
||||
:id :ssh-key
|
||||
:parse-fn str
|
||||
:default nil]])
|
||||
|
||||
(def parsed-params (parse-opts *command-line-args* cli-options))
|
||||
(def options (:options parsed-params))
|
||||
|
@ -40,40 +44,47 @@
|
|||
(println "building project..")
|
||||
(safe-sh (create-path-string wd "gradlew") (str ":" module ":assemble" (str/capitalize variant))))
|
||||
|
||||
(defn- non-nil-vector [& args]
|
||||
(apply vector (keep identity (flatten args))))
|
||||
|
||||
(defn- fetch-remote-config [server user path file-name]
|
||||
(non-nil-vector "-u" (str "a" ":") (if (not false)
|
||||
(list "--key" "key")))
|
||||
|
||||
(defn- fetch-remote-config [server user ssh-key path file-name]
|
||||
"fetches and parses the configuration on the remote server"
|
||||
(let [remote-path (str server path "/" file-name ".json")]
|
||||
(println "fetching remote config..")
|
||||
(json/parse-string (->
|
||||
(:body (curl/get remote-path {:raw-args ["-u" (str user ":")]}))
|
||||
(:body (curl/get remote-path {:raw-args (non-nil-vector "-u" (str user ":") (if (not (nil? ssh-key))
|
||||
(list "--key" ssh-key)))}))
|
||||
;; remove non printable characters causing parsing issues
|
||||
(str/replace #"\p{C}" ""))
|
||||
true)))
|
||||
|
||||
(defn- upload-version [config metadata]
|
||||
(defn- upload-version [config options metadata]
|
||||
"uploads the built apk and updates the remote json to reflect the new version"
|
||||
(let [info (second config)
|
||||
server (:server info)
|
||||
user (:user info)
|
||||
ssh-key (:ssh-key options)
|
||||
path (:path info)
|
||||
file-name (:fileName info)
|
||||
output-folder (get-output-folder (:module info) (:productFlavor info) (:buildType info))
|
||||
output-file (create-path-string output-folder (get-in metadata [:elements 0 :outputFile]))
|
||||
remote-config (fetch-remote-config server user path file-name)
|
||||
remote-config (fetch-remote-config server user ssh-key path file-name)
|
||||
new-version (get-in metadata [:elements 0 :versionCode])
|
||||
version-name (get-in metadata [:elements 0 :versionName])]
|
||||
(if (<= new-version (get-in remote-config [:android :version_code]))
|
||||
(println "warning: version on remote was higher or the same as uploaded version"))
|
||||
(println "uploading apk..")
|
||||
(curl/post (str server path "/" file-name ".apk") {:raw-args ["-T" output-file "-u" (str user ":")]})
|
||||
(curl/post (str server path "/" file-name ".apk") {:raw-args (non-nil-vector "-T" output-file "-u" (str user ":") (if (not (nil? ssh-key)) (list "--key" ssh-key)))})
|
||||
(println "updating version on remote..")
|
||||
(let [updated-remote-file (create-path-string output-folder (str file-name ".json"))]
|
||||
(as-> remote-config $
|
||||
(update-in $ [:android :version_code] (fn [x] new-version))
|
||||
(json/generate-string $ {:pretty true})
|
||||
(spit updated-remote-file $))
|
||||
(curl/post (str server path "/" file-name ".json") {:raw-args ["-T" updated-remote-file "-u" (str user ":")]}))
|
||||
(curl/post (str server path "/" file-name ".json") {:raw-args (non-nil-vector "-T" updated-remote-file "-u" (str user ":") (if (not (nil? ssh-key)) (list "--key" ssh-key)))}))
|
||||
(println (str "new version " version-name " (" new-version ")" " successfully uploaded to " (name (first config))))))
|
||||
|
||||
(defn- add-git-tag [config metadata]
|
||||
|
@ -90,9 +101,10 @@
|
|||
(println (str "created tag " tag " and pushed it to remote " remote)))
|
||||
(println "warning: there were uncommitted changes. git tag was not automatically created"))))
|
||||
|
||||
(defn- build-and-upload [config skip-build]
|
||||
(defn- build-and-upload [config options]
|
||||
"builds & uploads the application based on the handed over configuration"
|
||||
(let [info (second config)
|
||||
skip-build (:skip-build options)
|
||||
module (:module info)
|
||||
product-flavor (:productFlavor info)
|
||||
build-type (:buildType info)
|
||||
|
@ -100,7 +112,7 @@
|
|||
git-tag (:gitTag info)]
|
||||
(if (not skip-build) (create-enterprise-release module variant))
|
||||
(let [metadata (parse-generated-metadata-file module product-flavor build-type)]
|
||||
(upload-version config metadata)
|
||||
(upload-version config options metadata)
|
||||
(if (not (nil? git-tag))
|
||||
(add-git-tag git-tag metadata)))))
|
||||
|
||||
|
@ -115,4 +127,4 @@
|
|||
|
||||
(if (nil? selected-config)
|
||||
(println "error: no matching config found")
|
||||
(build-and-upload selected-config (:skip-build options)))
|
||||
(build-and-upload selected-config options))
|
||||
|
|
|
@ -55,11 +55,9 @@ erp.clj -s "INT"
|
|||
|
||||
##
|
||||
### SSH Configuration
|
||||
I'm assuming that you've properly defined your credentials in `~/.ssh/config`. Unfortunately curl does not pick up the users defined inside that file, so the actual user still has to be specified inside `enterprise-releases.json`.
|
||||
|
||||
```
|
||||
Host SERVER
|
||||
IdentityFile PATH_TO_KEY
|
||||
You can use the `-k` option to provide an SSH key to use, if you are not using your default SSH key.
|
||||
```bash
|
||||
erp.clj -k /home/user/.ssh/enterprise
|
||||
```
|
||||
|
||||
### Fish
|
||||
|
@ -67,7 +65,7 @@ If you don't want to add the script itself to your path you can also create a fi
|
|||
|
||||
```
|
||||
function erp
|
||||
PATH_TO_SCRIPT/erp.clj $argv
|
||||
PATH_TO_SCRIPT/erp.clj -k /home/user/.ssh/enterprise $argv
|
||||
end
|
||||
|
||||
funcsave erp
|
||||
|
|
Loading…
Reference in New Issue