Skip to content

Instantly share code, notes, and snippets.

@fennifith
Last active February 4, 2019 18:39
Show Gist options
  • Save fennifith/4221a79ec5f39c21085fec4c41d7d160 to your computer and use it in GitHub Desktop.
Save fennifith/4221a79ec5f39c21085fec4c41d7d160 to your computer and use it in GitHub Desktop.
A script to format environment variables into a Bintray descriptor file to use for Travis deployments.
{
"package": {
"name": "$(echo $TRAVIS_REPO_SLUG | cut -d '/' -f 2)",
"repo": "builds",
"subject": "18jafenn90",
"vcs_url": "https://github.com/$TRAVIS_REPO_SLUG",
"issue_tracker_url": "https://github.com/$TRAVIS_REPO_SLUG/issues",
"licenses": ["Apache-2.0"]
},
"version": {
"name": "$TRAVIS_COMMIT",
"desc": "$TRAVIS_COMMIT_MESSAGE"
},
"files": [
{
"includePattern": "app/build/outputs/apk/(.*)/(.*\\.apk)",
"uploadPattern": "/$TRAVIS_COMMIT/\$2",
"matrixParams": {
"override": 1
}
}
],
"publish": true
}
#!/bin/bash
# MIT License
#
# Copyright (c) 2019 James Fenn
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# 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 OR COPYRIGHT HOLDERS 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.
# All that this script really does is replace all "$SOMETHING" strings in 'bintray.json'
# with the respective environment variables, and write the result to itself. It looks weird,
# but it works. Trust me.
#
# Variables that you do not want to be replaced (ex: $2 in the `uploadPattern` in the json
# file above) can be escaped with a backslash ("\$2" will become just "$2" in the output).
# Escaped characters will need to be double-escaped as well ("\\.apk" will become "\.apk").
#
# See https://unix.stackexchange.com/questions/294835/replace-environment-variables-in-a-file-with-their-actual-values
# for more ways to do this. I am only using this method because it A: works, and B: has the
# smallest amount of dependencies.
eval "cat << EOF
$(<bintray.json)
EOF
" > bintray.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment