Skip to content

Commit

Permalink
Fix travis release upload
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Apr 15, 2018
1 parent 48de632 commit 7437ddb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 17 deletions.
20 changes: 3 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ script:
- cp meshlite/target/release/libmeshlite.dylib thirdparty/meshlite/libmeshlite.dylib
- qmake -config release
- make
#- mv dust3d.app dust3d-unstable.app
#- macdeployqt dust3d-unstable.app -dmg

#deploy:
# - provider: releases
# api_key:
# secure: ZoWp2r5I3tq6QjVJZBpZUwch0PBKV2GWqsaKGKc/Ntic28S2aNecF91Esx7Ebt/aUxVmooONvkSF0DvTsf9nUSxgRUhGI9kaPC3Ove4AGJjMUfSzdVSmv7DRFLWfZx/g4e0SxZ7QShiZQ4y9t08wMUZaCIt6hH46oe+FY8hawxnQ7BZMkdQDL7re2BO0XixBMzTO3ZeLJIPreFs9K/bCUwsmsC++EKf5lRkxQDkBPgryumQuKB//4D8NIsnfmjrUYH4mdCRIezIiiafFXiWSeYO+iuBtme/PH3V7c9npNCp4qbYIi0YwfPeLMS+sDngqWSmn/KFaXhPeS2h9z2z/dHf9C59kQ2Z83hdAujrX66lnrwL5le511KUpPAcH4z/DQpLMYn3zvac9dZVkRt4Ze+8Mw8UvdzNKUp0OafyeYTF85DoTP8dZW1pDMTdTSOm8u9xuPx64qX1D6os0I1mK8dTyQvcDYoKlZ7/V7nD2Xm0+p1LsRx4+K0BQF9PWytT2u0I8Tx9RUcy3p6vMS7vrYtgFvuW7sLKIvgkP/n2PvHRmUcTCD7SdFE8U7nwqEAyPXg5F2jO4CxrLzkU4R2OpPSh30+gE3TF3DtyldFdAk+RIrKtLu3iW1dek0YgtkF+zLGMVAWzTjkJhSRk8bzeyhdGwGpjfnJq1QstHknZB/iA=
# file:
# - dust3d-unstable.dmg
# overwrite: true
# skip_cleanup: true
# on:
# tags: true
# condition: $TRAVIS_OS_NAME = osx
# branches:
# only:
# - master
- mv dust3d.app dust3d_unstable.app
- macdeployqt dust3d_unstable.app -dmg
- sh ci/upload-github-release-asset.sh github_api_token=${my_auth_token} branch=$TRAVIS_BRANCH owner=huxingyi repo=dust3d tag=unstable filename=dust3d_unstable.dmg
84 changes: 84 additions & 0 deletions ci/upload-github-release-asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
#
# Author: Stefan Buck
# License: MIT
# https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
#
# Note: This file has been slightly changed from the original version(Stefan Buck) by adding asset overwrite.
#
# 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 owner=stefanbuck repo=playground tag=v0.1.0 filename=./build.zip
#

# Check dependencies.
set -e
xargs=$(which gxargs || 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/$owner/$repo"
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

if [ "$branch" == "master" ] || [ "$branch" == "ci" ]; then
echo "Start upload progress..."
else
echo "This branch($branch) no need to upload."
exit 0
fi

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

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

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

# Get ID of the asset based on given filename.
id=""
eval $(echo "$response" | grep -C1 "name.:.\+$filename" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
assert_id="$id"
if [ "$assert_id" = "" ]; then
echo "No need to overwrite asset"
else
echo "Deleting asset($assert_id)... "
curl "$GITHUB_OAUTH_BASIC" -X "DELETE" -H "Authorization: token $github_api_token" "https://api.github.com/repos/$owner/$repo/releases/assets/$assert_id"
fi

# Upload asset
echo "Uploading asset... "

# Construct url
GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$release_id/assets?name=$(basename $filename)"

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 7437ddb

Please sign in to comment.