Compare commits
	
		
			2 commits
		
	
	
		
			f95b7ccd7d
			...
			2b7396cb2f
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 2b7396cb2f | |||
| 4868599c9b | 
					 4 changed files with 78 additions and 11 deletions
				
			
		
							
								
								
									
										24
									
								
								LICENSE
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								LICENSE
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
This is free and unencumbered software released into the public domain.
 | 
			
		||||
 | 
			
		||||
Anyone is free to copy, modify, publish, use, compile, sell, or
 | 
			
		||||
distribute this software, either in source code form or as a compiled
 | 
			
		||||
binary, for any purpose, commercial or non-commercial, and by any
 | 
			
		||||
means.
 | 
			
		||||
 | 
			
		||||
In jurisdictions that recognize copyright laws, the author or authors
 | 
			
		||||
of this software dedicate any and all copyright interest in the
 | 
			
		||||
software to the public domain. We make this dedication for the benefit
 | 
			
		||||
of the public at large and to the detriment of our heirs and
 | 
			
		||||
successors. We intend this dedication to be an overt act of
 | 
			
		||||
relinquishment in perpetuity of all present and future rights to this
 | 
			
		||||
software under copyright law.
 | 
			
		||||
 | 
			
		||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 | 
			
		||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 | 
			
		||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 | 
			
		||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 | 
			
		||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 | 
			
		||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 | 
			
		||||
OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		||||
 | 
			
		||||
For more information, please refer to <http://unlicense.org/>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,8 +1,13 @@
 | 
			
		|||
#! /usr/bin/bb
 | 
			
		||||
