Skip to content

Commit

Permalink
Showing 3 changed files with 369 additions and 44 deletions.
161 changes: 117 additions & 44 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ __dir__="$(cd "$(dirname "$0")" && pwd)"

# shellcheck source=scripts/configuration.sh
source "$__dir__/configuration.sh"
# shellcheck source=scripts/github.sh
source "$__dir__/github.sh"
# shellcheck source=scripts/aws.sh
source "$__dir__/aws.sh"
# shellcheck source=scripts/io.sh
@@ -59,64 +61,135 @@ function rbx_upload_files {
}

# Build and upload the release tarball to S3.
if [[ $TRAVIS_OS_NAME == osx ]]; then
echo "Deploying release tarball $(rbx_release_name)..."
function rbx_deploy_release_tarball {
if [[ $1 == osx ]]; then
echo "Deploying release tarball $(rbx_release_name)..."

"$__dir__/release.sh" || fail "unable to build release tarball"
"$__dir__/release.sh" || fail "unable to build release tarball"

rbx_upload_files "$(rbx_release_bucket)" "$(rbx_release_name)" "$(rbx_release_name)"
fi
rbx_upload_files "$(rbx_release_bucket)" "$(rbx_release_name)" "$(rbx_release_name)"
fi
}

# Build and upload a Homebrew binary to S3.
if [[ $TRAVIS_OS_NAME == osx ]]; then
echo "Deploying Homebrew binary $(rbx_release_name)..."
function rbx_deploy_homebrew_binary {
if [[ $1 == osx ]]; then
echo "Deploying Homebrew binary $(rbx_release_name)..."

"$__dir__/package.sh" homebrew || fail "unable to build Homebrew binary"
"$__dir__/package.sh" homebrew || fail "unable to build Homebrew binary"

rbx_upload_files "$(rbx_binary_bucket)" "$(rbx_release_name)" \
"$(rbx_release_name)" "/homebrew/"
fi
rbx_upload_files "$(rbx_binary_bucket)" "$(rbx_release_name)" \
"$(rbx_release_name)" "/homebrew/"
fi
}

# Build and upload a binary to S3.
echo "Deploying Travis binary $(rbx_release_name) for ${TRAVIS_OS_NAME}..."
function rbx_deploy_travis_binary {
local os_name vendor_llvm

# TODO: Remove this hack when LLVM 3.6/7 support lands.
vendor_llvm="./vendor/llvm/Release/bin/llvm-config"
if [[ -f "$vendor_llvm" ]]; then
export RBX_BINARY_CONFIG="--llvm-config=$vendor_llvm"
fi
os_name=$1
echo "Deploying Travis binary $(rbx_release_name) for $os_name..."

"$__dir__/package.sh" binary || fail "unable to build binary"

declare -a paths os_releases versions

if [[ $TRAVIS_OS_NAME == linux ]]; then
os_releases=("12.04" "14.04" "15.10")
for (( i=0; i < ${#os_releases[@]}; i++ )); do
paths[i]="/ubuntu/${os_releases[i]}/x86_64/"
# TODO: Remove this hack when LLVM 3.6/7 support lands.
if [[ $os_name == linux ]]; then
vendor_llvm="./vendor/llvm/Release/bin/llvm-config"
if [[ -f "$vendor_llvm" ]]; then
export RBX_BINARY_CONFIG="--llvm-config=$vendor_llvm"
fi
fi

"$__dir__/package.sh" binary || fail "unable to build binary"

declare -a paths os_releases versions

if [[ $os_name == linux ]]; then
os_releases=("12.04" "14.04" "15.10")
for (( i=0; i < ${#os_releases[@]}; i++ )); do
paths[i]="/ubuntu/${os_releases[i]}/x86_64/"
done
elif [[ $os_name == osx ]]; then
os_releases=("10.9" "10.10" "10.11")
for (( i=0; i < ${#os_releases[@]}; i++ )); do
paths[i]="/osx/${os_releases[i]}/x86_64/"
done
else
echo "${FUNCNAME[1]}: no match for OS name"
return
fi

IFS="." read -r -a array <<< "$(rbx_revision_version)"

let i=0
version=""
versions[i]=""

for v in "${array[@]}"; do
let i=i+1
versions[i]="-$version$v"
version="$v."
done
else
os_releases=("10.9" "10.10" "10.11")
for (( i=0; i < ${#os_releases[@]}; i++ )); do
paths[i]="/osx/${os_releases[i]}/x86_64/"

for path in "${paths[@]}"; do
for version in "${versions[@]}"; do
rbx_upload_files "$(rbx_binary_bucket)" "rubinius$version.tar.bz2" \
"$(rbx_release_name)" "$path"
done
done
fi
}

function rbx_deploy_github_release {
local os_name upload_url

IFS="." read -r -a array <<< "$(rbx_revision_version)"
os_name=$1

let i=0
version=""
versions[i]=""
if [[ $os_name == osx ]]; then
upload_url=$(rbx_github_release "$(rbx_revision_version)" "$(rbx_revision_date)")

rbx_github_release_assets "$upload_url" "$(rbx_release_name)"
fi
}

for v in "${array[@]}"; do
let i=i+1
versions[i]="-$version$v"
version="$v."
done
function rbx_deploy_website_release {
local os_name

for path in "${paths[@]}"; do
for version in "${versions[@]}"; do
rbx_upload_files "$(rbx_binary_bucket)" "rubinius$version.tar.bz2" \
"$(rbx_release_name)" "$path"
os_name=$1

if [[ $os_name == osx ]]; then
echo rbx_deploy_website_release
fi
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
if [[ -z $1 ]]; then
"$0" release github travis homebrew website
exit $?
fi

for cmd in "${@}"; do
case "$cmd" in
"release")
rbx_deploy_release_tarball "$TRAVIS_OS_NAME"
;;
"github")
rbx_deploy_github_release "$TRAVIS_OS_NAME"
;;
"travis")
rbx_deploy_travis_binary "$TRAVIS_OS_NAME"
;;
"homebrew")
rbx_deploy_homebrew_binary "$TRAVIS_OS_NAME"
;;
"website")
rbx_deploy_website_release "$TRAVIS_OS_NAME"
;;
*)
cat >&2 <<-EOM
Usage: ${0##*/} [release github travis homebrew website]
If no arguments are passed, all deploy tasks are run.
EOM
exit 1
;;
esac
done
done
fi
52 changes: 52 additions & 0 deletions scripts/github.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
__dir__="$(cd "$(dirname "$0")" && pwd)"

function rbx_github_release_url {
echo "https://api.github.com/repos/rubinius/rubinius/releases"
}

function rbx_github_release {
local version date request response upload_url

version=$1
date=$2

request=$(printf '{
"tag_name": "v%s",
"target_commitish": "master",
"name": "Release %s",
"body": "Version %s (%s)",
"draft": false,
"prerelease": false
}' "$version" "$version" "$version" "$date")

response=$(curl --data "$request" \
"$(rbx_github_release_url)?access_token=$GITHUB_OAUTH_TOKEN")

if [ $? -ne 0 ]; then
return
fi

upload_url=$(echo "$response" | "$__dir__/json.sh" -b | \
egrep '\["upload_url"\][[:space:]]\"[^"]+\"' | egrep -o '\"[^"]+{')

let i=${#upload_url}

echo "${upload_url:1:$i-2}"
}

function rbx_github_release_assets {
local upload_url name src file_exts

upload_url=$1
name=$2

file_exts=("" ".sha512")

for ext in "${file_exts[@]}"; do
src="$name$ext"

curl -X PUT -T "$src" \
-H "Content-Type: $(file --mime-type -b "$src")" \
"$upload_url?name=$src&access_token=$GITHUB_OAUTH_TOKEN"
done
}
200 changes: 200 additions & 0 deletions scripts/json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#!/usr/bin/env bash
#
# From https://github.com/dominictarr/JSON.sh
# Original License: MIT
# https://github.com/dominictarr/JSON.sh/blob/master/LICENSE.MIT

throw () {
echo "$*" >&2
exit 1
}

BRIEF=0
LEAFONLY=0
PRUNE=0
NORMALIZE_SOLIDUS=0

usage() {
echo
echo "Usage: JSON.sh [-b] [-l] [-p] [-s] [-h]"
echo
echo "-p - Prune empty. Exclude fields with empty values."
echo "-l - Leaf only. Only show leaf nodes, which stops data duplication."
echo "-b - Brief. Combines 'Leaf only' and 'Prune empty' options."
echo "-s - Remove escaping of the solidus symbol (stright slash)."
echo "-h - This help text."
echo
}

parse_options() {
set -- "$@"
local ARGN=$#
while [ "$ARGN" -ne 0 ]
do
case $1 in
-h) usage
exit 0
;;
-b) BRIEF=1
LEAFONLY=1
PRUNE=1
;;
-l) LEAFONLY=1
;;
-p) PRUNE=1
;;
-s) NORMALIZE_SOLIDUS=1
;;
?*) echo "ERROR: Unknown option."
usage
exit 0
;;
esac
shift 1
ARGN=$((ARGN-1))
done
}

awk_egrep () {
local pattern_string=$1

gawk '{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
print token;
$0=substr($0, start+RLENGTH);
}
}' pattern="$pattern_string"
}

tokenize () {
local GREP
local ESCAPE
local CHAR

if echo "test string" | egrep -ao --color=never "test" &>/dev/null
then
GREP='egrep -ao --color=never'
else
GREP='egrep -ao'
fi

if echo "test string" | egrep -o "test" &>/dev/null
then
ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\]'
else
GREP=awk_egrep
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\\\]'
fi

