Skip to content

Commit

Permalink
Added GitHub release for deploy.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Dec 23, 2015
1 parent 1265212 commit a66e804
Show file tree
Hide file tree
Showing 3 changed files with 369 additions and 44 deletions.
161 changes: 117 additions & 44 deletions scripts/deploy.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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
@@ -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
}

0 comments on commit a66e804

Please sign in to comment.