Fix travis release upload

master
Jeremy Hu 2018-04-15 11:38:08 +08:00
parent 48de632d17
commit 7437ddb597
2 changed files with 87 additions and 17 deletions

View File

@ -28,20 +28,6 @@ script:
- cp meshlite/target/release/libmeshlite.dylib thirdparty/meshlite/libmeshlite.dylib - cp meshlite/target/release/libmeshlite.dylib thirdparty/meshlite/libmeshlite.dylib
- qmake -config release - qmake -config release
- make - make
#- mv dust3d.app dust3d-unstable.app - mv dust3d.app dust3d_unstable.app
#- macdeployqt dust3d-unstable.app -dmg - 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
#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

View File

@ -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