local STRING="\"$CHAR*($ESCAPE$CHAR*)*\""
local NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD='null|false|true'
local SPACE='[[:space:]]+'

$GREP "$STRING|$NUMBER|$KEYWORD|$SPACE|." | egrep -v "^$SPACE$"
}

parse_array () {
local index=0
local ary=''
read -r token
case "$token" in
']') ;;
*)
while :
do
parse_value "$1" "$index"
index=$((index+1))
ary="$ary""$value"
read -r token
case "$token" in
']') break ;;
',') ary="$ary," ;;
*) throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
[ "$BRIEF" -eq 0 ] && value=$(printf '[%s]' "$ary") || value=
:
}

parse_object () {
local key
local obj=''
read -r token
case "$token" in
'}') ;;
*)
while :
do
case "$token" in
'"'*'"') key=$token ;;
*) throw "EXPECTED string GOT ${token:-EOF}" ;;
esac
read -r token
case "$token" in
':') ;;
*) throw "EXPECTED : GOT ${token:-EOF}" ;;
esac
read -r token
parse_value "$1" "$key"
obj="$obj$key:$value"
read -r token
case "$token" in
'}') break ;;
',') obj="$obj," ;;
*) throw "EXPECTED , or } GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
[ "$BRIEF" -eq 0 ] && value=$(printf '{%s}' "$obj") || value=
:
}

parse_value () {
local jpath="${1:+$1,}$2" isleaf=0 isempty=0 print=0
case "$token" in
'{') parse_object "$jpath" ;;
'[') parse_array "$jpath" ;;
# At this point, the only valid single-character tokens are digits.
''|[!0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token
# if asked, replace solidus ("\/") in json strings with normalized value: "/"
[ "$NORMALIZE_SOLIDUS" -eq 1 ] && value=${value//\\\//\/}
isleaf=1
[ "$value" = '""' ] && isempty=1
;;
esac
[ "$value" = '' ] && return
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && [ $PRUNE -eq 0 ] && print=1
[ "$LEAFONLY" -eq 0 ] && [ "$PRUNE" -eq 1 ] && [ "$isempty" -eq 0 ] && print=1
[ "$LEAFONLY" -eq 1 ] && [ "$isleaf" -eq 1 ] && \
[ $PRUNE -eq 1 ] && [ $isempty -eq 0 ] && print=1
[ "$print" -eq 1 ] && printf "[%s]\t%s\n" "$jpath" "$value"
:
}

parse () {
read -r token
parse_value
read -r token
case "$token" in
'') ;;
*) throw "EXPECTED EOF GOT $token" ;;
esac
}

if ([ "$0" = "$BASH_SOURCE" ] || ! [ -n "$BASH_SOURCE" ]);
then
parse_options "$@"
tokenize | parse
fi

0 comments on commit a66e804

Please sign in to comment.