(require '[babashka.curl :as curl])
 | 
			
		||||
 | 
			
		||||
;;executes shell command but throws exception on error
 | 
			
		||||
(defn- safe-sh [& commands]
 | 
			
		||||
  (as-> (apply shell/sh commands) $
 | 
			
		||||
      (if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
 | 
			
		||||
 | 
			
		||||
;;gets the working directory, but removes the new line in the end
 | 
			
		||||
(def wd (as-> (:out (shell/sh "pwd")) $
 | 
			
		||||
(def wd (as-> (:out (safe-sh "pwd")) $
 | 
			
		||||
          (subs $ 0 (- (count $) 1))))
 | 
			
		||||
(def metadata-file "output-metadata.json")
 | 
			
		||||
(def config-file "enterprise-releases.json")
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +23,7 @@
 | 
			
		|||
(defn- create-enterprise-release [module variant]
 | 
			
		||||
  "builds the app using the given module & variant and then returns the parsed metadata"
 | 
			
		||||
  (println "building project..")
 | 
			
		||||
  (shell/sh (create-path-string wd "gradlew") (str ":" module ":assemble" (str/capitalize variant)))
 | 
			
		||||
  (safe-sh (create-path-string wd "gradlew") (str ":" module ":assemble" (str/capitalize variant)))
 | 
			
		||||
  (json/parse-string (slurp (create-path-string (get-output-folder module variant) metadata-file)) true))
 | 
			
		||||
 | 
			
		||||
(defn- fetch-remote-config [server path file-name]
 | 
			
		||||
| 
						 | 
				
			
			@ -51,13 +56,30 @@
 | 
			
		|||
      (curl/post (str server path "/" file-name ".json") {:raw-args ["-T" updated-remote-file]}))
 | 
			
		||||
    (println (str "new version " version-name " (" new-version ")" " successfully uploaded to " (name (first config))))))
 | 
			
		||||
 | 
			
		||||
(defn- add-git-tag [config metadata]
 | 
			
		||||
  "creates a new git tag based on the defined format and pushes it to the remote repository"
 | 
			
		||||
  (let [unstaged-changes (filter #(not (str/blank? %)) (str/split-lines (:out (safe-sh "git" "status" "-s" "uno"))))
 | 
			
		||||
        nr-of-changes (count unstaged-changes)]
 | 
			
		||||
    (if (= nr-of-changes 0)
 | 
			
		||||
      (let [tag-format (:format config)
 | 
			
		||||
            tag-args (map #(get-in metadata [:elements 0 %]) (map #(keyword %) (:arguments config)))
 | 
			
		||||
            tag (apply format (conj tag-args tag-format))
 | 
			
		||||
            remote "origin"]
 | 
			
		||||
        (safe-sh "git" "tag" tag)
 | 
			
		||||
        (safe-sh "git" "push" remote tag)
 | 
			
		||||
        (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]
 | 
			
		||||
  "builds & uploads the application based on the handed over configuration"
 | 
			
		||||
  (let [info (second config)
 | 
			
		||||
        module (:module info)
 | 
			
		||||
        variant (:variant info)]
 | 
			
		||||
    (as-> (create-enterprise-release module variant) $
 | 
			
		||||
      (upload-version config $))))
 | 
			
		||||
        variant (:variant info)
 | 
			
		||||
        git-tag (:gitTag info)]
 | 
			
		||||
    (let [metadata (create-enterprise-release module variant)]
 | 
			
		||||
      (upload-version config metadata)
 | 
			
		||||
      (if (not (nil? git-tag))
 | 
			
		||||
        (add-git-tag git-tag metadata)))))
 | 
			
		||||
 | 
			
		||||
(def config (json/parse-string (slurp (create-path-string wd config-file)) true))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,11 @@ This file can contain multiple release configurations and needs to specify a cou
 | 
			
		|||
        "variant": "debug",
 | 
			
		||||
        "server": "sftp://127.0.0.1",
 | 
			
		||||
        "path": "/var/www/apps/projects/test",
 | 
			
		||||
        "fileName": "Enterprise-Test"
 | 
			
		||||
        "fileName": "Enterprise-Test",
 | 
			
		||||
        "gitTag": {
 | 
			
		||||
            "format": "ent/v%d",
 | 
			
		||||
            "arguments": ["versionCode"]
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    "INT": {
 | 
			
		||||
        "module": "app",
 | 
			
		||||
| 
						 | 
				
			
			@ -22,11 +26,14 @@ This file can contain multiple release configurations and needs to specify a cou
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
- `module`: specifies the module built with Gradle
 | 
			
		||||
- `variant`: the variant that should be built. it's combined with the module from above to create the proper Gradle command, e.g. `:app:assembleDebug`
 | 
			
		||||
- `server`: the server (including protocol) to upload the files to
 | 
			
		||||
- `path`: the path on the remote server where the files should be placed
 | 
			
		||||
- `fileName`: the name to be used for the apk & json files on the remote
 | 
			
		||||
- `module`: Specifies the module built with Gradle.
 | 
			
		||||
- `variant`: The variant that should be built. It's combined with the module from above to create the proper Gradle command, e.g. `:app:assembleDebug`.
 | 
			
		||||
- `server`: The server (including protocol) to upload the files to.
 | 
			
		||||
- `path`: The path on the remote server where the files should be placed.
 | 
			
		||||
- `fileName`: The name to be used for the apk & json files on the remote.
 | 
			
		||||
- `gitTag`: Optional object specifying the format of git tags that should be created automatically.
 | 
			
		||||
  - `format`: A string specifying the tag format. Uses classic [Java formatting](https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html) of strings.
 | 
			
		||||
  - `arguments`: Arguments supplied to the format string. You can use `versionCode` and/or `versionName` here. (Theoretically it could be any value inside the `elements` key from the `output-metadata.json` file generated by the Gradle build.)
 | 
			
		||||
 | 
			
		||||
If there's only one release configuration defined, it will automatically pick that one. In case there are multiple configurations you have to add the configuration name you want to build & upload as argument (see examples below).
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										14
									
								
								readme.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								readme.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
# Android Scripts
 | 
			
		||||
Welcome to my personal script collection.  
 | 
			
		||||
This repository contains a selection of scripts which I created to make my life as Android developer a bit easier.
 | 
			
		||||
Whenever I feel like there's a need for it, I'll add another one.  
 | 
			
		||||
Just take what appeals to you, I'd be happy if it helped you in some way!
 | 
			
		||||
 | 
			
		||||
## Running
 | 
			
		||||
All scripts are written in Clojure and require [Babashka](https://babashka.org/) to run.
 | 
			
		||||
Just follow the instructions for your operating system on the website. In case there's no proper way of distribution for your OS you can always just download the binary from [their releases](https://github.com/babashka/babashka/releases) and add it to your path, which is what I'm also doing.  
 | 
			
		||||
 | 
			
		||||
To get info on how to actually use the individual scripts just take a look in the corresponding folder. Normally each folder should contain a readme which explains the purpose and usage of the script.
 | 
			
		||||
 | 
			
		||||
## License
 | 
			
		||||
These scripts are all "unlicensed", see the [LICENSE](LICENSE) file.
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue