Add travis CI script to auto-update homebrew formula

This commit is contained in:
James Dinsdale 2017-07-05 23:23:56 +01:00
parent 69a55a927d
commit c9993257ce
No known key found for this signature in database
GPG key ID: DBCB56BD98007031
2 changed files with 73 additions and 0 deletions

13
.travis.yml Normal file
View file

@ -0,0 +1,13 @@
language: generic
addons:
apt:
packages:
- zsh
deploy:
provider: script
script: scripts/update-homebrew.zsh $TRAVIS_TAG
on:
tags: true
env:
global:
secure: XO16NzSnPrd8O1ef1I+UhJSaAJrYhniOmGhr4/t5Kjw5wC3MBFJhLyE45yXPKdtUn+wWWWM+LdgiU0+/qEAM6Gt6CkuvUrPCmDdhW3XqYuUAP9Xl3KWdxgqmuApfZbmmdUjQDXxJoMGfik3ftIEaF6L4sEpYjR2kvf0TOulorskfIuGZs1QislNZQIvryN2o3iPc3pS5Hv7CfxaqoftYiAgJPHvr6dcmZ/rtCcbYrQhBMUsQ/+BbemkhUz3GQdGkYBYlb1PZZ9qeuJAWvHzZQ+W10ZYk+Hw5hSaR+MgUTrk888GeSpnabluvv9pgnKb3+Y8mXFjdTQ/0x+wVcc9LRyWWi72/MSg0Y2zsh5ZWUb7RS3iGqnwNpAFMkJ/E/WKmppjBwaZr3zBIWASfhrarhnphazmiybTkv2s0H1siyv9b1eF/EoyWk2p1xAzHUgd/mFT6lWrvYa9X+KTlWn+U8lrh7xFmEGhL9sFDBiIBBl1ooR3yBIVuwDR4j5jtZvSXt9g5M+Xq7s+OMFTJeVj6rnZ2ylco3hVEiAhGWvqfAHD8i9ltAmI7qA/g+uIjr045pcE2N4PZyYjKkvvChXUZqyS5CmzjHWV9E3kOz4cWi6xX4jQ/SwyNmVhft0co4BmRye40QykpAYe7HhuxZuHsEwCAtO8P1LdC1em49Xp64Z8=

60
scripts/update-homebrew.zsh Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env zsh
function update_homebrew() {
local version="$1"
local url="https://github.com/molovo/revolver/archive/$version.tar.gz"
local -a sumcmds; sumcmds=(sha256sum gsha256sum)
local sumcmd
if [[ -z $GH_TOKEN ]]; then
echo '\033[0;31mGithub repo token not found\033[0;m'
exit 1
fi
if [[ -z $version ]]; then
echo '\033[0;31mMust supply a version\033[0;m'
exit 1
fi
for cmd in $sumcmds; do
if type -p $cmd >/dev/null 2>&1; then
sumcmd=$cmd
break
fi
done
if [[ -z $sumcmd ]]; then
echo '\033[0;31mUnable to find sha256sum\033[0;m'
exit 1
fi
wget $url
local sum=($($sumcmd $version.tar.gz))
sum=${sum[1]}
local oldIFS=$IFS
IFS=$'\n'
local formula=($(cat ./Formula/revolver.rb))
for line in "${(@f)formula}"; do
if [[ "$line" =~ '^([ ]+)?url \".*\"' ]]; then
echo " url \"$url\"" >> tmpfile
continue
fi
if [[ "$line" =~ '^([ ]+)?sha256 \".*\"' ]]; then
echo " sha256 \"$sum\"" >> tmpfile
continue
fi
echo $line >> tmpfile
done
IFS=$oldIFS
mv tmpfile ./Formula/revolver.rb
git remote add deploy https://${GH_TOKEN}@github.com/molovo/revolver.git >/dev/null 2>&1
git add ./Formula/revolver.rb
git commit -m "Update homebrew formula"
git push --quiet deploy master >/dev/null 2>&1
}
update_homebrew "$@"