From fb35da42ed27f68e52a6aad24cbb2b49a4738673 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 19 Nov 2019 10:15:02 -0800 Subject: [PATCH] upload separately --- src/install/prepare-sources-tarball.sh | 48 ------------------------ src/install/upload-src-tarball.sh | 51 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 48 deletions(-) create mode 100755 src/install/upload-src-tarball.sh diff --git a/src/install/prepare-sources-tarball.sh b/src/install/prepare-sources-tarball.sh index 6f2f3bc0..c3d40e49 100755 --- a/src/install/prepare-sources-tarball.sh +++ b/src/install/prepare-sources-tarball.sh @@ -6,51 +6,3 @@ git clone --depth 1 https://github.com/schollz/croc $tmp/croc (cd $tmp/croc && go mod tidy && go mod vendor) (cd $tmp && tar -cvzf croc_${VERSION}_src.tar.gz croc) mv $tmp/croc_${VERSION}_src.tar.gz dist/ - -# Check dependencies. -set -e -xargs=$(which gxargs || which xargs) - -# Validate settings. -[ "$TRACE" ] && set -x - -CONFIG=$@ - -for line in $CONFIG; do - eval "$line" -done - -owner="schollz" -repo="croc" -tag="v${VERSION}" -filename="dist/croc_${VERSION}_src.tar.gz" - -# 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_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. -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:]]=') -[ "$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/$owner/$repo/releases/$id/assets?name=$(basename $filename)" - -curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" $GH_ASSET diff --git a/src/install/upload-src-tarball.sh b/src/install/upload-src-tarball.sh new file mode 100755 index 00000000..2c34e7ad --- /dev/null +++ b/src/install/upload-src-tarball.sh @@ -0,0 +1,51 @@ +#!/bin/bash +VERSION=$(cat ./src/cli/cli.go | grep 'Version = "v' | sed 's/[^0-9.]*\([0-9.]*\).*/\1/') +echo $VERSION + +# Check dependencies. +set -e +xargs=$(which gxargs || which xargs) + +# Validate settings. +[ "$TRACE" ] && set -x + +CONFIG=$@ + +for line in $CONFIG; do + eval "$line" +done + +owner="schollz" +repo="croc" +tag="v${VERSION}" +filename="dist/croc_${VERSION}_src.tar.gz" + +# 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_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. +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:]]=') +[ "$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/$owner/$repo/releases/$id/assets?name=$(basename $filename)" + +curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" $GH_ASSET