Skip to content

Commit

Permalink
working on post deploy upload of md5sum file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jef Spaleta committed Dec 4, 2018
1 parent 802b572 commit 64f4a3f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ script:
before_deploy:
- go get github.com/goreleaser/goreleaser
deploy:
skip_cleanup: true
- #goreleaser
provider: script
script: goreleaser
skip_cleanup: true
on:
tags: true
- #checksum
provider: script
script: travis/generate-sha512sum.sh
on:
tags: true

after_deploy:
- travis/generate-sha512sum.sh

env:
global:
Expand Down
67 changes: 67 additions & 0 deletions travis/github-release-upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
#
# This script accepts the following parameters:
#
# * owner
# * repo
# * tag
# * filename
# * github_api_token
#
# Script to upload a release asset using the GitHub API v3.
#
# Example:
#
# upload-github-release-asset.sh github_api_token=TOKEN repo_slug=hey/now tag=v0.1.0 filename=./build.zip
#

# Check dependencies.
set -e
xargs=$(which xargs)

# Validate settings.
[ "$TRACE" ] && set -x

CONFIG=$@

for line in $CONFIG; do
eval "$line"
done

# Define variables.
GH_API="https://api.github.com"
GH_REPO="$GH_API/repos/$repo_slug"
GH_TAGS="$GH_REPO/releases/tags/$tag"
AUTH="Authorization: token $github_api_token"
WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
CURL_ARGS="-LJO#"

if [[ "$tag" == 'LATEST' ]]; then
GH_TAGS="$GH_REPO/releases/latest"
fi

# Validate token.
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }

# Read asset tags.
echo "curl -sH "$AUTH" $GH_TAGS"
response=$(curl -sH "$AUTH" $GH_TAGS)

# Get ID of the asset based on given filename.
eval $(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
echo $id
[ "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; }

# Upload asset
echo "Uploading asset... "

# Construct url
GH_ASSET="https://uploads.github.com/repos/$repo_slug/releases/$id/assets?name=$(basename $filename)"
echo $GH_ASSET
echo "curl $GITHUB_OAUTH_BASIC --data-binary @$filename -H \"Authorization: token $github_api_token\" -H \"Content-Type: application/octet-stream\" $GH_ASSET"
curl ${GITHUB_OAUTH_BASIC} --data-binary @${filename} -H "Authorization: token ${github_api_token}" -H "Content-Type: application/octet-stream" ${GH_ASSET}

0 comments on commit 64f4a3f

Please sign in to comment.